eslint-plugin-react-x 1.23.3-next.8 → 1.24.0-beta.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/dist/index.js +410 -478
- package/dist/index.mjs +410 -478
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F, O, isString, not, or, isNullable } from '@eslint-react/eff';
|
|
2
1
|
import * as JSX7 from '@eslint-react/jsx';
|
|
3
2
|
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
|
|
4
3
|
import * as AST11 from '@eslint-react/ast';
|
|
5
4
|
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
5
|
+
import { _ } from '@eslint-react/eff';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var name = "eslint-plugin-react-x";
|
|
18
|
-
var version = "1.
|
|
18
|
+
var version = "1.24.0-beta.0";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -38,18 +38,19 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
38
38
|
},
|
|
39
39
|
name: RULE_NAME,
|
|
40
40
|
create(context) {
|
|
41
|
-
function getReportDescriptor(node) {
|
|
42
|
-
return node.value != null ? O.none() : O.some({
|
|
43
|
-
messageId: "avoidShorthandBoolean",
|
|
44
|
-
node,
|
|
45
|
-
data: {
|
|
46
|
-
propName: JSX7.getPropName(node)
|
|
47
|
-
},
|
|
48
|
-
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
41
|
return {
|
|
52
|
-
JSXAttribute
|
|
42
|
+
JSXAttribute(node) {
|
|
43
|
+
if (node.value === null) {
|
|
44
|
+
context.report({
|
|
45
|
+
messageId: "avoidShorthandBoolean",
|
|
46
|
+
node,
|
|
47
|
+
data: {
|
|
48
|
+
propName: JSX7.getPropName(node)
|
|
49
|
+
},
|
|
50
|
+
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
53
54
|
};
|
|
54
55
|
},
|
|
55
56
|
defaultOptions: []
|
|
@@ -112,7 +113,7 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
112
113
|
if (component == null || !AST11.isFunction(component)) {
|
|
113
114
|
return;
|
|
114
115
|
}
|
|
115
|
-
const
|
|
116
|
+
const ref = component.params[1];
|
|
116
117
|
if (ref != null) {
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
@@ -134,15 +135,15 @@ function getName(node) {
|
|
|
134
135
|
return getName(node.expression);
|
|
135
136
|
}
|
|
136
137
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
137
|
-
return
|
|
138
|
+
return node.name;
|
|
138
139
|
}
|
|
139
140
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
140
|
-
return
|
|
141
|
+
return String(node.value);
|
|
141
142
|
}
|
|
142
143
|
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
143
|
-
return
|
|
144
|
+
return node.quasis[0]?.value.raw;
|
|
144
145
|
}
|
|
145
|
-
return
|
|
146
|
+
return _;
|
|
146
147
|
}
|
|
147
148
|
var no_access_state_in_setstate_default = createRule({
|
|
148
149
|
meta: {
|
|
@@ -161,89 +162,86 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
161
162
|
if (!context.sourceCode.text.includes("setState")) {
|
|
162
163
|
return {};
|
|
163
164
|
}
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
165
|
+
const classEntries = [];
|
|
166
|
+
const methodEntries = [];
|
|
167
|
+
const setStateEntries = [];
|
|
167
168
|
return {
|
|
168
169
|
CallExpression(node) {
|
|
169
170
|
if (!isThisSetState(node)) {
|
|
170
171
|
return;
|
|
171
172
|
}
|
|
172
|
-
|
|
173
|
+
setStateEntries.push([node, false]);
|
|
173
174
|
},
|
|
174
175
|
"CallExpression:exit"(node) {
|
|
175
176
|
if (!isThisSetState(node)) {
|
|
176
177
|
return;
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
setStateEntries.pop();
|
|
179
180
|
},
|
|
180
181
|
ClassDeclaration(node) {
|
|
181
|
-
|
|
182
|
+
classEntries.push([node, isClassComponent(node)]);
|
|
182
183
|
},
|
|
183
184
|
"ClassDeclaration:exit"() {
|
|
184
|
-
|
|
185
|
+
classEntries.pop();
|
|
185
186
|
},
|
|
186
187
|
ClassExpression(node) {
|
|
187
|
-
|
|
188
|
+
classEntries.push([node, isClassComponent(node)]);
|
|
188
189
|
},
|
|
189
190
|
"ClassExpression:exit"() {
|
|
190
|
-
|
|
191
|
+
classEntries.pop();
|
|
191
192
|
},
|
|
192
193
|
MemberExpression(node) {
|
|
193
194
|
if (!AST11.isThisExpression(node.object)) {
|
|
194
195
|
return;
|
|
195
196
|
}
|
|
196
|
-
const [currClass, isComponent] =
|
|
197
|
+
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
197
198
|
if (currClass == null || !isComponent) {
|
|
198
199
|
return;
|
|
199
200
|
}
|
|
200
|
-
const [currMethod, isStatic] =
|
|
201
|
+
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
201
202
|
if (currMethod == null || isStatic) {
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
204
|
-
const [setState, hasThisState] =
|
|
205
|
+
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
205
206
|
if (setState == null || hasThisState) {
|
|
206
207
|
return;
|
|
207
208
|
}
|
|
208
|
-
if (
|
|
209
|
+
if (getName(node.property) !== "state") {
|
|
209
210
|
return;
|
|
210
211
|
}
|
|
211
212
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
212
213
|
},
|
|
213
214
|
MethodDefinition(node) {
|
|
214
|
-
|
|
215
|
+
methodEntries.push([node, node.static]);
|
|
215
216
|
},
|
|
216
217
|
"MethodDefinition:exit"() {
|
|
217
|
-
|
|
218
|
+
methodEntries.pop();
|
|
218
219
|
},
|
|
219
220
|
PropertyDefinition(node) {
|
|
220
|
-
|
|
221
|
+
methodEntries.push([node, node.static]);
|
|
221
222
|
},
|
|
222
223
|
"PropertyDefinition:exit"() {
|
|
223
|
-
|
|
224
|
+
methodEntries.pop();
|
|
224
225
|
},
|
|
225
226
|
VariableDeclarator(node) {
|
|
226
|
-
const [currClass, isComponent] =
|
|
227
|
+
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
227
228
|
if (currClass == null || !isComponent) {
|
|
228
229
|
return;
|
|
229
230
|
}
|
|
230
|
-
const [currMethod, isStatic] =
|
|
231
|
+
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
231
232
|
if (currMethod == null || isStatic) {
|
|
232
233
|
return;
|
|
233
234
|
}
|
|
234
|
-
const [setState, hasThisState] =
|
|
235
|
+
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
235
236
|
if (setState == null || hasThisState) {
|
|
236
237
|
return;
|
|
237
238
|
}
|
|
238
239
|
if (!(node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
239
240
|
return;
|
|
240
241
|
}
|
|
241
|
-
const hasState = node.id.properties.some(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
return false;
|
|
246
|
-
});
|
|
242
|
+
const hasState = node.id.properties.some(
|
|
243
|
+
(prop) => prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key) && getName(prop.key) === "state"
|
|
244
|
+
);
|
|
247
245
|
if (!hasState) {
|
|
248
246
|
return;
|
|
249
247
|
}
|
|
@@ -296,32 +294,32 @@ function isUsingReactChildren(node, context) {
|
|
|
296
294
|
function getMapIndexParamName(node, context) {
|
|
297
295
|
const { callee } = node;
|
|
298
296
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
299
|
-
return
|
|
297
|
+
return _;
|
|
300
298
|
}
|
|
301
299
|
if (callee.property.type !== AST_NODE_TYPES.Identifier) {
|
|
302
|
-
return
|
|
300
|
+
return _;
|
|
303
301
|
}
|
|
304
302
|
const { name: name2 } = callee.property;
|
|
305
303
|
if (!iteratorFunctionIndexParamPosition.has(name2)) {
|
|
306
|
-
return
|
|
304
|
+
return _;
|
|
307
305
|
}
|
|
308
306
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
309
307
|
if (callbackArg == null) {
|
|
310
|
-
return
|
|
308
|
+
return _;
|
|
311
309
|
}
|
|
312
310
|
if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
313
|
-
return
|
|
311
|
+
return _;
|
|
314
312
|
}
|
|
315
313
|
const { params } = callbackArg;
|
|
316
314
|
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
|
|
317
|
-
if (
|
|
318
|
-
return
|
|
315
|
+
if (indexParamPosition == null) {
|
|
316
|
+
return _;
|
|
319
317
|
}
|
|
320
318
|
if (params.length < indexParamPosition + 1) {
|
|
321
|
-
return
|
|
319
|
+
return _;
|
|
322
320
|
}
|
|
323
321
|
const param = params.at(indexParamPosition);
|
|
324
|
-
return param != null && "name" in param ?
|
|
322
|
+
return param != null && "name" in param ? param.name : _;
|
|
325
323
|
}
|
|
326
324
|
var no_array_index_key_default = createRule({
|
|
327
325
|
meta: {
|
|
@@ -339,7 +337,7 @@ var no_array_index_key_default = createRule({
|
|
|
339
337
|
create(context) {
|
|
340
338
|
const indexParamNames = [];
|
|
341
339
|
function isArrayIndex(node) {
|
|
342
|
-
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(
|
|
340
|
+
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name2) => name2 != null && name2 === node.name);
|
|
343
341
|
}
|
|
344
342
|
function isCreateOrCloneElementCall(node) {
|
|
345
343
|
return isCreateElementCall(node, context) || isCloneElementCall(node, context);
|
|
@@ -348,7 +346,7 @@ var no_array_index_key_default = createRule({
|
|
|
348
346
|
switch (node.type) {
|
|
349
347
|
// key={bar}
|
|
350
348
|
case AST_NODE_TYPES.Identifier: {
|
|
351
|
-
if (indexParamNames.some(
|
|
349
|
+
if (indexParamNames.some((name2) => name2 != null && name2 === node.name)) {
|
|
352
350
|
return [{
|
|
353
351
|
messageId: "noArrayIndexKey",
|
|
354
352
|
node
|
|
@@ -402,7 +400,7 @@ var no_array_index_key_default = createRule({
|
|
|
402
400
|
if (!isCreateOrCloneElementCall(node)) {
|
|
403
401
|
return;
|
|
404
402
|
}
|
|
405
|
-
const [
|
|
403
|
+
const [, props] = node.arguments;
|
|
406
404
|
if (props?.type !== AST_NODE_TYPES.ObjectExpression) {
|
|
407
405
|
return;
|
|
408
406
|
}
|
|
@@ -585,10 +583,17 @@ var no_children_prop_default = createRule({
|
|
|
585
583
|
create(context) {
|
|
586
584
|
return {
|
|
587
585
|
JSXElement(node) {
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
586
|
+
const prop = JSX7.getProp(
|
|
587
|
+
"children",
|
|
588
|
+
context.sourceCode.getScope(node),
|
|
589
|
+
node.openingElement.attributes
|
|
590
|
+
);
|
|
591
|
+
if (prop) {
|
|
592
|
+
context.report({
|
|
593
|
+
messageId: "noChildrenProp",
|
|
594
|
+
node: prop
|
|
595
|
+
});
|
|
596
|
+
}
|
|
592
597
|
}
|
|
593
598
|
};
|
|
594
599
|
},
|
|
@@ -657,7 +662,7 @@ var no_class_component_default = createRule({
|
|
|
657
662
|
...listeners,
|
|
658
663
|
"Program:exit"(node) {
|
|
659
664
|
const components = ctx.getAllComponents(node);
|
|
660
|
-
for (const { name: name2, node: component } of components.values()) {
|
|
665
|
+
for (const { name: name2 = "anonymous", node: component } of components.values()) {
|
|
661
666
|
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
662
667
|
continue;
|
|
663
668
|
}
|
|
@@ -666,7 +671,7 @@ var no_class_component_default = createRule({
|
|
|
666
671
|
node: component,
|
|
667
672
|
data: {
|
|
668
673
|
// eslint-disable-next-line eslint-plugin/no-unused-placeholders
|
|
669
|
-
name:
|
|
674
|
+
name: name2
|
|
670
675
|
}
|
|
671
676
|
});
|
|
672
677
|
}
|
|
@@ -732,22 +737,21 @@ var no_comment_textnodes_default = createRule({
|
|
|
732
737
|
const rawValue = context.sourceCode.getText(node);
|
|
733
738
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
734
739
|
}
|
|
735
|
-
const
|
|
740
|
+
const visitorFunction = (node) => {
|
|
736
741
|
if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
737
|
-
return
|
|
742
|
+
return;
|
|
738
743
|
}
|
|
739
744
|
if (!hasCommentLike(node)) {
|
|
740
|
-
return
|
|
745
|
+
return;
|
|
741
746
|
}
|
|
742
747
|
if (!node.parent.type.includes("JSX")) {
|
|
743
|
-
return
|
|
748
|
+
return;
|
|
744
749
|
}
|
|
745
|
-
|
|
750
|
+
context.report({
|
|
746
751
|
messageId: "noCommentTextnodes",
|
|
747
752
|
node
|
|
748
753
|
});
|
|
749
754
|
};
|
|
750
|
-
const visitorFunction = F.flow(getReportDescriptor, O.map(context.report), F.constVoid);
|
|
751
755
|
return {
|
|
752
756
|
JSXText: visitorFunction,
|
|
753
757
|
Literal: visitorFunction
|
|
@@ -773,20 +777,22 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
773
777
|
},
|
|
774
778
|
name: RULE_NAME15,
|
|
775
779
|
create(context) {
|
|
776
|
-
|
|
780
|
+
const visitorFunction = (node) => {
|
|
777
781
|
const jsxExpContainer = node.parent?.parent;
|
|
778
782
|
if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
779
|
-
return
|
|
783
|
+
return;
|
|
780
784
|
}
|
|
781
785
|
if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
782
|
-
return
|
|
786
|
+
return;
|
|
783
787
|
}
|
|
784
788
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
785
|
-
return
|
|
789
|
+
return;
|
|
786
790
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
791
|
+
context.report({
|
|
792
|
+
messageId: "noComplexConditionalRendering",
|
|
793
|
+
node: jsxExpContainer
|
|
794
|
+
});
|
|
795
|
+
};
|
|
790
796
|
return {
|
|
791
797
|
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
792
798
|
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
@@ -1030,13 +1036,9 @@ var no_create_ref_default = createRule({
|
|
|
1030
1036
|
create(context) {
|
|
1031
1037
|
return {
|
|
1032
1038
|
CallExpression(node) {
|
|
1033
|
-
if (
|
|
1034
|
-
|
|
1039
|
+
if (isCreateRefCall(node, context) && !AST11.findParentNode(node, isClassComponent)) {
|
|
1040
|
+
context.report({ messageId: "noCreateRef", node });
|
|
1035
1041
|
}
|
|
1036
|
-
if (O.isSome(AST11.findParentNode(node, isClassComponent))) {
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
context.report({ messageId: "noCreateRef", node });
|
|
1040
1042
|
}
|
|
1041
1043
|
};
|
|
1042
1044
|
},
|
|
@@ -1078,14 +1080,10 @@ var no_default_props_default = createRule({
|
|
|
1078
1080
|
if (!isComponentName(object.name)) {
|
|
1079
1081
|
return;
|
|
1080
1082
|
}
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
);
|
|
1086
|
-
if (!isComponent) {
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1083
|
+
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1084
|
+
const variableNode = VAR.getVariableNode(variable, 0);
|
|
1085
|
+
if (variableNode === _) return;
|
|
1086
|
+
if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
|
|
1089
1087
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1090
1088
|
},
|
|
1091
1089
|
PropertyDefinition(node) {
|
|
@@ -1110,19 +1108,19 @@ function getName2(node) {
|
|
|
1110
1108
|
return getName2(node.expression);
|
|
1111
1109
|
}
|
|
1112
1110
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
1113
|
-
return
|
|
1111
|
+
return node.name;
|
|
1114
1112
|
}
|
|
1115
1113
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
1116
|
-
return
|
|
1114
|
+
return node.value?.toString();
|
|
1117
1115
|
}
|
|
1118
1116
|
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
1119
|
-
return
|
|
1117
|
+
return node.quasis[0]?.value.raw;
|
|
1120
1118
|
}
|
|
1121
|
-
return
|
|
1119
|
+
return _;
|
|
1122
1120
|
}
|
|
1123
1121
|
function isAssignmentToThisState(node) {
|
|
1124
1122
|
const { left } = node;
|
|
1125
|
-
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) &&
|
|
1123
|
+
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName2(left.property) === "state";
|
|
1126
1124
|
}
|
|
1127
1125
|
function isConstructorFunction(node) {
|
|
1128
1126
|
return AST11.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST11.isOneOf([AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
@@ -1141,31 +1139,26 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1141
1139
|
},
|
|
1142
1140
|
name: RULE_NAME22,
|
|
1143
1141
|
create(context) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
O.bind("parentClass", () => AST11.findParentNodeGuard(
|
|
1142
|
+
return {
|
|
1143
|
+
AssignmentExpression(node) {
|
|
1144
|
+
if (!isAssignmentToThisState(node)) {
|
|
1145
|
+
return;
|
|
1146
|
+
}
|
|
1147
|
+
const parentClass = AST11.findParentNodeGuard(
|
|
1151
1148
|
node,
|
|
1152
1149
|
AST11.isOneOf([
|
|
1153
1150
|
AST_NODE_TYPES.ClassDeclaration,
|
|
1154
1151
|
AST_NODE_TYPES.ClassExpression
|
|
1155
1152
|
])
|
|
1156
|
-
)
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
return {
|
|
1168
|
-
AssignmentExpression: F.flow(getReportDescriptor, O.map(context.report))
|
|
1153
|
+
);
|
|
1154
|
+
if (!parentClass) return;
|
|
1155
|
+
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNodeGuard(node, isConstructorFunction)) {
|
|
1156
|
+
context.report({
|
|
1157
|
+
messageId: "noDirectMutationState",
|
|
1158
|
+
node
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1169
1162
|
};
|
|
1170
1163
|
},
|
|
1171
1164
|
defaultOptions: []
|
|
@@ -1196,7 +1189,7 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1196
1189
|
continue;
|
|
1197
1190
|
}
|
|
1198
1191
|
const name2 = attr.name.name;
|
|
1199
|
-
if (
|
|
1192
|
+
if (typeof name2 !== "string") {
|
|
1200
1193
|
continue;
|
|
1201
1194
|
}
|
|
1202
1195
|
if (!props.includes(name2)) {
|
|
@@ -1260,16 +1253,10 @@ var no_duplicate_key_default = createRule({
|
|
|
1260
1253
|
break;
|
|
1261
1254
|
}
|
|
1262
1255
|
default: {
|
|
1263
|
-
const
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
O.bind("arg0", ({ call: call2 }) => O.fromNullable(call2.arguments[0]))
|
|
1268
|
-
);
|
|
1269
|
-
if (O.isNone(mbEntry)) {
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
const { arg0, call, iter } = mbEntry.value;
|
|
1256
|
+
const call = AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose);
|
|
1257
|
+
const iter = call && AST11.findParentNodeStop(jsxElement, call, AST11.isFunction);
|
|
1258
|
+
const arg0 = call?.arguments[0];
|
|
1259
|
+
if (!call || !iter || !arg0) return;
|
|
1273
1260
|
if (AST11.unwrapTypeExpression(arg0) !== iter) {
|
|
1274
1261
|
return;
|
|
1275
1262
|
}
|
|
@@ -1370,21 +1357,19 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1370
1357
|
if (arg0 == null) {
|
|
1371
1358
|
return [];
|
|
1372
1359
|
}
|
|
1373
|
-
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) =>
|
|
1374
|
-
const fixedArg1Text = match(arg1).with(P.nullish, () =>
|
|
1375
|
-
if (
|
|
1360
|
+
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => _);
|
|
1361
|
+
const fixedArg1Text = match(arg1).with(P.nullish, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: P.not("ref") }, (n) => `ref: ${n.name}`).otherwise(() => _);
|
|
1362
|
+
if (fixedArg0Text == null || fixedArg1Text == null) {
|
|
1376
1363
|
return [];
|
|
1377
1364
|
}
|
|
1378
|
-
const fixedPropsText = fixedArg0Text.value;
|
|
1379
|
-
const fixedRefText = fixedArg1Text.value;
|
|
1380
1365
|
if (typeArg0 == null || typeArg1 == null) {
|
|
1381
1366
|
return [
|
|
1382
1367
|
fixer.replaceText(
|
|
1383
1368
|
arg0,
|
|
1384
1369
|
[
|
|
1385
1370
|
"{",
|
|
1386
|
-
|
|
1387
|
-
|
|
1371
|
+
fixedArg1Text + ",",
|
|
1372
|
+
fixedArg0Text,
|
|
1388
1373
|
"}"
|
|
1389
1374
|
].join(" ")
|
|
1390
1375
|
),
|
|
@@ -1396,8 +1381,8 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1396
1381
|
arg0,
|
|
1397
1382
|
[
|
|
1398
1383
|
"{",
|
|
1399
|
-
|
|
1400
|
-
|
|
1384
|
+
fixedArg1Text + ",",
|
|
1385
|
+
fixedArg0Text,
|
|
1401
1386
|
"}:",
|
|
1402
1387
|
getText(typeArg1),
|
|
1403
1388
|
"&",
|
|
@@ -1428,17 +1413,17 @@ var no_implicit_key_default = createRule({
|
|
|
1428
1413
|
},
|
|
1429
1414
|
name: RULE_NAME26,
|
|
1430
1415
|
create(context) {
|
|
1431
|
-
function getReportDescriptor(node) {
|
|
1432
|
-
const initialScope = context.sourceCode.getScope(node);
|
|
1433
|
-
const keyPropFound = JSX7.findPropInAttributes(node.attributes, initialScope)("key");
|
|
1434
|
-
const keyPropOnElement = node.attributes.some((n) => AST11.is(AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key");
|
|
1435
|
-
if (O.isSome(keyPropFound) && !keyPropOnElement) {
|
|
1436
|
-
return O.some({ messageId: "noImplicitKey", node: keyPropFound.value });
|
|
1437
|
-
}
|
|
1438
|
-
return O.none();
|
|
1439
|
-
}
|
|
1440
1416
|
return {
|
|
1441
|
-
JSXOpeningElement
|
|
1417
|
+
JSXOpeningElement(node) {
|
|
1418
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1419
|
+
const keyPropFound = JSX7.findPropInAttributes("key", initialScope, node.attributes);
|
|
1420
|
+
const keyPropOnElement = node.attributes.some(
|
|
1421
|
+
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1422
|
+
);
|
|
1423
|
+
if (keyPropFound && !keyPropOnElement) {
|
|
1424
|
+
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1442
1427
|
};
|
|
1443
1428
|
},
|
|
1444
1429
|
defaultOptions: []
|
|
@@ -1484,11 +1469,12 @@ function inspectVariantTypes(types) {
|
|
|
1484
1469
|
const booleans = types.filter(tsHelpers.isBooleanType);
|
|
1485
1470
|
switch (true) {
|
|
1486
1471
|
case (booleans.length === 1 && booleans[0] != null): {
|
|
1487
|
-
const
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
)
|
|
1491
|
-
|
|
1472
|
+
const first = booleans[0];
|
|
1473
|
+
if (isTrueLiteralType(first)) {
|
|
1474
|
+
variantTypes.add("truthy boolean");
|
|
1475
|
+
} else if (isFalseLiteralType(first)) {
|
|
1476
|
+
variantTypes.add("falsy boolean");
|
|
1477
|
+
}
|
|
1492
1478
|
break;
|
|
1493
1479
|
}
|
|
1494
1480
|
case booleans.length === 2: {
|
|
@@ -1498,17 +1484,17 @@ function inspectVariantTypes(types) {
|
|
|
1498
1484
|
}
|
|
1499
1485
|
const strings = types.filter(tsHelpers.isStringType);
|
|
1500
1486
|
if (strings.length > 0) {
|
|
1501
|
-
const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType),
|
|
1487
|
+
const evaluated = match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), () => "truthy string").when((types2) => types2.every(tsHelpers.isFalsyStringType), () => "falsy string").otherwise(() => "string");
|
|
1502
1488
|
variantTypes.add(evaluated);
|
|
1503
1489
|
}
|
|
1504
1490
|
const bigints = types.filter(tsHelpers.isBigIntType);
|
|
1505
1491
|
if (bigints.length > 0) {
|
|
1506
|
-
const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType),
|
|
1492
|
+
const evaluated = match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(tsHelpers.isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
|
|
1507
1493
|
variantTypes.add(evaluated);
|
|
1508
1494
|
}
|
|
1509
1495
|
const numbers = types.filter(tsHelpers.isNumberType);
|
|
1510
1496
|
if (numbers.length > 0) {
|
|
1511
|
-
const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType),
|
|
1497
|
+
const evaluated = match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), () => "truthy number").when((types2) => types2.every(tsHelpers.isFalsyNumberType), () => "falsy number").otherwise(() => "number");
|
|
1512
1498
|
variantTypes.add(evaluated);
|
|
1513
1499
|
}
|
|
1514
1500
|
if (types.some(tsHelpers.isEnumType)) {
|
|
@@ -1526,19 +1512,15 @@ function inspectVariantTypes(types) {
|
|
|
1526
1512
|
return variantTypes;
|
|
1527
1513
|
}
|
|
1528
1514
|
function isInitExpression(node) {
|
|
1515
|
+
if (node == null) return false;
|
|
1529
1516
|
return node.type !== AST_NODE_TYPES.VariableDeclaration;
|
|
1530
1517
|
}
|
|
1531
|
-
function getVariableInitExpression(at) {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
(d) => "init" in d.node ? O.fromNullable(d.node.init) : O.none()
|
|
1538
|
-
),
|
|
1539
|
-
O.filter(isInitExpression)
|
|
1540
|
-
);
|
|
1541
|
-
};
|
|
1518
|
+
function getVariableInitExpression(variable, at) {
|
|
1519
|
+
const def = variable?.defs[at];
|
|
1520
|
+
if (def?.node === _ || !("init" in def.node)) {
|
|
1521
|
+
return _;
|
|
1522
|
+
}
|
|
1523
|
+
return isInitExpression(def.node.init) ? def.node.init : _;
|
|
1542
1524
|
}
|
|
1543
1525
|
var no_leaked_conditional_rendering_default = createRule({
|
|
1544
1526
|
meta: {
|
|
@@ -1572,19 +1554,20 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1572
1554
|
];
|
|
1573
1555
|
const services = ESLintUtils.getParserServices(context, false);
|
|
1574
1556
|
function getReportDescriptor(node) {
|
|
1575
|
-
|
|
1557
|
+
if (node === _) return _;
|
|
1558
|
+
return match(node).when(AST11.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1576
1559
|
const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1577
1560
|
if (isLeftUnaryNot) {
|
|
1578
1561
|
return getReportDescriptor(right);
|
|
1579
1562
|
}
|
|
1580
1563
|
const initialScope = context.sourceCode.getScope(left);
|
|
1581
|
-
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" ||
|
|
1564
|
+
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.toResolved({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1582
1565
|
if (isLeftNan) {
|
|
1583
|
-
return
|
|
1566
|
+
return {
|
|
1584
1567
|
messageId: "noLeakedConditionalRendering",
|
|
1585
1568
|
node: left,
|
|
1586
1569
|
data: { value: context.sourceCode.getText(left) }
|
|
1587
|
-
}
|
|
1570
|
+
};
|
|
1588
1571
|
}
|
|
1589
1572
|
const leftType = getConstrainedTypeAtLocation(services, left);
|
|
1590
1573
|
const leftTypeVariants = inspectVariantTypes(unionTypeParts(leftType));
|
|
@@ -1592,22 +1575,24 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1592
1575
|
if (isLeftValid) {
|
|
1593
1576
|
return getReportDescriptor(right);
|
|
1594
1577
|
}
|
|
1595
|
-
return
|
|
1578
|
+
return {
|
|
1596
1579
|
messageId: "noLeakedConditionalRendering",
|
|
1597
1580
|
node: left,
|
|
1598
1581
|
data: { value: context.sourceCode.getText(left) }
|
|
1599
|
-
}
|
|
1582
|
+
};
|
|
1600
1583
|
}).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
|
|
1601
|
-
return
|
|
1584
|
+
return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
|
|
1602
1585
|
}).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
);
|
|
1608
|
-
}).otherwise(O.none);
|
|
1586
|
+
const variable = VAR.findVariable(n.name, context.sourceCode.getScope(n));
|
|
1587
|
+
const initExpression = getVariableInitExpression(variable, 0);
|
|
1588
|
+
return getReportDescriptor(initExpression);
|
|
1589
|
+
}).otherwise(() => _);
|
|
1609
1590
|
}
|
|
1610
|
-
const visitorFunction =
|
|
1591
|
+
const visitorFunction = (node) => {
|
|
1592
|
+
const descriptor = getReportDescriptor(node);
|
|
1593
|
+
if (descriptor === _) return;
|
|
1594
|
+
context.report(descriptor);
|
|
1595
|
+
};
|
|
1611
1596
|
return {
|
|
1612
1597
|
"JSXExpressionContainer > ConditionalExpression": visitorFunction,
|
|
1613
1598
|
"JSXExpressionContainer > LogicalExpression": visitorFunction
|
|
@@ -1643,13 +1628,13 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1643
1628
|
const components = ctx.getAllComponents(node);
|
|
1644
1629
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1645
1630
|
const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
|
|
1646
|
-
if (
|
|
1631
|
+
if (AST11.getFunctionIdentifier(node2)) {
|
|
1647
1632
|
continue;
|
|
1648
1633
|
}
|
|
1649
1634
|
if (!isMemoOrForwardRef) {
|
|
1650
1635
|
continue;
|
|
1651
1636
|
}
|
|
1652
|
-
if (
|
|
1637
|
+
if (!displayName) {
|
|
1653
1638
|
context.report({
|
|
1654
1639
|
messageId: "noMissingComponentDisplayName",
|
|
1655
1640
|
node: node2
|
|
@@ -1685,51 +1670,55 @@ var no_missing_key_default = createRule({
|
|
|
1685
1670
|
switch (node.type) {
|
|
1686
1671
|
case AST_NODE_TYPES.JSXElement: {
|
|
1687
1672
|
const initialScope = context.sourceCode.getScope(node);
|
|
1688
|
-
if (!JSX7.hasProp(
|
|
1689
|
-
return
|
|
1673
|
+
if (!JSX7.hasProp("key", initialScope, node.openingElement.attributes)) {
|
|
1674
|
+
return {
|
|
1690
1675
|
messageId: "noMissingKey",
|
|
1691
1676
|
node
|
|
1692
|
-
}
|
|
1677
|
+
};
|
|
1693
1678
|
}
|
|
1694
|
-
return
|
|
1679
|
+
return null;
|
|
1695
1680
|
}
|
|
1696
1681
|
case AST_NODE_TYPES.JSXFragment: {
|
|
1697
|
-
return
|
|
1682
|
+
return {
|
|
1698
1683
|
messageId: "noMissingKeyWithFragment",
|
|
1699
1684
|
node
|
|
1700
|
-
}
|
|
1685
|
+
};
|
|
1701
1686
|
}
|
|
1702
1687
|
default:
|
|
1703
|
-
return
|
|
1688
|
+
return null;
|
|
1704
1689
|
}
|
|
1705
1690
|
}
|
|
1706
1691
|
function checkExpression(node) {
|
|
1707
1692
|
switch (node.type) {
|
|
1708
1693
|
case AST_NODE_TYPES.ConditionalExpression:
|
|
1709
|
-
if (
|
|
1710
|
-
return
|
|
1694
|
+
if ("consequent" in node) {
|
|
1695
|
+
return checkIteratorElement(node.consequent) ?? checkIteratorElement(node.alternate);
|
|
1711
1696
|
}
|
|
1712
|
-
return
|
|
1697
|
+
return null;
|
|
1713
1698
|
case AST_NODE_TYPES.JSXElement:
|
|
1714
1699
|
case AST_NODE_TYPES.JSXFragment:
|
|
1715
1700
|
return checkIteratorElement(node);
|
|
1716
1701
|
case AST_NODE_TYPES.LogicalExpression:
|
|
1717
|
-
if (
|
|
1718
|
-
return
|
|
1702
|
+
if ("left" in node) {
|
|
1703
|
+
return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
|
|
1719
1704
|
}
|
|
1720
|
-
return
|
|
1705
|
+
return null;
|
|
1721
1706
|
default:
|
|
1722
|
-
return
|
|
1707
|
+
return null;
|
|
1723
1708
|
}
|
|
1724
1709
|
}
|
|
1725
1710
|
function checkBlockStatement(node) {
|
|
1726
|
-
|
|
1711
|
+
const descriptors = [];
|
|
1712
|
+
for (const statement of AST11.getNestedReturnStatements(node)) {
|
|
1727
1713
|
if (statement.argument == null) {
|
|
1728
|
-
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
const descriptor = checkIteratorElement(statement.argument);
|
|
1717
|
+
if (descriptor != null) {
|
|
1718
|
+
descriptors.push(descriptor);
|
|
1729
1719
|
}
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
}, []);
|
|
1720
|
+
}
|
|
1721
|
+
return descriptors;
|
|
1733
1722
|
}
|
|
1734
1723
|
return {
|
|
1735
1724
|
ArrayExpression(node) {
|
|
@@ -1742,7 +1731,7 @@ var no_missing_key_default = createRule({
|
|
|
1742
1731
|
}
|
|
1743
1732
|
const initialScope = context.sourceCode.getScope(node);
|
|
1744
1733
|
for (const element of elements) {
|
|
1745
|
-
if (!JSX7.hasProp(
|
|
1734
|
+
if (!JSX7.hasProp("key", initialScope, element.openingElement.attributes)) {
|
|
1746
1735
|
context.report({
|
|
1747
1736
|
messageId: "noMissingKey",
|
|
1748
1737
|
node: element
|
|
@@ -1755,30 +1744,24 @@ var no_missing_key_default = createRule({
|
|
|
1755
1744
|
if (state.isWithinChildrenToArray) {
|
|
1756
1745
|
return;
|
|
1757
1746
|
}
|
|
1758
|
-
const
|
|
1759
|
-
|
|
1760
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
1761
|
-
callee: {
|
|
1762
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
1763
|
-
property: {
|
|
1764
|
-
name: "from"
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
}, node);
|
|
1768
|
-
if (!isMapCall && !isArrayFromCall) {
|
|
1747
|
+
const isMapCallLike = AST11.isMapCallLoose(node);
|
|
1748
|
+
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1769
1749
|
return;
|
|
1770
1750
|
}
|
|
1771
|
-
const fn = node.arguments[
|
|
1772
|
-
if (
|
|
1751
|
+
const fn = node.arguments[isMapCallLike ? 0 : 1];
|
|
1752
|
+
if (fn?.type !== AST_NODE_TYPES.ArrowFunctionExpression && fn?.type !== AST_NODE_TYPES.FunctionExpression) {
|
|
1773
1753
|
return;
|
|
1774
1754
|
}
|
|
1775
1755
|
if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
1776
|
-
for (const
|
|
1777
|
-
context.report(
|
|
1756
|
+
for (const descriptor2 of checkBlockStatement(fn.body)) {
|
|
1757
|
+
context.report(descriptor2);
|
|
1778
1758
|
}
|
|
1779
1759
|
return;
|
|
1780
1760
|
}
|
|
1781
|
-
|
|
1761
|
+
const descriptor = checkExpression(fn.body);
|
|
1762
|
+
if (descriptor != null) {
|
|
1763
|
+
context.report(descriptor);
|
|
1764
|
+
}
|
|
1782
1765
|
},
|
|
1783
1766
|
"CallExpression:exit"(node) {
|
|
1784
1767
|
if (!isChildrenToArrayCall(node, context)) {
|
|
@@ -1801,6 +1784,9 @@ var no_missing_key_default = createRule({
|
|
|
1801
1784
|
},
|
|
1802
1785
|
defaultOptions: []
|
|
1803
1786
|
});
|
|
1787
|
+
function isArrayFromCall(node) {
|
|
1788
|
+
return node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "from";
|
|
1789
|
+
}
|
|
1804
1790
|
var RULE_NAME30 = "no-nested-components";
|
|
1805
1791
|
var RULE_FEATURES30 = [
|
|
1806
1792
|
"CHK"
|
|
@@ -1839,16 +1825,15 @@ var no_nested_components_default = createRule({
|
|
|
1839
1825
|
const isClassComponent11 = (node2) => {
|
|
1840
1826
|
return AST11.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1841
1827
|
};
|
|
1842
|
-
for (const { name:
|
|
1828
|
+
for (const { name: name2, node: component } of functionComponents) {
|
|
1843
1829
|
if (isDirectValueOfRenderPropertyLoose(component)) {
|
|
1844
1830
|
continue;
|
|
1845
1831
|
}
|
|
1846
|
-
if (
|
|
1832
|
+
if (name2 === _) {
|
|
1847
1833
|
continue;
|
|
1848
1834
|
}
|
|
1849
|
-
const name2 = componentName.value;
|
|
1850
1835
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1851
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
1836
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || !!JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer);
|
|
1852
1837
|
if (isInsideJSXPropValue) {
|
|
1853
1838
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1854
1839
|
context.report({
|
|
@@ -1871,13 +1856,8 @@ var no_nested_components_default = createRule({
|
|
|
1871
1856
|
});
|
|
1872
1857
|
continue;
|
|
1873
1858
|
}
|
|
1874
|
-
const
|
|
1875
|
-
|
|
1876
|
-
component,
|
|
1877
|
-
isFunctionComponent
|
|
1878
|
-
),
|
|
1879
|
-
not(isDirectValueOfRenderPropertyLoose)
|
|
1880
|
-
);
|
|
1859
|
+
const parentComponent = AST11.findParentNodeGuard(component, isFunctionComponent);
|
|
1860
|
+
const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1881
1861
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1882
1862
|
context.report({
|
|
1883
1863
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
@@ -1898,15 +1878,15 @@ var no_nested_components_default = createRule({
|
|
|
1898
1878
|
});
|
|
1899
1879
|
}
|
|
1900
1880
|
}
|
|
1901
|
-
for (const { name: name2, node: component } of classComponents) {
|
|
1902
|
-
if (
|
|
1881
|
+
for (const { name: name2 = "unknown", node: component } of classComponents) {
|
|
1882
|
+
if (!AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
|
|
1903
1883
|
continue;
|
|
1904
1884
|
}
|
|
1905
1885
|
context.report({
|
|
1906
1886
|
messageId: "nestedComponent",
|
|
1907
1887
|
node: component,
|
|
1908
1888
|
data: {
|
|
1909
|
-
name:
|
|
1889
|
+
name: name2
|
|
1910
1890
|
}
|
|
1911
1891
|
});
|
|
1912
1892
|
}
|
|
@@ -1951,15 +1931,11 @@ var no_prop_types_default = createRule({
|
|
|
1951
1931
|
if (!isComponentName(object.name)) {
|
|
1952
1932
|
return;
|
|
1953
1933
|
}
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
);
|
|
1959
|
-
if (!isComponent) {
|
|
1960
|
-
return;
|
|
1934
|
+
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1935
|
+
const variableNode = variable && VAR.getVariableNode(variable, 0);
|
|
1936
|
+
if (variableNode && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
|
|
1937
|
+
context.report({ messageId: "noPropTypes", node: property });
|
|
1961
1938
|
}
|
|
1962
|
-
context.report({ messageId: "noPropTypes", node: property });
|
|
1963
1939
|
},
|
|
1964
1940
|
PropertyDefinition(node) {
|
|
1965
1941
|
if (!isClassComponent(node.parent.parent)) {
|
|
@@ -2003,7 +1979,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2003
1979
|
...listeners,
|
|
2004
1980
|
"Program:exit"(node) {
|
|
2005
1981
|
const components = ctx.getAllComponents(node);
|
|
2006
|
-
for (const { name: name2, node: component, flag } of components.values()) {
|
|
1982
|
+
for (const { name: name2 = "PureComponent", node: component, flag } of components.values()) {
|
|
2007
1983
|
if ((flag & ERClassComponentFlag.PureComponent) === 0n) {
|
|
2008
1984
|
continue;
|
|
2009
1985
|
}
|
|
@@ -2014,7 +1990,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2014
1990
|
messageId: "noRedundantShouldComponentUpdate",
|
|
2015
1991
|
node: member,
|
|
2016
1992
|
data: {
|
|
2017
|
-
componentName:
|
|
1993
|
+
componentName: name2
|
|
2018
1994
|
}
|
|
2019
1995
|
});
|
|
2020
1996
|
}
|
|
@@ -2049,32 +2025,22 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2049
2025
|
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2050
2026
|
return {};
|
|
2051
2027
|
}
|
|
2052
|
-
function getReportDescriptor(node) {
|
|
2053
|
-
if (!isThisSetState(node)) {
|
|
2054
|
-
return O.none();
|
|
2055
|
-
}
|
|
2056
|
-
return F.pipe(
|
|
2057
|
-
O.Do,
|
|
2058
|
-
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
2059
|
-
O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentDidMount)),
|
|
2060
|
-
O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
|
|
2061
|
-
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2062
|
-
O.filter(
|
|
2063
|
-
({
|
|
2064
|
-
clazz,
|
|
2065
|
-
method,
|
|
2066
|
-
methodScope,
|
|
2067
|
-
upperScope
|
|
2068
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2069
|
-
),
|
|
2070
|
-
O.map(() => ({
|
|
2071
|
-
messageId: "noSetStateInComponentDidMount",
|
|
2072
|
-
node
|
|
2073
|
-
}))
|
|
2074
|
-
);
|
|
2075
|
-
}
|
|
2076
2028
|
return {
|
|
2077
|
-
CallExpression
|
|
2029
|
+
CallExpression(node) {
|
|
2030
|
+
if (!isThisSetState(node)) {
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2034
|
+
const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidMount);
|
|
2035
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2036
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2037
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2038
|
+
context.report({
|
|
2039
|
+
messageId: "noSetStateInComponentDidMount",
|
|
2040
|
+
node
|
|
2041
|
+
});
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2078
2044
|
};
|
|
2079
2045
|
},
|
|
2080
2046
|
defaultOptions: []
|
|
@@ -2103,32 +2069,22 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2103
2069
|
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2104
2070
|
return {};
|
|
2105
2071
|
}
|
|
2106
|
-
function getReportDescriptor(node) {
|
|
2107
|
-
if (!isThisSetState(node)) {
|
|
2108
|
-
return O.none();
|
|
2109
|
-
}
|
|
2110
|
-
return F.pipe(
|
|
2111
|
-
O.Do,
|
|
2112
|
-
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
2113
|
-
O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentDidUpdate)),
|
|
2114
|
-
O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
|
|
2115
|
-
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2116
|
-
O.filter(
|
|
2117
|
-
({
|
|
2118
|
-
clazz,
|
|
2119
|
-
method,
|
|
2120
|
-
methodScope,
|
|
2121
|
-
upperScope
|
|
2122
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2123
|
-
),
|
|
2124
|
-
O.map(() => ({
|
|
2125
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
2126
|
-
node
|
|
2127
|
-
}))
|
|
2128
|
-
);
|
|
2129
|
-
}
|
|
2130
2072
|
return {
|
|
2131
|
-
CallExpression
|
|
2073
|
+
CallExpression(node) {
|
|
2074
|
+
if (!isThisSetState(node)) {
|
|
2075
|
+
return;
|
|
2076
|
+
}
|
|
2077
|
+
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2078
|
+
const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentDidUpdate);
|
|
2079
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2080
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2081
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2082
|
+
context.report({
|
|
2083
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
2084
|
+
node
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2132
2088
|
};
|
|
2133
2089
|
},
|
|
2134
2090
|
defaultOptions: []
|
|
@@ -2157,32 +2113,22 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2157
2113
|
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2158
2114
|
return {};
|
|
2159
2115
|
}
|
|
2160
|
-
function getReportDescriptor(node) {
|
|
2161
|
-
if (!isThisSetState(node)) {
|
|
2162
|
-
return O.none();
|
|
2163
|
-
}
|
|
2164
|
-
return F.pipe(
|
|
2165
|
-
O.Do,
|
|
2166
|
-
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
2167
|
-
O.bind("method", ({ clazz }) => AST11.findParentNodeStop(node, clazz, isComponentWillUpdate3)),
|
|
2168
|
-
O.bind("methodScope", ({ method }) => O.some(context.sourceCode.getScope(method))),
|
|
2169
|
-
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2170
|
-
O.filter(
|
|
2171
|
-
({
|
|
2172
|
-
clazz,
|
|
2173
|
-
method,
|
|
2174
|
-
methodScope,
|
|
2175
|
-
upperScope
|
|
2176
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2177
|
-
),
|
|
2178
|
-
O.map(() => ({
|
|
2179
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
2180
|
-
node
|
|
2181
|
-
}))
|
|
2182
|
-
);
|
|
2183
|
-
}
|
|
2184
2116
|
return {
|
|
2185
|
-
CallExpression
|
|
2117
|
+
CallExpression(node) {
|
|
2118
|
+
if (!isThisSetState(node)) {
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2122
|
+
const method = clazz && AST11.findParentNodeStop(node, clazz, isComponentWillUpdate3);
|
|
2123
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2124
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2125
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2126
|
+
context.report({
|
|
2127
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
2128
|
+
node
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2186
2132
|
};
|
|
2187
2133
|
},
|
|
2188
2134
|
defaultOptions: []
|
|
@@ -2192,14 +2138,14 @@ var RULE_FEATURES36 = [
|
|
|
2192
2138
|
"CHK"
|
|
2193
2139
|
];
|
|
2194
2140
|
function containsStringLiteral({ value }) {
|
|
2195
|
-
return value?.type === AST_NODE_TYPES.Literal &&
|
|
2141
|
+
return value?.type === AST_NODE_TYPES.Literal && typeof value.value === "string";
|
|
2196
2142
|
}
|
|
2197
2143
|
function containsStringExpressionContainer({ value }) {
|
|
2198
2144
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2199
2145
|
return false;
|
|
2200
2146
|
}
|
|
2201
2147
|
if (value.expression.type === AST_NODE_TYPES.Literal) {
|
|
2202
|
-
return
|
|
2148
|
+
return typeof value.expression.value === "string";
|
|
2203
2149
|
}
|
|
2204
2150
|
return value.expression.type === AST_NODE_TYPES.TemplateLiteral;
|
|
2205
2151
|
}
|
|
@@ -2400,39 +2346,28 @@ var no_unstable_context_value_default = createRule({
|
|
|
2400
2346
|
if (openingElementName.property.name !== "Provider") {
|
|
2401
2347
|
return;
|
|
2402
2348
|
}
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
node.attributes.find((attribute) => {
|
|
2408
|
-
return attribute.type === AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
|
|
2409
|
-
})
|
|
2410
|
-
)),
|
|
2411
|
-
O.bind("value", ({ attribute }) => "value" in attribute ? O.some(attribute.value) : O.none()),
|
|
2412
|
-
O.bind("valueExpression", ({ value }) => value?.type === AST_NODE_TYPES.JSXExpressionContainer ? O.some(value.expression) : O.none()),
|
|
2413
|
-
O.bind("construction", ({ valueExpression }) => {
|
|
2414
|
-
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2415
|
-
return O.some(VAR.getValueConstruction(valueExpression, initialScope));
|
|
2416
|
-
}),
|
|
2417
|
-
O.map((vc) => {
|
|
2418
|
-
if (vc.construction.kind === "None") {
|
|
2419
|
-
return;
|
|
2420
|
-
}
|
|
2421
|
-
if (isReactHookCall(vc.construction.node)) {
|
|
2422
|
-
return;
|
|
2423
|
-
}
|
|
2424
|
-
const prevs = constructions.get(vc.function.node) ?? [];
|
|
2425
|
-
constructions.set(vc.function.node, [...prevs, vc.construction]);
|
|
2426
|
-
})
|
|
2349
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2350
|
+
if (functionEntry === _) return;
|
|
2351
|
+
const attribute = node.attributes.find(
|
|
2352
|
+
(attribute2) => attribute2.type === AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2427
2353
|
);
|
|
2354
|
+
if (attribute === _ || !("value" in attribute)) return;
|
|
2355
|
+
const value = attribute.value;
|
|
2356
|
+
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2357
|
+
const valueExpression = value.expression;
|
|
2358
|
+
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2359
|
+
const construction = VAR.getValueConstruction(valueExpression, initialScope);
|
|
2360
|
+
if (construction === _) return;
|
|
2361
|
+
if (isReactHookCall(construction.node)) {
|
|
2362
|
+
return;
|
|
2363
|
+
}
|
|
2364
|
+
const prevs = constructions.get(functionEntry.node) ?? [];
|
|
2365
|
+
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2428
2366
|
},
|
|
2429
2367
|
"Program:exit"(node) {
|
|
2430
2368
|
const components = ctx.getAllComponents(node).values();
|
|
2431
2369
|
for (const { node: component } of components) {
|
|
2432
2370
|
for (const construction of constructions.get(component) ?? []) {
|
|
2433
|
-
if (construction.kind === "None") {
|
|
2434
|
-
continue;
|
|
2435
|
-
}
|
|
2436
2371
|
const { kind, node: constructionNode } = construction;
|
|
2437
2372
|
const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
2438
2373
|
context.report({
|
|
@@ -2494,7 +2429,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2494
2429
|
initialScope,
|
|
2495
2430
|
VAR.ValueConstructionHint.StrictCallExpression
|
|
2496
2431
|
);
|
|
2497
|
-
if (construction
|
|
2432
|
+
if (construction === _) {
|
|
2498
2433
|
continue;
|
|
2499
2434
|
}
|
|
2500
2435
|
if (isReactHookCall(construction.node)) {
|
|
@@ -2512,13 +2447,10 @@ var no_unstable_default_props_default = createRule({
|
|
|
2512
2447
|
}
|
|
2513
2448
|
},
|
|
2514
2449
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2515
|
-
const
|
|
2516
|
-
if (
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
const entry = mbEntry.value;
|
|
2520
|
-
const prevs = declarators.get(entry.node) ?? [];
|
|
2521
|
-
declarators.set(entry.node, [...prevs, node]);
|
|
2450
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2451
|
+
if (!functionEntry) return;
|
|
2452
|
+
const prevs = declarators.get(functionEntry.node) ?? [];
|
|
2453
|
+
declarators.set(functionEntry.node, [...prevs, node]);
|
|
2522
2454
|
}
|
|
2523
2455
|
};
|
|
2524
2456
|
},
|
|
@@ -2550,15 +2482,15 @@ function getName3(node) {
|
|
|
2550
2482
|
return getName3(node.expression);
|
|
2551
2483
|
}
|
|
2552
2484
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
2553
|
-
return
|
|
2485
|
+
return node.name;
|
|
2554
2486
|
}
|
|
2555
2487
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
2556
|
-
return
|
|
2488
|
+
return node.value?.toString();
|
|
2557
2489
|
}
|
|
2558
2490
|
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2559
|
-
return
|
|
2491
|
+
return node.quasis[0]?.value.raw;
|
|
2560
2492
|
}
|
|
2561
|
-
return
|
|
2493
|
+
return _;
|
|
2562
2494
|
}
|
|
2563
2495
|
var no_unused_class_component_members_default = createRule({
|
|
2564
2496
|
meta: {
|
|
@@ -2574,12 +2506,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2574
2506
|
},
|
|
2575
2507
|
name: RULE_NAME42,
|
|
2576
2508
|
create(context) {
|
|
2577
|
-
const
|
|
2578
|
-
const
|
|
2509
|
+
const classEntries = [];
|
|
2510
|
+
const methodEntries = [];
|
|
2579
2511
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
2580
2512
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2581
2513
|
function classEnter(node) {
|
|
2582
|
-
|
|
2514
|
+
classEntries.push(node);
|
|
2583
2515
|
if (!isClassComponent(node)) {
|
|
2584
2516
|
return;
|
|
2585
2517
|
}
|
|
@@ -2587,37 +2519,37 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2587
2519
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2588
2520
|
}
|
|
2589
2521
|
function classExit() {
|
|
2590
|
-
const currentClass =
|
|
2522
|
+
const currentClass = classEntries.pop();
|
|
2591
2523
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2592
2524
|
return;
|
|
2593
2525
|
}
|
|
2594
|
-
const className =
|
|
2526
|
+
const className = AST11.getClassIdentifier(currentClass)?.name;
|
|
2595
2527
|
const defs = propertyDefs.get(currentClass);
|
|
2596
2528
|
const usages = propertyUsages.get(currentClass);
|
|
2597
2529
|
if (defs == null) {
|
|
2598
2530
|
return;
|
|
2599
2531
|
}
|
|
2600
2532
|
for (const def of defs) {
|
|
2601
|
-
const
|
|
2602
|
-
if (
|
|
2533
|
+
const methodName = getName3(def);
|
|
2534
|
+
if (methodName == null) {
|
|
2603
2535
|
continue;
|
|
2604
2536
|
}
|
|
2605
|
-
if (usages?.has(
|
|
2537
|
+
if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
|
|
2606
2538
|
continue;
|
|
2607
2539
|
}
|
|
2608
2540
|
context.report({
|
|
2609
2541
|
messageId: "noUnusedClassComponentMembers",
|
|
2610
2542
|
node: def,
|
|
2611
2543
|
data: {
|
|
2612
|
-
className:
|
|
2613
|
-
methodName
|
|
2544
|
+
className: className ?? "Component",
|
|
2545
|
+
methodName
|
|
2614
2546
|
}
|
|
2615
2547
|
});
|
|
2616
2548
|
}
|
|
2617
2549
|
}
|
|
2618
2550
|
function methodEnter(node) {
|
|
2619
|
-
|
|
2620
|
-
const currentClass =
|
|
2551
|
+
methodEntries.push(node);
|
|
2552
|
+
const currentClass = classEntries.at(-1);
|
|
2621
2553
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2622
2554
|
return;
|
|
2623
2555
|
}
|
|
@@ -2629,7 +2561,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2629
2561
|
}
|
|
2630
2562
|
}
|
|
2631
2563
|
function methodExit() {
|
|
2632
|
-
|
|
2564
|
+
methodEntries.pop();
|
|
2633
2565
|
}
|
|
2634
2566
|
return {
|
|
2635
2567
|
ClassDeclaration: classEnter,
|
|
@@ -2637,8 +2569,8 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2637
2569
|
ClassExpression: classEnter,
|
|
2638
2570
|
"ClassExpression:exit": classExit,
|
|
2639
2571
|
MemberExpression(node) {
|
|
2640
|
-
const currentClass =
|
|
2641
|
-
const currentMethod =
|
|
2572
|
+
const currentClass = classEntries.at(-1);
|
|
2573
|
+
const currentMethod = methodEntries.at(-1);
|
|
2642
2574
|
if (currentClass == null || currentMethod == null) {
|
|
2643
2575
|
return;
|
|
2644
2576
|
}
|
|
@@ -2652,15 +2584,18 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2652
2584
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2653
2585
|
return;
|
|
2654
2586
|
}
|
|
2655
|
-
|
|
2587
|
+
const propertyName = getName3(node.property);
|
|
2588
|
+
if (propertyName != null) {
|
|
2589
|
+
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2590
|
+
}
|
|
2656
2591
|
},
|
|
2657
2592
|
MethodDefinition: methodEnter,
|
|
2658
2593
|
"MethodDefinition:exit": methodExit,
|
|
2659
2594
|
PropertyDefinition: methodEnter,
|
|
2660
2595
|
"PropertyDefinition:exit": methodExit,
|
|
2661
2596
|
VariableDeclarator(node) {
|
|
2662
|
-
const currentClass =
|
|
2663
|
-
const currentMethod =
|
|
2597
|
+
const currentClass = classEntries.at(-1);
|
|
2598
|
+
const currentMethod = methodEntries.at(-1);
|
|
2664
2599
|
if (currentClass == null || currentMethod == null) {
|
|
2665
2600
|
return;
|
|
2666
2601
|
}
|
|
@@ -2670,10 +2605,9 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2670
2605
|
if (node.init != null && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2671
2606
|
for (const prop of node.id.properties) {
|
|
2672
2607
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
2673
|
-
const
|
|
2674
|
-
if (
|
|
2675
|
-
|
|
2676
|
-
propertyUsages.get(currentClass)?.add(name2);
|
|
2608
|
+
const keyName = getName3(prop.key);
|
|
2609
|
+
if (keyName != null) {
|
|
2610
|
+
propertyUsages.get(currentClass)?.add(keyName);
|
|
2677
2611
|
}
|
|
2678
2612
|
}
|
|
2679
2613
|
}
|
|
@@ -2692,19 +2626,19 @@ function getName4(node) {
|
|
|
2692
2626
|
return getName4(node.expression);
|
|
2693
2627
|
}
|
|
2694
2628
|
if (node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.PrivateIdentifier) {
|
|
2695
|
-
return
|
|
2629
|
+
return node.name;
|
|
2696
2630
|
}
|
|
2697
2631
|
if (node.type === AST_NODE_TYPES.Literal) {
|
|
2698
|
-
return
|
|
2632
|
+
return String(node.value);
|
|
2699
2633
|
}
|
|
2700
2634
|
if (node.type === AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2701
|
-
return
|
|
2635
|
+
return node.quasis[0]?.value.raw;
|
|
2702
2636
|
}
|
|
2703
|
-
return
|
|
2637
|
+
return _;
|
|
2704
2638
|
}
|
|
2705
2639
|
function isAssignmentToThisState2(node) {
|
|
2706
2640
|
const { left } = node;
|
|
2707
|
-
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) &&
|
|
2641
|
+
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2708
2642
|
}
|
|
2709
2643
|
var isGetDerivedStateFromProps = isMatching({
|
|
2710
2644
|
key: {
|
|
@@ -2729,72 +2663,72 @@ var no_unused_state_default = createRule({
|
|
|
2729
2663
|
},
|
|
2730
2664
|
name: RULE_NAME43,
|
|
2731
2665
|
create(context) {
|
|
2732
|
-
const
|
|
2733
|
-
const
|
|
2734
|
-
const
|
|
2666
|
+
const classEntries = [];
|
|
2667
|
+
const methodEntries = [];
|
|
2668
|
+
const constructorEntries = [];
|
|
2735
2669
|
const stateDefs = /* @__PURE__ */ new WeakMap();
|
|
2736
2670
|
function classEnter(node) {
|
|
2737
|
-
|
|
2671
|
+
classEntries.push(node);
|
|
2738
2672
|
}
|
|
2739
2673
|
function classExit() {
|
|
2740
|
-
const currentClass =
|
|
2674
|
+
const currentClass = classEntries.pop();
|
|
2741
2675
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2742
2676
|
return;
|
|
2743
2677
|
}
|
|
2744
|
-
const className =
|
|
2745
|
-
const
|
|
2746
|
-
if (
|
|
2678
|
+
const className = AST11.getClassIdentifier(currentClass)?.name;
|
|
2679
|
+
const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
|
|
2680
|
+
if (!defNode || isUsed) {
|
|
2747
2681
|
return;
|
|
2748
2682
|
}
|
|
2749
2683
|
context.report({
|
|
2750
2684
|
messageId: "noUnusedState",
|
|
2751
|
-
node:
|
|
2685
|
+
node: defNode,
|
|
2752
2686
|
data: {
|
|
2753
|
-
className:
|
|
2687
|
+
className: className ?? "Component"
|
|
2754
2688
|
}
|
|
2755
2689
|
});
|
|
2756
2690
|
}
|
|
2757
2691
|
function methodEnter(node) {
|
|
2758
|
-
|
|
2759
|
-
const currentClass =
|
|
2692
|
+
methodEntries.push(node);
|
|
2693
|
+
const currentClass = classEntries.at(-1);
|
|
2760
2694
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2761
2695
|
return;
|
|
2762
2696
|
}
|
|
2763
2697
|
if (node.static) {
|
|
2764
2698
|
if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
|
|
2765
|
-
const
|
|
2766
|
-
stateDefs.set(currentClass,
|
|
2699
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2700
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2767
2701
|
}
|
|
2768
2702
|
return;
|
|
2769
2703
|
}
|
|
2770
|
-
if (
|
|
2771
|
-
stateDefs.set(currentClass,
|
|
2704
|
+
if (getName4(node.key) === "state") {
|
|
2705
|
+
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2772
2706
|
}
|
|
2773
2707
|
}
|
|
2774
2708
|
function methodExit() {
|
|
2775
|
-
|
|
2709
|
+
methodEntries.pop();
|
|
2776
2710
|
}
|
|
2777
2711
|
function constructorEnter(node) {
|
|
2778
|
-
|
|
2712
|
+
constructorEntries.push(node);
|
|
2779
2713
|
}
|
|
2780
2714
|
function constructorExit() {
|
|
2781
|
-
|
|
2715
|
+
constructorEntries.pop();
|
|
2782
2716
|
}
|
|
2783
2717
|
return {
|
|
2784
2718
|
AssignmentExpression(node) {
|
|
2785
2719
|
if (!isAssignmentToThisState2(node)) {
|
|
2786
2720
|
return;
|
|
2787
2721
|
}
|
|
2788
|
-
const currentClass =
|
|
2722
|
+
const currentClass = classEntries.at(-1);
|
|
2789
2723
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2790
2724
|
return;
|
|
2791
2725
|
}
|
|
2792
|
-
const currentConstructor =
|
|
2726
|
+
const currentConstructor = constructorEntries.at(-1);
|
|
2793
2727
|
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2794
2728
|
return;
|
|
2795
2729
|
}
|
|
2796
|
-
const
|
|
2797
|
-
stateDefs.set(currentClass,
|
|
2730
|
+
const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
|
|
2731
|
+
stateDefs.set(currentClass, { node: node.left, isUsed });
|
|
2798
2732
|
},
|
|
2799
2733
|
ClassDeclaration: classEnter,
|
|
2800
2734
|
"ClassDeclaration:exit": classExit,
|
|
@@ -2804,25 +2738,25 @@ var no_unused_state_default = createRule({
|
|
|
2804
2738
|
if (!AST11.isThisExpression(node.object)) {
|
|
2805
2739
|
return;
|
|
2806
2740
|
}
|
|
2807
|
-
if (
|
|
2741
|
+
if (getName4(node.property) !== "state") {
|
|
2808
2742
|
return;
|
|
2809
2743
|
}
|
|
2810
|
-
const currentClass =
|
|
2744
|
+
const currentClass = classEntries.at(-1);
|
|
2811
2745
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2812
2746
|
return;
|
|
2813
2747
|
}
|
|
2814
|
-
const currentMethod =
|
|
2748
|
+
const currentMethod = methodEntries.at(-1);
|
|
2815
2749
|
if (currentMethod == null || currentMethod.static) {
|
|
2816
2750
|
return;
|
|
2817
2751
|
}
|
|
2818
|
-
if (currentMethod ===
|
|
2752
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2819
2753
|
return;
|
|
2820
2754
|
}
|
|
2821
2755
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2822
2756
|
return;
|
|
2823
2757
|
}
|
|
2824
|
-
const
|
|
2825
|
-
stateDefs.set(currentClass,
|
|
2758
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2759
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2826
2760
|
},
|
|
2827
2761
|
MethodDefinition: methodEnter,
|
|
2828
2762
|
"MethodDefinition:exit": methodExit,
|
|
@@ -2831,15 +2765,15 @@ var no_unused_state_default = createRule({
|
|
|
2831
2765
|
PropertyDefinition: methodEnter,
|
|
2832
2766
|
"PropertyDefinition:exit": methodExit,
|
|
2833
2767
|
VariableDeclarator(node) {
|
|
2834
|
-
const currentClass =
|
|
2768
|
+
const currentClass = classEntries.at(-1);
|
|
2835
2769
|
if (currentClass == null || !isClassComponent(currentClass)) {
|
|
2836
2770
|
return;
|
|
2837
2771
|
}
|
|
2838
|
-
const currentMethod =
|
|
2772
|
+
const currentMethod = methodEntries.at(-1);
|
|
2839
2773
|
if (currentMethod == null || currentMethod.static) {
|
|
2840
2774
|
return;
|
|
2841
2775
|
}
|
|
2842
|
-
if (currentMethod ===
|
|
2776
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2843
2777
|
return;
|
|
2844
2778
|
}
|
|
2845
2779
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
@@ -2850,15 +2784,15 @@ var no_unused_state_default = createRule({
|
|
|
2850
2784
|
}
|
|
2851
2785
|
const hasState = node.id.properties.some((prop) => {
|
|
2852
2786
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
2853
|
-
return
|
|
2787
|
+
return getName4(prop.key) === "state";
|
|
2854
2788
|
}
|
|
2855
2789
|
return false;
|
|
2856
2790
|
});
|
|
2857
2791
|
if (!hasState) {
|
|
2858
2792
|
return;
|
|
2859
2793
|
}
|
|
2860
|
-
const
|
|
2861
|
-
stateDefs.set(currentClass,
|
|
2794
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2795
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2862
2796
|
}
|
|
2863
2797
|
};
|
|
2864
2798
|
},
|
|
@@ -2985,10 +2919,8 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2985
2919
|
if (!AST11.isFunction(block)) {
|
|
2986
2920
|
return false;
|
|
2987
2921
|
}
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
(id) => isComponentName(id.name) && components.some((component) => component.node === block)
|
|
2991
|
-
);
|
|
2922
|
+
const id = AST11.getFunctionIdentifier(block);
|
|
2923
|
+
return !!id && isComponentName(id.name) && components.some((component) => component.node === block);
|
|
2992
2924
|
}
|
|
2993
2925
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
2994
2926
|
let scope = initialScope;
|
|
@@ -3117,7 +3049,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3117
3049
|
...listeners,
|
|
3118
3050
|
"Program:exit"(node) {
|
|
3119
3051
|
const components = ctx.getAllComponents(node);
|
|
3120
|
-
for (const [
|
|
3052
|
+
for (const [, component] of components) {
|
|
3121
3053
|
const [props] = component.node.params;
|
|
3122
3054
|
if (props == null) {
|
|
3123
3055
|
continue;
|
|
@@ -3153,24 +3085,23 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3153
3085
|
},
|
|
3154
3086
|
name: RULE_NAME48,
|
|
3155
3087
|
create(context) {
|
|
3156
|
-
function getReportDescriptor(node) {
|
|
3157
|
-
const { value } = node;
|
|
3158
|
-
const propName = JSX7.getPropName(node);
|
|
3159
|
-
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3160
|
-
if (!hasValueTrue) {
|
|
3161
|
-
return O.none();
|
|
3162
|
-
}
|
|
3163
|
-
return O.some({
|
|
3164
|
-
messageId: "preferShorthandBoolean",
|
|
3165
|
-
node,
|
|
3166
|
-
data: {
|
|
3167
|
-
propName
|
|
3168
|
-
},
|
|
3169
|
-
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3170
|
-
});
|
|
3171
|
-
}
|
|
3172
3088
|
return {
|
|
3173
|
-
JSXAttribute
|
|
3089
|
+
JSXAttribute(node) {
|
|
3090
|
+
const { value } = node;
|
|
3091
|
+
const propName = JSX7.getPropName(node);
|
|
3092
|
+
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3093
|
+
if (!hasValueTrue) {
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3096
|
+
context.report({
|
|
3097
|
+
messageId: "preferShorthandBoolean",
|
|
3098
|
+
node,
|
|
3099
|
+
data: {
|
|
3100
|
+
propName
|
|
3101
|
+
},
|
|
3102
|
+
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3103
|
+
});
|
|
3104
|
+
}
|
|
3174
3105
|
};
|
|
3175
3106
|
},
|
|
3176
3107
|
defaultOptions: []
|
|
@@ -3195,31 +3126,32 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3195
3126
|
},
|
|
3196
3127
|
name: RULE_NAME49,
|
|
3197
3128
|
create(context) {
|
|
3198
|
-
function getReportDescriptor(node) {
|
|
3199
|
-
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3200
|
-
return O.none();
|
|
3201
|
-
}
|
|
3202
|
-
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3203
|
-
if (hasAttributes) {
|
|
3204
|
-
return O.none();
|
|
3205
|
-
}
|
|
3206
|
-
return O.some({
|
|
3207
|
-
messageId: "preferShorthandFragment",
|
|
3208
|
-
node,
|
|
3209
|
-
fix: (fixer) => {
|
|
3210
|
-
const { closingElement, openingElement } = node;
|
|
3211
|
-
if (closingElement == null) {
|
|
3212
|
-
return [];
|
|
3213
|
-
}
|
|
3214
|
-
return [
|
|
3215
|
-
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3216
|
-
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3217
|
-
];
|
|
3218
|
-
}
|
|
3219
|
-
});
|
|
3220
|
-
}
|
|
3221
3129
|
return {
|
|
3222
|
-
JSXElement
|
|
3130
|
+
JSXElement(node) {
|
|
3131
|
+
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3132
|
+
return;
|
|
3133
|
+
}
|
|
3134
|
+
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3135
|
+
if (hasAttributes) {
|
|
3136
|
+
return;
|
|
3137
|
+
}
|
|
3138
|
+
context.report({
|
|
3139
|
+
messageId: "preferShorthandFragment",
|
|
3140
|
+
node,
|
|
3141
|
+
fix: (fixer) => {
|
|
3142
|
+
const { closingElement, openingElement } = node;
|
|
3143
|
+
if (closingElement == null) {
|
|
3144
|
+
return [];
|
|
3145
|
+
}
|
|
3146
|
+
return [
|
|
3147
|
+
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3148
|
+
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3149
|
+
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3150
|
+
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3151
|
+
];
|
|
3152
|
+
}
|
|
3153
|
+
});
|
|
3154
|
+
}
|
|
3223
3155
|
};
|
|
3224
3156
|
},
|
|
3225
3157
|
defaultOptions: []
|
|
@@ -3241,23 +3173,23 @@ var use_jsx_vars_default = createRule({
|
|
|
3241
3173
|
},
|
|
3242
3174
|
name: RULE_NAME50,
|
|
3243
3175
|
create(context) {
|
|
3244
|
-
function getName5(node) {
|
|
3245
|
-
switch (node.type) {
|
|
3246
|
-
case AST_NODE_TYPES.JSXIdentifier:
|
|
3247
|
-
return O.some(node.name);
|
|
3248
|
-
case AST_NODE_TYPES.JSXMemberExpression:
|
|
3249
|
-
return getName5(node.object);
|
|
3250
|
-
default:
|
|
3251
|
-
return O.none();
|
|
3252
|
-
}
|
|
3253
|
-
}
|
|
3254
3176
|
return {
|
|
3255
3177
|
JSXOpeningElement(node) {
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3178
|
+
switch (node.name.type) {
|
|
3179
|
+
case AST_NODE_TYPES.JSXIdentifier: {
|
|
3180
|
+
if (/^[a-z]/u.test(node.name.name)) {
|
|
3181
|
+
return;
|
|
3182
|
+
}
|
|
3183
|
+
context.sourceCode.markVariableAsUsed(node.name.name, node);
|
|
3184
|
+
break;
|
|
3185
|
+
}
|
|
3186
|
+
case AST_NODE_TYPES.JSXMemberExpression: {
|
|
3187
|
+
const { object } = node.name;
|
|
3188
|
+
if (object.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
3189
|
+
context.sourceCode.markVariableAsUsed(object.name, node);
|
|
3190
|
+
}
|
|
3191
|
+
break;
|
|
3192
|
+
}
|
|
3261
3193
|
}
|
|
3262
3194
|
}
|
|
3263
3195
|
};
|