eslint-plugin-react-features 1.2.5 → 1.2.7
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/package.json +7 -18
- package/src/index.d.ts +15 -2074
- package/src/index.js +1 -36
- package/src/oxlint.d.ts +17 -20
- package/src/oxlint.js +0 -18
- package/src/rules/component-api/no-arbitrary-token-class.js +0 -11
- package/src/rules/component-api/no-default-test-id.js +0 -7
- package/src/rules/component-api/no-inline-style.js +0 -6
- package/src/rules/component-api/no-is-prefix-prop.js +0 -7
- package/src/rules/component-api/no-kind-prop-discriminator.js +0 -5
- package/src/rules/component-api/no-raw-color-literal.js +0 -8
- package/src/rules/component-api/no-wrapper-sub-component.js +0 -8
- package/src/rules/component-api/require-data-slot.js +0 -5
- package/src/rules/migration/react-class-to-hooks.js +1 -26
- package/src/rules/performance/no-unnecessary-rerenders.js +1 -32
- package/src/rules/performance/react-no-inline-functions.js +2 -29
- package/src/rules/performance/react-render-optimization.js +1 -40
- package/src/rules/react/checked-requires-onchange-or-readonly.js +0 -7
- package/src/rules/react/default-props-match-prop-types.js +2 -23
- package/src/rules/react/display-name.js +1 -33
- package/src/rules/react/hooks-exhaustive-deps.js +1 -90
- package/src/rules/react/jsx-handler-names.js +0 -8
- package/src/rules/react/jsx-key.js +0 -84
- package/src/rules/react/jsx-max-depth.js +0 -10
- package/src/rules/react/jsx-no-bind.js +0 -10
- package/src/rules/react/jsx-no-duplicate-props.js +0 -5
- package/src/rules/react/jsx-no-literals.js +0 -5
- package/src/rules/react/jsx-no-script-url.js +0 -16
- package/src/rules/react/jsx-no-target-blank.js +1 -20
- package/src/rules/react/no-access-state-in-setstate.js +0 -13
- package/src/rules/react/no-adjacent-inline-elements.js +0 -10
- package/src/rules/react/no-arrow-function-lifecycle.js +0 -7
- package/src/rules/react/no-children-prop.js +0 -7
- package/src/rules/react/no-danger-with-children.js +0 -13
- package/src/rules/react/no-danger.js +0 -5
- package/src/rules/react/no-deprecated.js +0 -11
- package/src/rules/react/no-did-mount-set-state.js +0 -6
- package/src/rules/react/no-did-update-set-state.js +0 -10
- package/src/rules/react/no-direct-mutation-state.js +3 -29
- package/src/rules/react/no-find-dom-node.js +0 -7
- package/src/rules/react/no-invalid-html-attribute.js +36 -41
- package/src/rules/react/no-is-mounted.js +0 -7
- package/src/rules/react/no-multi-comp.js +0 -14
- package/src/rules/react/no-namespace.js +0 -5
- package/src/rules/react/no-object-type-as-default-prop.js +0 -9
- package/src/rules/react/no-redundant-should-component-update.js +0 -6
- package/src/rules/react/no-render-return-value.js +1 -9
- package/src/rules/react/no-set-state.js +0 -6
- package/src/rules/react/no-string-refs.js +0 -8
- package/src/rules/react/no-this-in-sfc.js +0 -11
- package/src/rules/react/no-typos.js +1 -9
- package/src/rules/react/no-unescaped-entities.js +0 -7
- package/src/rules/react/no-unknown-property.js +0 -13
- package/src/rules/react/no-unsafe.js +0 -7
- package/src/rules/react/prefer-es6-class.js +0 -7
- package/src/rules/react/prefer-stateless-function.js +0 -13
- package/src/rules/react/prop-types.js +0 -12
- package/src/rules/react/react-in-jsx-scope.js +0 -9
- package/src/rules/react/require-default-props.js +0 -19
- package/src/rules/react/require-optimization.js +6 -44
- package/src/rules/react/require-render-return.js +0 -9
- package/src/rules/react/required-attributes.js +0 -34
- package/src/rules/react/sort-comp.js +1 -19
- package/src/rules/react/state-in-constructor.js +0 -11
- package/src/rules/react/static-property-placement.js +1 -21
- package/src/rules/react/void-dom-elements-no-children.js +0 -7
- package/src/types/index.js +0 -5
- package/CHANGELOG.md +0 -255
- package/src/rules/component-api/no-arbitrary-token-class.d.ts +0 -17
- package/src/rules/component-api/no-default-test-id.d.ts +0 -15
- package/src/rules/component-api/no-inline-style.d.ts +0 -15
- package/src/rules/component-api/no-is-prefix-prop.d.ts +0 -17
- package/src/rules/component-api/no-kind-prop-discriminator.d.ts +0 -25
- package/src/rules/component-api/no-raw-color-literal.d.ts +0 -16
- package/src/rules/component-api/no-wrapper-sub-component.d.ts +0 -23
- package/src/rules/component-api/require-data-slot.d.ts +0 -15
- package/src/rules/migration/react-class-to-hooks.d.ts +0 -22
- package/src/rules/performance/no-unnecessary-rerenders.d.ts +0 -26
- package/src/rules/performance/react-no-inline-functions.d.ts +0 -24
- package/src/rules/performance/react-render-optimization.d.ts +0 -31
- package/src/rules/react/checked-requires-onchange-or-readonly.d.ts +0 -16
- package/src/rules/react/default-props-match-prop-types.d.ts +0 -13
- package/src/rules/react/display-name.d.ts +0 -13
- package/src/rules/react/hooks-exhaustive-deps.d.ts +0 -25
- package/src/rules/react/jsx-handler-names.d.ts +0 -13
- package/src/rules/react/jsx-key.d.ts +0 -20
- package/src/rules/react/jsx-max-depth.d.ts +0 -19
- package/src/rules/react/jsx-no-bind.d.ts +0 -13
- package/src/rules/react/jsx-no-duplicate-props.d.ts +0 -21
- package/src/rules/react/jsx-no-literals.d.ts +0 -20
- package/src/rules/react/jsx-no-script-url.d.ts +0 -25
- package/src/rules/react/jsx-no-target-blank.d.ts +0 -26
- package/src/rules/react/no-access-state-in-setstate.d.ts +0 -13
- package/src/rules/react/no-adjacent-inline-elements.d.ts +0 -13
- package/src/rules/react/no-arrow-function-lifecycle.d.ts +0 -13
- package/src/rules/react/no-children-prop.d.ts +0 -13
- package/src/rules/react/no-danger-with-children.d.ts +0 -16
- package/src/rules/react/no-danger.d.ts +0 -13
- package/src/rules/react/no-deprecated.d.ts +0 -16
- package/src/rules/react/no-did-mount-set-state.d.ts +0 -13
- package/src/rules/react/no-did-update-set-state.d.ts +0 -19
- package/src/rules/react/no-direct-mutation-state.d.ts +0 -20
- package/src/rules/react/no-find-dom-node.d.ts +0 -15
- package/src/rules/react/no-invalid-html-attribute.d.ts +0 -13
- package/src/rules/react/no-is-mounted.d.ts +0 -13
- package/src/rules/react/no-multi-comp.d.ts +0 -18
- package/src/rules/react/no-namespace.d.ts +0 -13
- package/src/rules/react/no-object-type-as-default-prop.d.ts +0 -13
- package/src/rules/react/no-redundant-should-component-update.d.ts +0 -13
- package/src/rules/react/no-render-return-value.d.ts +0 -13
- package/src/rules/react/no-set-state.d.ts +0 -13
- package/src/rules/react/no-string-refs.d.ts +0 -13
- package/src/rules/react/no-this-in-sfc.d.ts +0 -13
- package/src/rules/react/no-typos.d.ts +0 -13
- package/src/rules/react/no-unescaped-entities.d.ts +0 -13
- package/src/rules/react/no-unknown-property.d.ts +0 -13
- package/src/rules/react/no-unsafe.d.ts +0 -20
- package/src/rules/react/prefer-es6-class.d.ts +0 -13
- package/src/rules/react/prefer-stateless-function.d.ts +0 -16
- package/src/rules/react/prop-types.d.ts +0 -18
- package/src/rules/react/react-in-jsx-scope.d.ts +0 -13
- package/src/rules/react/require-default-props.d.ts +0 -16
- package/src/rules/react/require-optimization.d.ts +0 -26
- package/src/rules/react/require-render-return.d.ts +0 -13
- package/src/rules/react/required-attributes.d.ts +0 -28
- package/src/rules/react/sort-comp.d.ts +0 -17
- package/src/rules/react/state-in-constructor.d.ts +0 -13
- package/src/rules/react/static-property-placement.d.ts +0 -20
- package/src/rules/react/void-dom-elements-no-children.d.ts +0 -15
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.reactNoInlineFunctions = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -18,7 +13,6 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
18
13
|
},
|
|
19
14
|
hasSuggestions: true,
|
|
20
15
|
messages: {
|
|
21
|
-
// 🎯 Token optimization: 42% reduction (48→28 tokens) - inline functions cause unnecessary re-renders
|
|
22
16
|
inlineFunction: (0, eslint_devkit_1.formatLLMMessage)({
|
|
23
17
|
icon: eslint_devkit_1.MessageIcons.PERFORMANCE,
|
|
24
18
|
issueName: 'Inline function',
|
|
@@ -94,12 +88,7 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
94
88
|
],
|
|
95
89
|
create(context) {
|
|
96
90
|
const options = context.options[0] || {};
|
|
97
|
-
// `options` is already object-coerced above, so no second `||` fallback.
|
|
98
91
|
const { allowInEventHandlers = false, minArraySize = 10 } = options;
|
|
99
|
-
/**
|
|
100
|
-
* Check if node is inside JSX
|
|
101
|
-
*/
|
|
102
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
103
92
|
const isInJSX = (node) => {
|
|
104
93
|
let parent = node.parent;
|
|
105
94
|
while (parent) {
|
|
@@ -110,9 +99,6 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
110
99
|
}
|
|
111
100
|
return false;
|
|
112
101
|
};
|
|
113
|
-
/**
|
|
114
|
-
* Check if inline function is in array method
|
|
115
|
-
*/
|
|
116
102
|
const isInArrayMethod = (node) => {
|
|
117
103
|
const parent = node.parent;
|
|
118
104
|
if (parent?.type === 'CallExpression') {
|
|
@@ -126,10 +112,6 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
126
112
|
}
|
|
127
113
|
return { inArray: false };
|
|
128
114
|
};
|
|
129
|
-
/**
|
|
130
|
-
* Calculate performance impact
|
|
131
|
-
*/
|
|
132
|
-
// oxlint-disable-next-line consistent-function-scoping
|
|
133
115
|
const calculateImpact = (arrayInfo) => {
|
|
134
116
|
if (arrayInfo.inArray && arrayInfo.estimatedSize && arrayInfo.estimatedSize > 50) {
|
|
135
117
|
return {
|
|
@@ -144,9 +126,6 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
144
126
|
affectedMetric: 'Interaction to Next Paint (INP)',
|
|
145
127
|
};
|
|
146
128
|
};
|
|
147
|
-
/**
|
|
148
|
-
* Check if node is inside JSXExpressionContainer (directly or nested)
|
|
149
|
-
*/
|
|
150
129
|
const isInJSXExpressionContainer = (node) => {
|
|
151
130
|
let current = node;
|
|
152
131
|
while (current) {
|
|
@@ -158,16 +137,14 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
158
137
|
return false;
|
|
159
138
|
};
|
|
160
139
|
return {
|
|
161
|
-
// Match direct children of JSXExpressionContainer
|
|
162
140
|
'JSXExpressionContainer > ArrowFunctionExpression, JSXExpressionContainer > FunctionExpression'(node) {
|
|
163
141
|
if (!isInJSX(node))
|
|
164
142
|
return;
|
|
165
|
-
// Check if it's in an event handler prop
|
|
166
143
|
const parent = node.parent;
|
|
167
144
|
if (allowInEventHandlers && parent?.parent?.type === 'JSXAttribute') {
|
|
168
145
|
const attr = parent.parent;
|
|
169
146
|
if (attr.name.type === 'JSXIdentifier' && attr.name.name.startsWith('on')) {
|
|
170
|
-
return;
|
|
147
|
+
return;
|
|
171
148
|
}
|
|
172
149
|
}
|
|
173
150
|
const arrayInfo = isInArrayMethod(node);
|
|
@@ -181,19 +158,15 @@ exports.reactNoInlineFunctions = (0, eslint_devkit_2.createRule)({
|
|
|
181
158
|
},
|
|
182
159
|
});
|
|
183
160
|
},
|
|
184
|
-
// Also match arrow functions inside CallExpressions within JSXExpressionContainer
|
|
185
|
-
// This catches cases like {items.map(() => ...)}
|
|
186
161
|
'CallExpression > ArrowFunctionExpression, CallExpression > FunctionExpression'(node) {
|
|
187
|
-
// Only check if we're inside a JSXExpressionContainer
|
|
188
162
|
if (!isInJSXExpressionContainer(node))
|
|
189
163
|
return;
|
|
190
|
-
// Check if it's in an event handler prop
|
|
191
164
|
let current = node;
|
|
192
165
|
while (current) {
|
|
193
166
|
if (current.type === 'JSXAttribute') {
|
|
194
167
|
const attr = current;
|
|
195
168
|
if (allowInEventHandlers && attr.name.type === 'JSXIdentifier' && attr.name.name.startsWith('on')) {
|
|
196
|
-
return;
|
|
169
|
+
return;
|
|
197
170
|
}
|
|
198
171
|
}
|
|
199
172
|
current = current.parent;
|
|
@@ -1,66 +1,38 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.reactRenderOptimization = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
10
5
|
const eslint_devkit_2 = require("@interlace/eslint-devkit");
|
|
11
|
-
/**
|
|
12
|
-
* Check if a node is an inline object literal
|
|
13
|
-
*/
|
|
14
6
|
function isInlineObject(node) {
|
|
15
7
|
return node.type === 'ObjectExpression';
|
|
16
8
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Check if a node is an inline array literal
|
|
19
|
-
*/
|
|
20
9
|
function isInlineArray(node) {
|
|
21
10
|
return node.type === 'ArrayExpression';
|
|
22
11
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Check if a node is an inline arrow function
|
|
25
|
-
*/
|
|
26
12
|
function isInlineArrowFunction(node) {
|
|
27
13
|
return node.type === 'ArrowFunctionExpression';
|
|
28
14
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Check if a node is an inline function expression
|
|
31
|
-
*/
|
|
32
15
|
function isInlineFunctionExpression(node) {
|
|
33
16
|
return node.type === 'FunctionExpression';
|
|
34
17
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Estimate computation complexity
|
|
37
|
-
*/
|
|
38
18
|
function estimateComplexity(node) {
|
|
39
19
|
let complexity = 0;
|
|
40
|
-
// Count loops
|
|
41
20
|
if (node.type === 'ForStatement' || node.type === 'ForOfStatement' ||
|
|
42
21
|
node.type === 'ForInStatement' || node.type === 'WhileStatement') {
|
|
43
22
|
complexity += 3;
|
|
44
23
|
}
|
|
45
|
-
// Count conditionals
|
|
46
24
|
if (node.type === 'IfStatement' || node.type === 'ConditionalExpression') {
|
|
47
25
|
complexity += 1;
|
|
48
26
|
}
|
|
49
|
-
// Count function calls (heuristic)
|
|
50
27
|
if (node.type === 'CallExpression') {
|
|
51
28
|
complexity += 1;
|
|
52
29
|
}
|
|
53
30
|
return complexity;
|
|
54
31
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Check if computation is expensive
|
|
57
|
-
*/
|
|
58
32
|
function isExpensiveComputation(node, minComplexity) {
|
|
59
|
-
// Check if it's a complex expression
|
|
60
33
|
if (node.type === 'BinaryExpression' || node.type === 'LogicalExpression') {
|
|
61
|
-
return false;
|
|
34
|
+
return false;
|
|
62
35
|
}
|
|
63
|
-
// Check for loops or nested structures
|
|
64
36
|
let current = node;
|
|
65
37
|
let depth = 0;
|
|
66
38
|
const maxDepth = 5;
|
|
@@ -69,7 +41,6 @@ function isExpensiveComputation(node, minComplexity) {
|
|
|
69
41
|
if (complexity >= minComplexity) {
|
|
70
42
|
return true;
|
|
71
43
|
}
|
|
72
|
-
// Check children
|
|
73
44
|
if ('body' in current && current.body) {
|
|
74
45
|
if (Array.isArray(current.body)) {
|
|
75
46
|
for (const child of current.body) {
|
|
@@ -193,27 +164,21 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
193
164
|
if (isTestFile) {
|
|
194
165
|
return {};
|
|
195
166
|
}
|
|
196
|
-
/**
|
|
197
|
-
* Check JSX attributes for inline props
|
|
198
|
-
*/
|
|
199
167
|
function checkJSXAttribute(node) {
|
|
200
168
|
try {
|
|
201
169
|
if (!node.value) {
|
|
202
170
|
return;
|
|
203
171
|
}
|
|
204
|
-
// Extract expression from JSXExpressionContainer
|
|
205
172
|
let value = null;
|
|
206
173
|
if (node.value.type === 'JSXExpressionContainer') {
|
|
207
174
|
value = node.value.expression;
|
|
208
175
|
}
|
|
209
176
|
else if (node.value.type === 'Literal') {
|
|
210
|
-
// String literals are fine
|
|
211
177
|
return;
|
|
212
178
|
}
|
|
213
179
|
if (!value) {
|
|
214
180
|
return;
|
|
215
181
|
}
|
|
216
|
-
// Check for inline objects
|
|
217
182
|
if (detectInlineProps && isInlineObject(value)) {
|
|
218
183
|
context.report({
|
|
219
184
|
node,
|
|
@@ -230,7 +195,6 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
230
195
|
});
|
|
231
196
|
return;
|
|
232
197
|
}
|
|
233
|
-
// Check for inline arrays
|
|
234
198
|
if (detectInlineProps && isInlineArray(value)) {
|
|
235
199
|
context.report({
|
|
236
200
|
node,
|
|
@@ -247,7 +211,6 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
247
211
|
});
|
|
248
212
|
return;
|
|
249
213
|
}
|
|
250
|
-
// Check for inline functions
|
|
251
214
|
if (detectInlineFunctions &&
|
|
252
215
|
(isInlineArrowFunction(value) || isInlineFunctionExpression(value))) {
|
|
253
216
|
context.report({
|
|
@@ -265,7 +228,6 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
265
228
|
});
|
|
266
229
|
return;
|
|
267
230
|
}
|
|
268
|
-
// Check for expensive computations
|
|
269
231
|
if (detectExpensiveComputations && isExpensiveComputation(value, minComputationComplexity)) {
|
|
270
232
|
const complexity = estimateComplexity(value);
|
|
271
233
|
context.report({
|
|
@@ -284,7 +246,6 @@ exports.reactRenderOptimization = (0, eslint_devkit_2.createRule)({
|
|
|
284
246
|
}
|
|
285
247
|
}
|
|
286
248
|
catch {
|
|
287
|
-
// Silently skip if there's an error processing this attribute
|
|
288
249
|
return;
|
|
289
250
|
}
|
|
290
251
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.checkedRequiresOnchangeOrReadonly = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -36,7 +31,6 @@ exports.checkedRequiresOnchangeOrReadonly = (0, eslint_devkit_1.createRule)({
|
|
|
36
31
|
return;
|
|
37
32
|
}
|
|
38
33
|
const tagName = node.openingElement.name.name;
|
|
39
|
-
// Only check input and textarea elements
|
|
40
34
|
if (!['input', 'textarea', 'select'].includes(tagName)) {
|
|
41
35
|
return;
|
|
42
36
|
}
|
|
@@ -62,7 +56,6 @@ exports.checkedRequiresOnchangeOrReadonly = (0, eslint_devkit_1.createRule)({
|
|
|
62
56
|
hasReadOnly = true;
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
|
-
// Report if checked/value is present but no onChange/readOnly
|
|
66
59
|
if ((hasChecked || hasValue) && !hasOnChange && !hasReadOnly) {
|
|
67
60
|
context.report({
|
|
68
61
|
node: node.openingElement.name,
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.defaultPropsMatchPropTypes = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -33,7 +28,6 @@ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
|
|
|
33
28
|
const propTypes = new Map();
|
|
34
29
|
const defaultProps = new Map();
|
|
35
30
|
return {
|
|
36
|
-
// Collect propTypes (PropertyDefinition is used by TypeScript parser)
|
|
37
31
|
'PropertyDefinition[key.name="propTypes"]'(node) {
|
|
38
32
|
if (node.value && node.value.type === 'ObjectExpression') {
|
|
39
33
|
for (const prop of node.value.properties) {
|
|
@@ -43,7 +37,6 @@ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
|
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
},
|
|
46
|
-
// Collect defaultProps (PropertyDefinition is used by TypeScript parser)
|
|
47
40
|
'PropertyDefinition[key.name="defaultProps"]'(node) {
|
|
48
41
|
if (node.value && node.value.type === 'ObjectExpression') {
|
|
49
42
|
for (const prop of node.value.properties) {
|
|
@@ -53,11 +46,9 @@ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
|
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
48
|
},
|
|
56
|
-
// Check after collecting both
|
|
57
49
|
'ClassDeclaration:exit'() {
|
|
58
50
|
for (const [propName, defaultProp] of defaultProps) {
|
|
59
51
|
const propType = propTypes.get(propName);
|
|
60
|
-
// Only check if both values are expressions (not patterns or TSEmptyBodyFunctionExpression)
|
|
61
52
|
if (propType &&
|
|
62
53
|
defaultProp.value &&
|
|
63
54
|
propType.value &&
|
|
@@ -72,19 +63,13 @@ exports.defaultPropsMatchPropTypes = (0, eslint_devkit_1.createRule)({
|
|
|
72
63
|
});
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
|
-
// Clear maps for next class
|
|
76
66
|
propTypes.clear();
|
|
77
67
|
defaultProps.clear();
|
|
78
68
|
},
|
|
79
69
|
};
|
|
80
70
|
},
|
|
81
71
|
});
|
|
82
|
-
/**
|
|
83
|
-
* Check if default value is compatible with prop type
|
|
84
|
-
*/
|
|
85
72
|
function isCompatibleDefaultValue(defaultValue, propType) {
|
|
86
|
-
// This is a simplified check - in practice, you'd want more comprehensive validation
|
|
87
|
-
// For now, just check if both are literals of the same type
|
|
88
73
|
if (defaultValue.type === 'Literal' && propType.type === 'MemberExpression') {
|
|
89
74
|
const propTypeName = getPropTypeName(propType);
|
|
90
75
|
const defaultType = typeof defaultValue.value;
|
|
@@ -96,14 +81,11 @@ function isCompatibleDefaultValue(defaultValue, propType) {
|
|
|
96
81
|
case 'bool':
|
|
97
82
|
return defaultType === 'boolean';
|
|
98
83
|
default:
|
|
99
|
-
return true;
|
|
84
|
+
return true;
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
|
-
return true;
|
|
87
|
+
return true;
|
|
103
88
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Extract prop type name from PropTypes expression
|
|
106
|
-
*/
|
|
107
89
|
function getPropTypeName(node) {
|
|
108
90
|
if (node.object.type === 'Identifier' &&
|
|
109
91
|
node.object.name === 'PropTypes' &&
|
|
@@ -112,9 +94,6 @@ function getPropTypeName(node) {
|
|
|
112
94
|
}
|
|
113
95
|
return '';
|
|
114
96
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Check if a node is a pattern (not an expression)
|
|
117
|
-
*/
|
|
118
97
|
function isPattern(node) {
|
|
119
98
|
return node.type === 'AssignmentPattern' || node.type === 'ArrayPattern' || node.type === 'ObjectPattern';
|
|
120
99
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
3
|
exports.displayName = void 0;
|
|
9
4
|
const eslint_devkit_1 = require("@interlace/eslint-devkit");
|
|
@@ -31,7 +26,6 @@ exports.displayName = (0, eslint_devkit_1.createRule)({
|
|
|
31
26
|
defaultOptions: [],
|
|
32
27
|
create(context) {
|
|
33
28
|
return {
|
|
34
|
-
// Check class components
|
|
35
29
|
ClassDeclaration(node) {
|
|
36
30
|
if (isReactComponent(node)) {
|
|
37
31
|
const hasDisplayName = hasDisplayNameProperty(node);
|
|
@@ -43,7 +37,6 @@ exports.displayName = (0, eslint_devkit_1.createRule)({
|
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
},
|
|
46
|
-
// Check function components
|
|
47
40
|
'VariableDeclarator, FunctionDeclaration'(node) {
|
|
48
41
|
const component = getComponentFromDeclaration(node);
|
|
49
42
|
if (component && isReactComponentFunction(component) && !hasDisplayNameInScope()) {
|
|
@@ -56,9 +49,6 @@ exports.displayName = (0, eslint_devkit_1.createRule)({
|
|
|
56
49
|
};
|
|
57
50
|
},
|
|
58
51
|
});
|
|
59
|
-
/**
|
|
60
|
-
* Check if class declaration is a React component
|
|
61
|
-
*/
|
|
62
52
|
function isReactComponent(node) {
|
|
63
53
|
if (!node.superClass)
|
|
64
54
|
return false;
|
|
@@ -73,9 +63,6 @@ function isReactComponent(node) {
|
|
|
73
63
|
}
|
|
74
64
|
return false;
|
|
75
65
|
}
|
|
76
|
-
/**
|
|
77
|
-
* Check if class has displayName property
|
|
78
|
-
*/
|
|
79
66
|
function hasDisplayNameProperty(node) {
|
|
80
67
|
for (const member of node.body.body) {
|
|
81
68
|
if (member.type === 'PropertyDefinition' &&
|
|
@@ -87,9 +74,6 @@ function hasDisplayNameProperty(node) {
|
|
|
87
74
|
}
|
|
88
75
|
return false;
|
|
89
76
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Get component from declaration
|
|
92
|
-
*/
|
|
93
77
|
function getComponentFromDeclaration(node) {
|
|
94
78
|
if (node.type === 'FunctionDeclaration') {
|
|
95
79
|
return node;
|
|
@@ -101,34 +85,19 @@ function getComponentFromDeclaration(node) {
|
|
|
101
85
|
}
|
|
102
86
|
return null;
|
|
103
87
|
}
|
|
104
|
-
/**
|
|
105
|
-
* Check if function is a React component
|
|
106
|
-
*/
|
|
107
88
|
function isReactComponentFunction(node) {
|
|
108
|
-
// Simple heuristic: check if function returns JSX or contains JSX
|
|
109
89
|
const body = node.type === 'FunctionDeclaration' ? node.body : node.body;
|
|
110
90
|
return containsJSX(body);
|
|
111
91
|
}
|
|
112
|
-
/**
|
|
113
|
-
* Check if component has displayName in scope
|
|
114
|
-
*/
|
|
115
92
|
function hasDisplayNameInScope() {
|
|
116
|
-
|
|
117
|
-
// This is a simplified check - in practice, you'd want to check the scope
|
|
118
|
-
return false; // For now, always require explicit displayName
|
|
93
|
+
return false;
|
|
119
94
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Get component name node for reporting
|
|
122
|
-
*/
|
|
123
95
|
function getComponentNameNode(node) {
|
|
124
96
|
if (node.type === 'FunctionDeclaration') {
|
|
125
97
|
return node.id || node;
|
|
126
98
|
}
|
|
127
99
|
return node.id || node;
|
|
128
100
|
}
|
|
129
|
-
/**
|
|
130
|
-
* Check if node contains JSX
|
|
131
|
-
*/
|
|
132
101
|
function containsJSX(node, visited = new Set()) {
|
|
133
102
|
if (!node)
|
|
134
103
|
return false;
|
|
@@ -138,7 +107,6 @@ function containsJSX(node, visited = new Set()) {
|
|
|
138
107
|
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
|
139
108
|
return true;
|
|
140
109
|
}
|
|
141
|
-
// Skip non-child keys to avoid circular references
|
|
142
110
|
const skipKeys = new Set(['parent', 'range', 'loc', 'start', 'end', 'tokens', 'comments']);
|
|
143
111
|
for (const key in node) {
|
|
144
112
|
if (skipKeys.has(key))
|