Skip to content

Commit c5e71a1

Browse files
authored
feat: add react-x/no-nested-lazy-component-declarations rule, closes #1048 (#1052)
1 parent d754869 commit c5e71a1

39 files changed

+314
-69
lines changed

apps/website/content/docs/rules/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"no-missing-key",
3535
"no-misused-capture-owner-stack",
3636
"no-nested-component-definitions",
37+
"no-nested-lazy-component-declarations",
3738
"no-prop-types",
3839
"no-redundant-should-component-update",
3940
"no-set-state-in-component-did-mount",

apps/website/content/docs/rules/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Linter rules can have false positives, false negatives, and some rules are depen
5757
| [`no-missing-key`](./no-missing-key) | 2️⃣ | | Disallow missing `key` on items in list rendering | |
5858
| [`no-misused-capture-owner-stack`](./no-misused-capture-owner-stack) | 0️⃣ | `🧪` | Prevents incorrect usage of `captureOwnerStack` | |
5959
| [`no-nested-component-definitions`](./no-nested-component-definitions) | 2️⃣ | | Disallow nesting component definitions inside other components | |
60+
| [`no-nested-lazy-component-declarations`](./no-nested-lazy-component-declarations) | 2️⃣ | | Disallow nesting lazy component declarations inside other components | |
6061
| [`no-prop-types`](./no-prop-types) | 2️⃣ | | Disallow `propTypes` in favor of TypeScript or another type-checking solution | |
6162
| [`no-redundant-should-component-update`](./no-redundant-should-component-update) | 2️⃣ | | Disallow `shouldComponentUpdate` when extending `React.PureComponent` | |
6263
| [`no-set-state-in-component-did-mount`](./no-set-state-in-component-did-mount) | 1️⃣ | | Disallow calling `this.setState` in `componentDidMount` outside of functions, such as callbacks | |

packages/core/docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
- [isForwardRef](variables/isForwardRef.md)
6161
- [isForwardRefCall](variables/isForwardRefCall.md)
6262
- [isInversePhase](variables/isInversePhase.md)
63+
- [isLazy](variables/isLazy.md)
64+
- [isLazyCall](variables/isLazyCall.md)
6365
- [isMemo](variables/isMemo.md)
6466
- [isMemoCall](variables/isMemoCall.md)
6567
- [isUseActionStateCall](variables/isUseActionStateCall.md)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isLazy
6+
7+
# Variable: isLazy
8+
9+
> `const` **isLazy**: `ReturnType`
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[**@eslint-react/core**](../README.md)
2+
3+
***
4+
5+
[@eslint-react/core](../README.md) / isLazyCall
6+
7+
# Variable: isLazyCall
8+
9+
> `const` **isLazyCall**: `ReturnType`

packages/core/src/component/component-definition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function isValidComponentDefinition(context: RuleContext, node: AST.TSEST
4242
if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST.isArrayMapCall(node.parent)) {
4343
return false;
4444
}
45-
const boundaryNode = AST.findParentNode(
45+
const significantParent = AST.findParentNode(
4646
node,
4747
AST.isOneOf([
4848
T.JSXExpressionContainer,
@@ -52,5 +52,5 @@ export function isValidComponentDefinition(context: RuleContext, node: AST.TSEST
5252
T.ClassBody,
5353
]),
5454
);
55-
return boundaryNode == null || boundaryNode.type !== T.JSXExpressionContainer;
55+
return significantParent == null || significantParent.type !== T.JSXExpressionContainer;
5656
}

packages/core/src/utils/is-react-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const isCreateElement = isReactAPI("createElement");
3232
export const isCreateRef = isReactAPI("createRef");
3333
export const isForwardRef = isReactAPI("forwardRef");
3434
export const isMemo = isReactAPI("memo");
35+
export const isLazy = isReactAPI("lazy");
3536

3637
export const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
3738
export const isChildrenCountCall = isReactAPICall("Children", "count");
@@ -45,3 +46,4 @@ export const isCreateElementCall = isReactAPICall("createElement");
4546
export const isCreateRefCall = isReactAPICall("createRef");
4647
export const isForwardRefCall = isReactAPICall("forwardRef");
4748
export const isMemoCall = isReactAPICall("memo");
49+
export const isLazyCall = isReactAPICall("lazy");

packages/plugins/eslint-plugin-react-debug/src/rules/class-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
3434
const { ctx, listeners } = ER.useComponentCollectorLegacy();
3535
return {
3636
...listeners,
37-
"Program:exit"(node) {
38-
const components = ctx.getAllComponents(node);
37+
"Program:exit"(program) {
38+
const components = ctx.getAllComponents(program);
3939
for (const { name = "anonymous", node: component } of components.values()) {
4040
context.report({
4141
messageId: "classComponent",

packages/plugins/eslint-plugin-react-debug/src/rules/function-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4242
);
4343
return {
4444
...listeners,
45-
"Program:exit"(node) {
46-
const components = ctx.getAllComponents(node);
45+
"Program:exit"(program) {
46+
const components = ctx.getAllComponents(program);
4747
for (const { name = "anonymous", node, displayName, flag, hookCalls } of components.values()) {
4848
context.report({
4949
messageId: "functionComponent",

packages/plugins/eslint-plugin-react-debug/src/rules/hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
3535

3636
return {
3737
...listeners,
38-
"Program:exit"(node) {
39-
const allHooks = ctx.getAllHooks(node);
38+
"Program:exit"(program) {
39+
const allHooks = ctx.getAllHooks(program);
4040

4141
for (const { name, node, hookCalls } of allHooks.values()) {
4242
context.report({

0 commit comments

Comments
 (0)