Skip to content

Commit ee4828d

Browse files
authored
feat(analyze/js): add useReactFunctionComponents rule (#7055)
1 parent 634a667 commit ee4828d

File tree

16 files changed

+487
-14
lines changed

16 files changed

+487
-14
lines changed

.changeset/long-socks-rhyme.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added the nursery rule [`useReactFunctionComponents`](https://biomejs.dev/linter/rules/use-react-function-components/). This rule enforces the preference to use function components instead of class components.
6+
7+
Valid:
8+
```jsx
9+
function Foo() {
10+
return <div>Hello, world!</div>;
11+
}
12+
```
13+
14+
Invalid:
15+
```jsx
16+
class Foo extends React.Component {
17+
render() {
18+
return <div>Hello, world!</div>;
19+
}
20+
}
21+
```

crates/biome_analyze/src/rule.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub enum RuleSource {
121121
EslintReactRefresh(&'static str),
122122
/// Rules from [eslint-react.xyz](https://eslint-react.xyz/)
123123
EslintReactXyz(&'static str),
124+
/// Rules from [Eslint Plugin React Prefer Function Component](https://github.com/tatethurston/eslint-plugin-react-prefer-function-component)
125+
ReactPreferFunctionComponent(&'static str),
124126
/// Rules from [Eslint Plugin Solid](https://github.com/solidjs-community/eslint-plugin-solid)
125127
EslintSolid(&'static str),
126128
/// Rules from [Eslint Plugin Sonar](https://github.com/SonarSource/eslint-plugin-sonarjs)
@@ -178,6 +180,9 @@ impl std::fmt::Display for RuleSource {
178180
Self::EslintReactHooks(_) => write!(f, "eslint-plugin-react-hooks"),
179181
Self::EslintReactRefresh(_) => write!(f, "eslint-plugin-react-refresh"),
180182
Self::EslintReactXyz(_) => write!(f, "@eslint-react/eslint-plugin"),
183+
Self::ReactPreferFunctionComponent(_) => {
184+
write!(f, "eslint-plugin-react-prefer-function-component")
185+
}
181186
Self::EslintSolid(_) => write!(f, "eslint-plugin-solid"),
182187
Self::EslintSonarJs(_) => write!(f, "eslint-plugin-sonarjs"),
183188
Self::EslintStylistic(_) => write!(f, "eslint-plugin-stylistic"),
@@ -253,6 +258,7 @@ impl RuleSource {
253258
| Self::EslintReactHooks(rule_name)
254259
| Self::EslintReactRefresh(rule_name)
255260
| Self::EslintReactXyz(rule_name)
261+
| Self::ReactPreferFunctionComponent(rule_name)
256262
| Self::EslintTypeScript(rule_name)
257263
| Self::EslintSolid(rule_name)
258264
| Self::EslintSonarJs(rule_name)
@@ -287,6 +293,9 @@ impl RuleSource {
287293
Self::EslintReactHooks(rule_name) => format!("react-hooks/{rule_name}"),
288294
Self::EslintReactRefresh(rule_name) => format!("react-refresh/{rule_name}"),
289295
Self::EslintReactXyz(rule_name) => format!("@eslint-react/{rule_name}"),
296+
Self::ReactPreferFunctionComponent(rule_name) => {
297+
format!("react-prefer-function-component/{rule_name}")
298+
}
290299
Self::EslintTypeScript(rule_name) => format!("@typescript-eslint/{rule_name}"),
291300
Self::EslintSolid(rule_name) => format!("solidjs/{rule_name}"),
292301
Self::EslintSonarJs(rule_name) => format!("sonarjs/{rule_name}"),
@@ -322,6 +331,7 @@ impl RuleSource {
322331
Self::EslintReactHooks(_) => "https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md".to_string(),
323332
Self::EslintReactRefresh(_) => "https://github.com/ArnaudBarre/eslint-plugin-react-refresh".to_string(),
324333
Self::EslintReactXyz(rule_name) => format!("https://eslint-react.xyz/docs/rules/{rule_name}"),
334+
Self::ReactPreferFunctionComponent(_) => "https://github.com/tatethurston/eslint-plugin-react-prefer-function-component".to_string(),
325335
Self::EslintTypeScript(rule_name) => format!("https://typescript-eslint.io/rules/{rule_name}"),
326336
Self::EslintSolid(rule_name) => format!("https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/{rule_name}.md"),
327337
Self::EslintSonarJs(rule_name) => format!("https://github.com/SonarSource/eslint-plugin-sonarjs/blob/HEAD/docs/rules/{rule_name}.md"),

crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)