Skip to content

Commit 64ca243

Browse files
authored
feat(lint): implement noNestedComponentDefinitions rule (#6053)
1 parent a57a018 commit 64ca243

File tree

14 files changed

+1271
-59
lines changed

14 files changed

+1271
-59
lines changed

.changeset/eight-spies-double.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Added the new rule [`noNestedComponentDefinitions`](https://biomejs.dev/linter/rules/no-nested-component-definitions),
6+
which disallows nested component definitions in React components.
7+
8+
This rule is useful for preventing potential performance issues and improving code readability by ensuring that components are defined at the top level.
9+
10+
**Example (Invalid):**
11+
12+
```jsx
13+
function ParentComponent() {
14+
function ChildComponent() {
15+
return <div>Hello</div>;
16+
}
17+
return <ChildComponent />;
18+
}
19+
```
20+
21+
**Example (Valid):**
22+
23+
```jsx
24+
function ChildComponent() {
25+
return <div>Hello</div>;
26+
}
27+
function ParentComponent() {
28+
return <ChildComponent />;
29+
}
30+
```

crates/biome_analyze/src/rule.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ pub enum RuleSource {
268268
EslintReactHooks(&'static str),
269269
/// Rules from [Eslint Plugin React Refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)
270270
EslintReactRefresh(&'static str),
271+
/// Rules from [eslint-react.xyz](https://eslint-react.xyz/)
272+
EslintReactXyz(&'static str),
271273
/// Rules from [Eslint Plugin Solid](https://github.com/solidjs-community/eslint-plugin-solid)
272274
EslintSolid(&'static str),
273275
/// Rules from [Eslint Plugin Sonar](https://github.com/SonarSource/eslint-plugin-sonarjs)
@@ -321,6 +323,7 @@ impl std::fmt::Display for RuleSource {
321323
Self::EslintReact(_) => write!(f, "eslint-plugin-react"),
322324
Self::EslintReactHooks(_) => write!(f, "eslint-plugin-react-hooks"),
323325
Self::EslintReactRefresh(_) => write!(f, "eslint-plugin-react-refresh"),
326+
Self::EslintReactXyz(_) => write!(f, "@eslint-react/eslint-plugin"),
324327
Self::EslintSolid(_) => write!(f, "eslint-plugin-solid"),
325328
Self::EslintSonarJs(_) => write!(f, "eslint-plugin-sonarjs"),
326329
Self::EslintStylistic(_) => write!(f, "eslint-plugin-stylistic"),
@@ -377,6 +380,7 @@ impl RuleSource {
377380
| Self::EslintReact(rule_name)
378381
| Self::EslintReactHooks(rule_name)
379382
| Self::EslintReactRefresh(rule_name)
383+
| Self::EslintReactXyz(rule_name)
380384
| Self::EslintTypeScript(rule_name)
381385
| Self::EslintSolid(rule_name)
382386
| Self::EslintSonarJs(rule_name)
@@ -408,6 +412,7 @@ impl RuleSource {
408412
Self::EslintReact(rule_name) => format!("react/{rule_name}"),
409413
Self::EslintReactHooks(rule_name) => format!("react-hooks/{rule_name}"),
410414
Self::EslintReactRefresh(rule_name) => format!("react-refresh/{rule_name}"),
415+
Self::EslintReactXyz(rule_name) => format!("@eslint-react/{rule_name}"),
411416
Self::EslintTypeScript(rule_name) => format!("@typescript-eslint/{rule_name}"),
412417
Self::EslintSolid(rule_name) => format!("solidjs/{rule_name}"),
413418
Self::EslintSonarJs(rule_name) => format!("sonarjs/{rule_name}"),
@@ -440,6 +445,7 @@ impl RuleSource {
440445
Self::EslintReact(rule_name) => format!("https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/{rule_name}.md"),
441446
Self::EslintReactHooks(_) => "https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md".to_string(),
442447
Self::EslintReactRefresh(_) => "https://github.com/ArnaudBarre/eslint-plugin-react-refresh".to_string(),
448+
Self::EslintReactXyz(rule_name) => format!("https://eslint-react.xyz/docs/rules/{rule_name}"),
443449
Self::EslintTypeScript(rule_name) => format!("https://typescript-eslint.io/rules/{rule_name}"),
444450
Self::EslintSolid(rule_name) => format!("https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/{rule_name}.md"),
445451
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: 11 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)