eslint-plugin-react-features 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -0
- package/README.md +99 -19
- package/package.json +20 -4
- package/src/index.d.ts +1004 -21
- package/src/index.js +78 -16
- package/src/oxlint.d.ts +20 -0
- package/src/oxlint.js +21 -0
- package/src/rules/component-api/no-arbitrary-token-class.d.ts +17 -0
- package/src/rules/component-api/no-arbitrary-token-class.js +85 -0
- package/src/rules/component-api/no-default-test-id.d.ts +15 -0
- package/src/rules/component-api/no-default-test-id.js +53 -0
- package/src/rules/component-api/no-inline-style.d.ts +15 -0
- package/src/rules/component-api/no-inline-style.js +63 -0
- package/src/rules/component-api/no-is-prefix-prop.d.ts +17 -0
- package/src/rules/component-api/no-is-prefix-prop.js +66 -0
- package/src/rules/component-api/no-kind-prop-discriminator.d.ts +25 -0
- package/src/rules/component-api/no-kind-prop-discriminator.js +62 -0
- package/src/rules/component-api/no-raw-color-literal.d.ts +16 -0
- package/src/rules/component-api/no-raw-color-literal.js +63 -0
- package/src/rules/component-api/no-wrapper-sub-component.d.ts +23 -0
- package/src/rules/component-api/no-wrapper-sub-component.js +103 -0
- package/src/rules/component-api/require-data-slot.d.ts +15 -0
- package/src/rules/component-api/require-data-slot.js +45 -0
- package/src/rules/migration/react-class-to-hooks.js +6 -1
- package/src/rules/performance/no-unnecessary-rerenders.js +7 -3
- package/src/rules/performance/react-no-inline-functions.js +3 -1
- package/src/rules/performance/react-render-optimization.js +2 -1
- package/src/rules/react/checked-requires-onchange-or-readonly.js +1 -0
- package/src/rules/react/default-props-match-prop-types.js +1 -0
- package/src/rules/react/display-name.js +1 -0
- package/src/rules/react/hooks-exhaustive-deps.d.ts +1 -1
- package/src/rules/react/hooks-exhaustive-deps.js +136 -47
- package/src/rules/react/jsx-handler-names.js +1 -0
- package/src/rules/react/jsx-key.js +3 -2
- package/src/rules/react/jsx-max-depth.js +1 -0
- package/src/rules/react/jsx-no-bind.js +1 -0
- package/src/rules/react/jsx-no-duplicate-props.js +1 -0
- package/src/rules/react/jsx-no-literals.js +1 -0
- package/src/rules/react/jsx-no-script-url.js +6 -2
- package/src/rules/react/jsx-no-target-blank.js +7 -1
- package/src/rules/react/no-access-state-in-setstate.js +1 -0
- package/src/rules/react/no-adjacent-inline-elements.js +1 -0
- package/src/rules/react/no-arrow-function-lifecycle.js +1 -0
- package/src/rules/react/no-children-prop.js +1 -0
- package/src/rules/react/no-danger-with-children.js +2 -0
- package/src/rules/react/no-danger.js +3 -0
- package/src/rules/react/no-deprecated.js +1 -0
- package/src/rules/react/no-did-mount-set-state.js +1 -0
- package/src/rules/react/no-did-update-set-state.js +1 -0
- package/src/rules/react/no-direct-mutation-state.js +24 -66
- package/src/rules/react/no-find-dom-node.js +1 -0
- package/src/rules/react/no-invalid-html-attribute.js +1 -0
- package/src/rules/react/no-is-mounted.js +1 -0
- package/src/rules/react/no-multi-comp.js +4 -0
- package/src/rules/react/no-namespace.js +1 -0
- package/src/rules/react/no-object-type-as-default-prop.js +1 -0
- package/src/rules/react/no-redundant-should-component-update.js +1 -0
- package/src/rules/react/no-render-return-value.js +1 -0
- package/src/rules/react/no-set-state.js +1 -0
- package/src/rules/react/no-string-refs.js +1 -0
- package/src/rules/react/no-this-in-sfc.js +1 -0
- package/src/rules/react/no-typos.js +1 -0
- package/src/rules/react/no-unescaped-entities.js +1 -0
- package/src/rules/react/no-unknown-property.js +1 -0
- package/src/rules/react/no-unsafe.js +1 -0
- package/src/rules/react/prefer-es6-class.js +1 -0
- package/src/rules/react/prefer-stateless-function.js +8 -3
- package/src/rules/react/prop-types.js +2 -0
- package/src/rules/react/react-in-jsx-scope.js +1 -0
- package/src/rules/react/require-default-props.js +4 -0
- package/src/rules/react/require-optimization.js +1 -0
- package/src/rules/react/require-render-return.js +1 -0
- package/src/rules/react/required-attributes.js +6 -0
- package/src/rules/react/sort-comp.js +17 -13
- package/src/rules/react/state-in-constructor.js +3 -0
- package/src/rules/react/static-property-placement.js +7 -0
- package/src/rules/react/void-dom-elements-no-children.js +2 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noRawColorLiteral = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const COLOR_PATTERN = /(#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|oklch|oklab)\s*\()/;
|
|
11
|
+
const isColorString = (s) => COLOR_PATTERN.test(s);
|
|
12
|
+
const reportIfColorLiteral = (context, node, value) => {
|
|
13
|
+
if (typeof value === 'string' && isColorString(value)) {
|
|
14
|
+
context.report({ node, messageId: 'rawColor' });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.noRawColorLiteral = (0, eslint_devkit_1.createRule)({
|
|
18
|
+
name: 'no-raw-color-literal',
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md',
|
|
23
|
+
description: 'No raw hex / rgb / hsl / oklch color literals in source — use design tokens (R19)',
|
|
24
|
+
},
|
|
25
|
+
schema: [],
|
|
26
|
+
messages: {
|
|
27
|
+
rawColor: (0, eslint_devkit_1.formatLLMMessage)({
|
|
28
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
29
|
+
issueName: 'Raw color literal',
|
|
30
|
+
description: 'Raw color literal in source — use a design token (R19)',
|
|
31
|
+
severity: 'MEDIUM',
|
|
32
|
+
fix: 'Replace with a CSS custom property (`var(--your-token)`) or a Tailwind theme class wired to it.',
|
|
33
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-raw-color-literal.md',
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultOptions: [],
|
|
38
|
+
create(context) {
|
|
39
|
+
return {
|
|
40
|
+
// Color inside JSX attribute string values (className="text-[#fff]", style="...")
|
|
41
|
+
'JSXAttribute > Literal'(node) {
|
|
42
|
+
reportIfColorLiteral(context, node, node.value);
|
|
43
|
+
},
|
|
44
|
+
// Color inside `style={{ color: "#fff" }}` and similar
|
|
45
|
+
'JSXExpressionContainer ObjectExpression > Property > Literal'(node) {
|
|
46
|
+
reportIfColorLiteral(context, node, node.value);
|
|
47
|
+
},
|
|
48
|
+
// Color inside cn()/clsx()/twMerge() args: cn("text-[#fff]")
|
|
49
|
+
CallExpression(node) {
|
|
50
|
+
if (node.callee.type !== 'Identifier')
|
|
51
|
+
return;
|
|
52
|
+
const name = node.callee.name;
|
|
53
|
+
if (name !== 'cn' && name !== 'clsx' && name !== 'twMerge' && name !== 'classNames')
|
|
54
|
+
return;
|
|
55
|
+
for (const arg of node.arguments) {
|
|
56
|
+
if (arg.type === 'Literal') {
|
|
57
|
+
reportIfColorLiteral(context, arg, arg.value);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: no-wrapper-sub-component
|
|
8
|
+
* Enforces R12: don't create wrapper sub-components when an existing
|
|
9
|
+
* primitive does the job. Heuristic: a function component whose entire body
|
|
10
|
+
* is `return <Primitive {...props} />;` — a pure passthrough wrapper that
|
|
11
|
+
* adds no structural behavior.
|
|
12
|
+
*
|
|
13
|
+
* Exempt cases:
|
|
14
|
+
* - The wrapper adds at least one literal attribute (className, data-slot,
|
|
15
|
+
* aria-*, role) — that's structural behavior.
|
|
16
|
+
* - The wrapper adds hook calls or computed values before returning.
|
|
17
|
+
* - The wrapper renames the component for re-export with no other change —
|
|
18
|
+
* still flagged; consumers should import the primitive directly.
|
|
19
|
+
*/
|
|
20
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
21
|
+
export declare const noWrapperSubComponent: TSESLint.RuleModule<"wrapperSubComponent", [], unknown, TSESLint.RuleListener> & {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.noWrapperSubComponent = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const isPassthroughBody = (body) => {
|
|
11
|
+
// Arrow function with concise body: () => <X {...props} />
|
|
12
|
+
if (body.type === 'JSXElement')
|
|
13
|
+
return body;
|
|
14
|
+
// Block body with a single return statement
|
|
15
|
+
if (body.type !== 'BlockStatement')
|
|
16
|
+
return null;
|
|
17
|
+
if (body.body.length !== 1)
|
|
18
|
+
return null;
|
|
19
|
+
const stmt = body.body[0];
|
|
20
|
+
if (stmt.type !== 'ReturnStatement')
|
|
21
|
+
return null;
|
|
22
|
+
if (!stmt.argument || stmt.argument.type !== 'JSXElement')
|
|
23
|
+
return null;
|
|
24
|
+
return stmt.argument;
|
|
25
|
+
};
|
|
26
|
+
const isSpreadOnlyJsx = (el) => {
|
|
27
|
+
const attrs = el.openingElement.attributes;
|
|
28
|
+
if (attrs.length !== 1)
|
|
29
|
+
return false;
|
|
30
|
+
const attr = attrs[0];
|
|
31
|
+
if (attr.type !== 'JSXSpreadAttribute')
|
|
32
|
+
return false;
|
|
33
|
+
if (attr.argument.type !== 'Identifier')
|
|
34
|
+
return false;
|
|
35
|
+
// children must be empty (self-closing or empty)
|
|
36
|
+
return el.children.length === 0;
|
|
37
|
+
};
|
|
38
|
+
const isPascalCaseIdentifier = (s) => /^[A-Z]/.test(s);
|
|
39
|
+
const isPascalCaseJsxName = (name) => {
|
|
40
|
+
if (name.type === 'JSXIdentifier')
|
|
41
|
+
return isPascalCaseIdentifier(name.name);
|
|
42
|
+
if (name.type === 'JSXMemberExpression')
|
|
43
|
+
return true;
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
exports.noWrapperSubComponent = (0, eslint_devkit_1.createRule)({
|
|
47
|
+
name: 'no-wrapper-sub-component',
|
|
48
|
+
meta: {
|
|
49
|
+
type: 'problem',
|
|
50
|
+
docs: {
|
|
51
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md',
|
|
52
|
+
description: 'Ban pure-passthrough wrapper sub-components — slot the primitive directly (R12)',
|
|
53
|
+
},
|
|
54
|
+
schema: [],
|
|
55
|
+
messages: {
|
|
56
|
+
wrapperSubComponent: (0, eslint_devkit_1.formatLLMMessage)({
|
|
57
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
58
|
+
issueName: 'Passthrough wrapper component',
|
|
59
|
+
description: 'Component `{{name}}` is a pure passthrough wrapper — slot the primitive directly (R12)',
|
|
60
|
+
severity: 'MEDIUM',
|
|
61
|
+
fix: 'Delete the wrapper and let consumers import the primitive. If the wrapper must exist, give it structural behavior (a slot, a default prop, or composition logic).',
|
|
62
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/no-wrapper-sub-component.md',
|
|
63
|
+
}),
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
defaultOptions: [],
|
|
67
|
+
create(context) {
|
|
68
|
+
const checkFn = (node, name) => {
|
|
69
|
+
if (!isPascalCaseIdentifier(name))
|
|
70
|
+
return;
|
|
71
|
+
const jsx = isPassthroughBody(node.body);
|
|
72
|
+
if (!jsx)
|
|
73
|
+
return;
|
|
74
|
+
if (!isSpreadOnlyJsx(jsx))
|
|
75
|
+
return;
|
|
76
|
+
if (!isPascalCaseJsxName(jsx.openingElement.name))
|
|
77
|
+
return;
|
|
78
|
+
context.report({
|
|
79
|
+
node,
|
|
80
|
+
messageId: 'wrapperSubComponent',
|
|
81
|
+
data: { name },
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
FunctionDeclaration(node) {
|
|
86
|
+
if (!node.id)
|
|
87
|
+
return;
|
|
88
|
+
checkFn(node, node.id.name);
|
|
89
|
+
},
|
|
90
|
+
VariableDeclarator(node) {
|
|
91
|
+
if (node.id.type !== 'Identifier')
|
|
92
|
+
return;
|
|
93
|
+
if (!node.init)
|
|
94
|
+
return;
|
|
95
|
+
if (node.init.type !== 'ArrowFunctionExpression' &&
|
|
96
|
+
node.init.type !== 'FunctionExpression') {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
checkFn(node.init, node.id.name);
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* ESLint Rule: require-data-slot
|
|
8
|
+
* Enforces R6: every named composition part carries `data-slot="<part-name>"`
|
|
9
|
+
* so consumers can style by slot. Heuristic: a JSX element that carries
|
|
10
|
+
* `data-testid` is a named part and must also carry `data-slot`.
|
|
11
|
+
*/
|
|
12
|
+
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
13
|
+
export declare const requireDataSlot: TSESLint.RuleModule<"missingDataSlot", [], unknown, TSESLint.RuleListener> & {
|
|
14
|
+
name: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.requireDataSlot = void 0;
|
|
9
|
+
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
|
+
const hasNamedAttribute = (node, name) => node.attributes.some((attr) => attr.type === 'JSXAttribute' &&
|
|
11
|
+
attr.name.type === 'JSXIdentifier' &&
|
|
12
|
+
attr.name.name === name);
|
|
13
|
+
exports.requireDataSlot = (0, eslint_devkit_1.createRule)({
|
|
14
|
+
name: 'require-data-slot',
|
|
15
|
+
meta: {
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md',
|
|
19
|
+
description: 'Named composition parts must carry data-slot (R6)',
|
|
20
|
+
},
|
|
21
|
+
schema: [],
|
|
22
|
+
messages: {
|
|
23
|
+
missingDataSlot: (0, eslint_devkit_1.formatLLMMessage)({
|
|
24
|
+
icon: eslint_devkit_1.MessageIcons.WARNING,
|
|
25
|
+
issueName: 'Missing data-slot',
|
|
26
|
+
description: 'JSX element has data-testid but no data-slot (R6)',
|
|
27
|
+
severity: 'MEDIUM',
|
|
28
|
+
fix: 'Add `data-slot="<part-name>"` so consumers can style by slot.',
|
|
29
|
+
documentationLink: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/component-api/require-data-slot.md',
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultOptions: [],
|
|
34
|
+
create(context) {
|
|
35
|
+
return {
|
|
36
|
+
JSXOpeningElement(node) {
|
|
37
|
+
if (!hasNamedAttribute(node, 'data-testid'))
|
|
38
|
+
return;
|
|
39
|
+
if (hasNamedAttribute(node, 'data-slot'))
|
|
40
|
+
return;
|
|
41
|
+
context.report({ node, messageId: 'missingDataSlot' });
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
});
|
|
@@ -13,7 +13,10 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'suggestion',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-class-to-hooks.md',
|
|
16
17
|
description: 'Suggest migrating React class components to hooks with detailed migration path',
|
|
18
|
+
cwe: 'CWE-1078',
|
|
19
|
+
cvss: 5,
|
|
17
20
|
},
|
|
18
21
|
fixable: 'code',
|
|
19
22
|
hasSuggestions: true,
|
|
@@ -71,10 +74,11 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
71
74
|
create(context) {
|
|
72
75
|
const options = context.options[0] || {};
|
|
73
76
|
const { allowComplexLifecycle = false } = options || {};
|
|
74
|
-
const sourceCode = context.sourceCode
|
|
77
|
+
const sourceCode = context.sourceCode;
|
|
75
78
|
/**
|
|
76
79
|
* Check if class extends React.Component
|
|
77
80
|
*/
|
|
81
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
78
82
|
const isReactComponent = (node) => {
|
|
79
83
|
if (!node.superClass)
|
|
80
84
|
return false;
|
|
@@ -97,6 +101,7 @@ exports.reactClassToHooks = (0, eslint_devkit_2.createRule)({
|
|
|
97
101
|
/**
|
|
98
102
|
* Analyze lifecycle methods used
|
|
99
103
|
*/
|
|
104
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
100
105
|
const analyzeLifecycleMethods = (node) => {
|
|
101
106
|
const lifecycleMethods = [];
|
|
102
107
|
const classBody = node.body.body;
|
|
@@ -12,10 +12,13 @@ const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
|
12
12
|
* Check if a node is in a React component render context
|
|
13
13
|
*/
|
|
14
14
|
function isInReactRenderContext(node) {
|
|
15
|
+
// `current` is `node` on entry and only ever reassigned from `parent` after
|
|
16
|
+
// an explicit `if (!parent) break;`, so it's never null at the loop check
|
|
17
|
+
// (CodeQL: `js/useless-conditional` on the `current &&` test).
|
|
15
18
|
let current = node;
|
|
16
19
|
let depth = 0;
|
|
17
20
|
const maxDepth = 15;
|
|
18
|
-
while (
|
|
21
|
+
while (depth < maxDepth) {
|
|
19
22
|
const parent = current.parent;
|
|
20
23
|
if (!parent)
|
|
21
24
|
break;
|
|
@@ -80,6 +83,7 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
80
83
|
meta: {
|
|
81
84
|
type: 'suggestion',
|
|
82
85
|
docs: {
|
|
86
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/no-unnecessary-rerenders.md',
|
|
83
87
|
description: 'Detects prevented re-renders in React',
|
|
84
88
|
},
|
|
85
89
|
hasSuggestions: true,
|
|
@@ -143,14 +147,14 @@ exports.noUnnecessaryRerenders = (0, eslint_devkit_2.createRule)({
|
|
|
143
147
|
],
|
|
144
148
|
create(context, [options = {}]) {
|
|
145
149
|
const { ignoreInTests = true, minSize = 5 } = options || {};
|
|
146
|
-
const filename = context.
|
|
150
|
+
const filename = context.filename;
|
|
147
151
|
// Only skip if ignoreInTests is true AND filename matches test pattern
|
|
148
152
|
// If ignoreInTests is explicitly false, always run the rule
|
|
149
153
|
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
150
154
|
if (isTestFile) {
|
|
151
155
|
return {};
|
|
152
156
|
}
|
|
153
|
-
const sourceCode = context.sourceCode
|
|
157
|
+
const sourceCode = context.sourceCode;
|
|
154
158
|
/**
|
|
155
159
|
* Check JSX attributes for unnecessary re-renders
|
|
156
160
|
*/
|
|
@@ -13,9 +13,9 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'suggestion',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-no-inline-functions.md',
|
|
16
17
|
description: 'Prevent inline functions in React renders with performance metrics',
|
|
17
18
|
},
|
|
18
|
-
fixable: 'code',
|
|
19
19
|
hasSuggestions: true,
|
|
20
20
|
messages: {
|
|
21
21
|
// 🎯 Token optimization: 42% reduction (48→28 tokens) - inline functions cause unnecessary re-renders
|
|
@@ -98,6 +98,7 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
98
98
|
/**
|
|
99
99
|
* Check if node is inside JSX
|
|
100
100
|
*/
|
|
101
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
101
102
|
const isInJSX = (node) => {
|
|
102
103
|
let parent = node.parent;
|
|
103
104
|
while (parent) {
|
|
@@ -127,6 +128,7 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
127
128
|
/**
|
|
128
129
|
* Calculate performance impact
|
|
129
130
|
*/
|
|
131
|
+
// oxlint-disable-next-line consistent-function-scoping
|
|
130
132
|
const calculateImpact = (arrayInfo) => {
|
|
131
133
|
if (arrayInfo.inArray && arrayInfo.estimatedSize && arrayInfo.estimatedSize > 50) {
|
|
132
134
|
return {
|
|
@@ -89,6 +89,7 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
89
89
|
meta: {
|
|
90
90
|
type: 'suggestion',
|
|
91
91
|
docs: {
|
|
92
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/react-render-optimization.md',
|
|
92
93
|
description: 'Detects unnecessary re-renders and expensive computations in React',
|
|
93
94
|
},
|
|
94
95
|
messages: {
|
|
@@ -187,7 +188,7 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
187
188
|
],
|
|
188
189
|
create(context, [options = {}]) {
|
|
189
190
|
const { detectInlineProps = true, detectInlineFunctions = true, detectExpensiveComputations = true, minComputationComplexity = 3, ignoreInTests = true, } = options || {};
|
|
190
|
-
const filename = context.
|
|
191
|
+
const filename = context.filename;
|
|
191
192
|
const isTestFile = ignoreInTests && /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
|
|
192
193
|
if (isTestFile) {
|
|
193
194
|
return {};
|
|
@@ -13,6 +13,7 @@ exports.checkedRequiresOnchangeOrReadonly = (0, eslint_devkit_1.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'problem',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/checked-requires-onchange-or-readonly.md',
|
|
16
17
|
description: 'Ensure controlled inputs have onChange or readOnly',
|
|
17
18
|
},
|
|
18
19
|
schema: [],
|
|
@@ -13,6 +13,7 @@ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'problem',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/default-props-match-prop-types.md',
|
|
16
17
|
description: 'Validate default props match prop types',
|
|
17
18
|
},
|
|
18
19
|
schema: [],
|
|
@@ -13,6 +13,7 @@ exports.displayName = (0, eslint_devkit_1.createRule)({
|
|
|
13
13
|
meta: {
|
|
14
14
|
type: 'problem',
|
|
15
15
|
docs: {
|
|
16
|
+
url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-react-features/docs/rules/display-name.md',
|
|
16
17
|
description: 'Enforce component display names',
|
|
17
18
|
},
|
|
18
19
|
schema: [],
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* useEffect, useCallback, useMemo, and useLayoutEffect.
|
|
12
12
|
*/
|
|
13
13
|
import type { TSESLint } from '@interlace/eslint-devkit';
|
|
14
|
-
type MessageIds = 'missingDep' | 'extraDep' | 'unnecessaryDep' | 'suggestAddDep' | 'suggestRemoveDep';
|
|
14
|
+
type MessageIds = 'missingDep' | 'extraDep' | 'unnecessaryDep' | 'suggestAddDep' | 'suggestRemoveDep' | 'depsNotArrayLiteral';
|
|
15
15
|
export interface Options {
|
|
16
16
|
/** Additional hooks to check (e.g., custom hooks using useEffect internally) */
|
|
17
17
|
additionalHooks?: string;
|