eslint-plugin-react-x 1.23.3-next.7 → 1.24.0-next.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 +419 -481
- package/dist/index.mjs +419 -481
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var eff = require('@eslint-react/eff');
|
|
4
3
|
var JSX7 = require('@eslint-react/jsx');
|
|
5
4
|
var shared = require('@eslint-react/shared');
|
|
6
5
|
var AST11 = require('@eslint-react/ast');
|
|
7
6
|
var core = require('@eslint-react/core');
|
|
7
|
+
var eff = require('@eslint-react/eff');
|
|
8
8
|
var types = require('@typescript-eslint/types');
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
10
|
var compareVersions = require('compare-versions');
|
|
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.
|
|
45
|
+
var version = "1.24.0-next.0";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -65,18 +65,19 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
65
65
|
},
|
|
66
66
|
name: RULE_NAME,
|
|
67
67
|
create(context) {
|
|
68
|
-
function getReportDescriptor(node) {
|
|
69
|
-
return node.value != null ? eff.O.none() : eff.O.some({
|
|
70
|
-
messageId: "avoidShorthandBoolean",
|
|
71
|
-
node,
|
|
72
|
-
data: {
|
|
73
|
-
propName: JSX7__namespace.getPropName(node)
|
|
74
|
-
},
|
|
75
|
-
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
68
|
return {
|
|
79
|
-
JSXAttribute
|
|
69
|
+
JSXAttribute(node) {
|
|
70
|
+
if (node.value === null) {
|
|
71
|
+
context.report({
|
|
72
|
+
messageId: "avoidShorthandBoolean",
|
|
73
|
+
node,
|
|
74
|
+
data: {
|
|
75
|
+
propName: JSX7__namespace.getPropName(node)
|
|
76
|
+
},
|
|
77
|
+
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
80
81
|
};
|
|
81
82
|
},
|
|
82
83
|
defaultOptions: []
|
|
@@ -139,7 +140,7 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
139
140
|
if (component == null || !AST11__namespace.isFunction(component)) {
|
|
140
141
|
return;
|
|
141
142
|
}
|
|
142
|
-
const
|
|
143
|
+
const ref = component.params[1];
|
|
143
144
|
if (ref != null) {
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
@@ -161,15 +162,15 @@ function getName(node) {
|
|
|
161
162
|
return getName(node.expression);
|
|
162
163
|
}
|
|
163
164
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
164
|
-
return
|
|
165
|
+
return node.name;
|
|
165
166
|
}
|
|
166
167
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
167
|
-
return
|
|
168
|
+
return String(node.value);
|
|
168
169
|
}
|
|
169
170
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
170
|
-
return
|
|
171
|
+
return node.quasis[0]?.value.raw;
|
|
171
172
|
}
|
|
172
|
-
return eff.
|
|
173
|
+
return eff._;
|
|
173
174
|
}
|
|
174
175
|
var no_access_state_in_setstate_default = createRule({
|
|
175
176
|
meta: {
|
|
@@ -188,89 +189,86 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
188
189
|
if (!context.sourceCode.text.includes("setState")) {
|
|
189
190
|
return {};
|
|
190
191
|
}
|
|
191
|
-
const
|
|
192
|
-
const
|
|
193
|
-
const
|
|
192
|
+
const classEntries = [];
|
|
193
|
+
const methodEntries = [];
|
|
194
|
+
const setStateEntries = [];
|
|
194
195
|
return {
|
|
195
196
|
CallExpression(node) {
|
|
196
197
|
if (!core.isThisSetState(node)) {
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
199
|
-
|
|
200
|
+
setStateEntries.push([node, false]);
|
|
200
201
|
},
|
|
201
202
|
"CallExpression:exit"(node) {
|
|
202
203
|
if (!core.isThisSetState(node)) {
|
|
203
204
|
return;
|
|
204
205
|
}
|
|
205
|
-
|
|
206
|
+
setStateEntries.pop();
|
|
206
207
|
},
|
|
207
208
|
ClassDeclaration(node) {
|
|
208
|
-
|
|
209
|
+
classEntries.push([node, core.isClassComponent(node)]);
|
|
209
210
|
},
|
|
210
211
|
"ClassDeclaration:exit"() {
|
|
211
|
-
|
|
212
|
+
classEntries.pop();
|
|
212
213
|
},
|
|
213
214
|
ClassExpression(node) {
|
|
214
|
-
|
|
215
|
+
classEntries.push([node, core.isClassComponent(node)]);
|
|
215
216
|
},
|
|
216
217
|
"ClassExpression:exit"() {
|
|
217
|
-
|
|
218
|
+
classEntries.pop();
|
|
218
219
|
},
|
|
219
220
|
MemberExpression(node) {
|
|
220
221
|
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
221
222
|
return;
|
|
222
223
|
}
|
|
223
|
-
const [currClass, isComponent] =
|
|
224
|
+
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
224
225
|
if (currClass == null || !isComponent) {
|
|
225
226
|
return;
|
|
226
227
|
}
|
|
227
|
-
const [currMethod, isStatic] =
|
|
228
|
+
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
228
229
|
if (currMethod == null || isStatic) {
|
|
229
230
|
return;
|
|
230
231
|
}
|
|
231
|
-
const [setState, hasThisState] =
|
|
232
|
+
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
232
233
|
if (setState == null || hasThisState) {
|
|
233
234
|
return;
|
|
234
235
|
}
|
|
235
|
-
if (
|
|
236
|
+
if (getName(node.property) !== "state") {
|
|
236
237
|
return;
|
|
237
238
|
}
|
|
238
239
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
239
240
|
},
|
|
240
241
|
MethodDefinition(node) {
|
|
241
|
-
|
|
242
|
+
methodEntries.push([node, node.static]);
|
|
242
243
|
},
|
|
243
244
|
"MethodDefinition:exit"() {
|
|
244
|
-
|
|
245
|
+
methodEntries.pop();
|
|
245
246
|
},
|
|
246
247
|
PropertyDefinition(node) {
|
|
247
|
-
|
|
248
|
+
methodEntries.push([node, node.static]);
|
|
248
249
|
},
|
|
249
250
|
"PropertyDefinition:exit"() {
|
|
250
|
-
|
|
251
|
+
methodEntries.pop();
|
|
251
252
|
},
|
|
252
253
|
VariableDeclarator(node) {
|
|
253
|
-
const [currClass, isComponent] =
|
|
254
|
+
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
254
255
|
if (currClass == null || !isComponent) {
|
|
255
256
|
return;
|
|
256
257
|
}
|
|
257
|
-
const [currMethod, isStatic] =
|
|
258
|
+
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
258
259
|
if (currMethod == null || isStatic) {
|
|
259
260
|
return;
|
|
260
261
|
}
|
|
261
|
-
const [setState, hasThisState] =
|
|
262
|
+
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
262
263
|
if (setState == null || hasThisState) {
|
|
263
264
|
return;
|
|
264
265
|
}
|
|
265
266
|
if (!(node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern)) {
|
|
266
267
|
return;
|
|
267
268
|
}
|
|
268
|
-
const hasState = node.id.properties.some(
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
return false;
|
|
273
|
-
});
|
|
269
|
+
const hasState = node.id.properties.some(
|
|
270
|
+
(prop) => prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key) && getName(prop.key) === "state"
|
|
271
|
+
);
|
|
274
272
|
if (!hasState) {
|
|
275
273
|
return;
|
|
276
274
|
}
|
|
@@ -323,32 +321,32 @@ function isUsingReactChildren(node, context) {
|
|
|
323
321
|
function getMapIndexParamName(node, context) {
|
|
324
322
|
const { callee } = node;
|
|
325
323
|
if (callee.type !== types.AST_NODE_TYPES.MemberExpression) {
|
|
326
|
-
return eff.
|
|
324
|
+
return eff._;
|
|
327
325
|
}
|
|
328
326
|
if (callee.property.type !== types.AST_NODE_TYPES.Identifier) {
|
|
329
|
-
return eff.
|
|
327
|
+
return eff._;
|
|
330
328
|
}
|
|
331
329
|
const { name: name2 } = callee.property;
|
|
332
330
|
if (!iteratorFunctionIndexParamPosition.has(name2)) {
|
|
333
|
-
return eff.
|
|
331
|
+
return eff._;
|
|
334
332
|
}
|
|
335
333
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
336
334
|
if (callbackArg == null) {
|
|
337
|
-
return eff.
|
|
335
|
+
return eff._;
|
|
338
336
|
}
|
|
339
337
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.ArrowFunctionExpression, types.AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
340
|
-
return eff.
|
|
338
|
+
return eff._;
|
|
341
339
|
}
|
|
342
340
|
const { params } = callbackArg;
|
|
343
341
|
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
|
|
344
|
-
if (
|
|
345
|
-
return eff.
|
|
342
|
+
if (indexParamPosition == null) {
|
|
343
|
+
return eff._;
|
|
346
344
|
}
|
|
347
345
|
if (params.length < indexParamPosition + 1) {
|
|
348
|
-
return eff.
|
|
346
|
+
return eff._;
|
|
349
347
|
}
|
|
350
348
|
const param = params.at(indexParamPosition);
|
|
351
|
-
return param != null && "name" in param ?
|
|
349
|
+
return param != null && "name" in param ? param.name : eff._;
|
|
352
350
|
}
|
|
353
351
|
var no_array_index_key_default = createRule({
|
|
354
352
|
meta: {
|
|
@@ -366,7 +364,7 @@ var no_array_index_key_default = createRule({
|
|
|
366
364
|
create(context) {
|
|
367
365
|
const indexParamNames = [];
|
|
368
366
|
function isArrayIndex(node) {
|
|
369
|
-
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(
|
|
367
|
+
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some((name2) => name2 != null && name2 === node.name);
|
|
370
368
|
}
|
|
371
369
|
function isCreateOrCloneElementCall(node) {
|
|
372
370
|
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
@@ -375,7 +373,7 @@ var no_array_index_key_default = createRule({
|
|
|
375
373
|
switch (node.type) {
|
|
376
374
|
// key={bar}
|
|
377
375
|
case types.AST_NODE_TYPES.Identifier: {
|
|
378
|
-
if (indexParamNames.some(
|
|
376
|
+
if (indexParamNames.some((name2) => name2 != null && name2 === node.name)) {
|
|
379
377
|
return [{
|
|
380
378
|
messageId: "noArrayIndexKey",
|
|
381
379
|
node
|
|
@@ -429,7 +427,7 @@ var no_array_index_key_default = createRule({
|
|
|
429
427
|
if (!isCreateOrCloneElementCall(node)) {
|
|
430
428
|
return;
|
|
431
429
|
}
|
|
432
|
-
const [
|
|
430
|
+
const [, props] = node.arguments;
|
|
433
431
|
if (props?.type !== types.AST_NODE_TYPES.ObjectExpression) {
|
|
434
432
|
return;
|
|
435
433
|
}
|
|
@@ -612,10 +610,17 @@ var no_children_prop_default = createRule({
|
|
|
612
610
|
create(context) {
|
|
613
611
|
return {
|
|
614
612
|
JSXElement(node) {
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
613
|
+
const prop = JSX7__namespace.getProp(
|
|
614
|
+
"children",
|
|
615
|
+
context.sourceCode.getScope(node),
|
|
616
|
+
node.openingElement.attributes
|
|
617
|
+
);
|
|
618
|
+
if (prop) {
|
|
619
|
+
context.report({
|
|
620
|
+
messageId: "noChildrenProp",
|
|
621
|
+
node: prop
|
|
622
|
+
});
|
|
623
|
+
}
|
|
619
624
|
}
|
|
620
625
|
};
|
|
621
626
|
},
|
|
@@ -684,7 +689,7 @@ var no_class_component_default = createRule({
|
|
|
684
689
|
...listeners,
|
|
685
690
|
"Program:exit"(node) {
|
|
686
691
|
const components = ctx.getAllComponents(node);
|
|
687
|
-
for (const { name: name2, node: component } of components.values()) {
|
|
692
|
+
for (const { name: name2 = "anonymous", node: component } of components.values()) {
|
|
688
693
|
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
689
694
|
continue;
|
|
690
695
|
}
|
|
@@ -693,7 +698,7 @@ var no_class_component_default = createRule({
|
|
|
693
698
|
node: component,
|
|
694
699
|
data: {
|
|
695
700
|
// eslint-disable-next-line eslint-plugin/no-unused-placeholders
|
|
696
|
-
name:
|
|
701
|
+
name: name2
|
|
697
702
|
}
|
|
698
703
|
});
|
|
699
704
|
}
|
|
@@ -759,22 +764,21 @@ var no_comment_textnodes_default = createRule({
|
|
|
759
764
|
const rawValue = context.sourceCode.getText(node);
|
|
760
765
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
761
766
|
}
|
|
762
|
-
const
|
|
767
|
+
const visitorFunction = (node) => {
|
|
763
768
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
764
|
-
return
|
|
769
|
+
return;
|
|
765
770
|
}
|
|
766
771
|
if (!hasCommentLike(node)) {
|
|
767
|
-
return
|
|
772
|
+
return;
|
|
768
773
|
}
|
|
769
774
|
if (!node.parent.type.includes("JSX")) {
|
|
770
|
-
return
|
|
775
|
+
return;
|
|
771
776
|
}
|
|
772
|
-
|
|
777
|
+
context.report({
|
|
773
778
|
messageId: "noCommentTextnodes",
|
|
774
779
|
node
|
|
775
780
|
});
|
|
776
781
|
};
|
|
777
|
-
const visitorFunction = eff.F.flow(getReportDescriptor, eff.O.map(context.report), eff.F.constVoid);
|
|
778
782
|
return {
|
|
779
783
|
JSXText: visitorFunction,
|
|
780
784
|
Literal: visitorFunction
|
|
@@ -800,20 +804,22 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
800
804
|
},
|
|
801
805
|
name: RULE_NAME15,
|
|
802
806
|
create(context) {
|
|
803
|
-
|
|
807
|
+
const visitorFunction = (node) => {
|
|
804
808
|
const jsxExpContainer = node.parent?.parent;
|
|
805
809
|
if (!AST11__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
806
|
-
return
|
|
810
|
+
return;
|
|
807
811
|
}
|
|
808
812
|
if (!AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
809
|
-
return
|
|
813
|
+
return;
|
|
810
814
|
}
|
|
811
815
|
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
812
|
-
return
|
|
816
|
+
return;
|
|
813
817
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
818
|
+
context.report({
|
|
819
|
+
messageId: "noComplexConditionalRendering",
|
|
820
|
+
node: jsxExpContainer
|
|
821
|
+
});
|
|
822
|
+
};
|
|
817
823
|
return {
|
|
818
824
|
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
819
825
|
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
@@ -1057,13 +1063,9 @@ var no_create_ref_default = createRule({
|
|
|
1057
1063
|
create(context) {
|
|
1058
1064
|
return {
|
|
1059
1065
|
CallExpression(node) {
|
|
1060
|
-
if (
|
|
1061
|
-
|
|
1062
|
-
}
|
|
1063
|
-
if (eff.O.isSome(AST11__namespace.findParentNode(node, core.isClassComponent))) {
|
|
1064
|
-
return;
|
|
1066
|
+
if (core.isCreateRefCall(node, context) && !AST11__namespace.findParentNode(node, core.isClassComponent)) {
|
|
1067
|
+
context.report({ messageId: "noCreateRef", node });
|
|
1065
1068
|
}
|
|
1066
|
-
context.report({ messageId: "noCreateRef", node });
|
|
1067
1069
|
}
|
|
1068
1070
|
};
|
|
1069
1071
|
},
|
|
@@ -1105,14 +1107,10 @@ var no_default_props_default = createRule({
|
|
|
1105
1107
|
if (!core.isComponentName(object.name)) {
|
|
1106
1108
|
return;
|
|
1107
1109
|
}
|
|
1108
|
-
const
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
);
|
|
1113
|
-
if (!isComponent) {
|
|
1114
|
-
return;
|
|
1115
|
-
}
|
|
1110
|
+
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1111
|
+
const variableNode = VAR__namespace.getVariableNode(variable, 0);
|
|
1112
|
+
if (variableNode === eff._) return;
|
|
1113
|
+
if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
|
|
1116
1114
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1117
1115
|
},
|
|
1118
1116
|
PropertyDefinition(node) {
|
|
@@ -1137,19 +1135,19 @@ function getName2(node) {
|
|
|
1137
1135
|
return getName2(node.expression);
|
|
1138
1136
|
}
|
|
1139
1137
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
1140
|
-
return
|
|
1138
|
+
return node.name;
|
|
1141
1139
|
}
|
|
1142
1140
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
1143
|
-
return
|
|
1141
|
+
return node.value?.toString();
|
|
1144
1142
|
}
|
|
1145
1143
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
1146
|
-
return
|
|
1144
|
+
return node.quasis[0]?.value.raw;
|
|
1147
1145
|
}
|
|
1148
|
-
return eff.
|
|
1146
|
+
return eff._;
|
|
1149
1147
|
}
|
|
1150
1148
|
function isAssignmentToThisState(node) {
|
|
1151
1149
|
const { left } = node;
|
|
1152
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) &&
|
|
1150
|
+
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName2(left.property) === "state";
|
|
1153
1151
|
}
|
|
1154
1152
|
function isConstructorFunction(node) {
|
|
1155
1153
|
return AST11__namespace.isOneOf([types.AST_NODE_TYPES.FunctionDeclaration, types.AST_NODE_TYPES.FunctionExpression])(node) && AST11__namespace.isOneOf([types.AST_NODE_TYPES.MethodDefinition, types.AST_NODE_TYPES.PropertyDefinition])(node.parent) && node.parent.key.type === types.AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
@@ -1168,31 +1166,26 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1168
1166
|
},
|
|
1169
1167
|
name: RULE_NAME22,
|
|
1170
1168
|
create(context) {
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
eff.O.bind("parentClass", () => AST11__namespace.findParentNodeGuard(
|
|
1169
|
+
return {
|
|
1170
|
+
AssignmentExpression(node) {
|
|
1171
|
+
if (!isAssignmentToThisState(node)) {
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
const parentClass = AST11__namespace.findParentNodeGuard(
|
|
1178
1175
|
node,
|
|
1179
1176
|
AST11__namespace.isOneOf([
|
|
1180
1177
|
types.AST_NODE_TYPES.ClassDeclaration,
|
|
1181
1178
|
types.AST_NODE_TYPES.ClassExpression
|
|
1182
1179
|
])
|
|
1183
|
-
)
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
);
|
|
1193
|
-
}
|
|
1194
|
-
return {
|
|
1195
|
-
AssignmentExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
1180
|
+
);
|
|
1181
|
+
if (!parentClass) return;
|
|
1182
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNodeGuard(node, isConstructorFunction)) {
|
|
1183
|
+
context.report({
|
|
1184
|
+
messageId: "noDirectMutationState",
|
|
1185
|
+
node
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1196
1189
|
};
|
|
1197
1190
|
},
|
|
1198
1191
|
defaultOptions: []
|
|
@@ -1223,7 +1216,7 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1223
1216
|
continue;
|
|
1224
1217
|
}
|
|
1225
1218
|
const name2 = attr.name.name;
|
|
1226
|
-
if (
|
|
1219
|
+
if (typeof name2 !== "string") {
|
|
1227
1220
|
continue;
|
|
1228
1221
|
}
|
|
1229
1222
|
if (!props.includes(name2)) {
|
|
@@ -1287,16 +1280,10 @@ var no_duplicate_key_default = createRule({
|
|
|
1287
1280
|
break;
|
|
1288
1281
|
}
|
|
1289
1282
|
default: {
|
|
1290
|
-
const
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
eff.O.bind("arg0", ({ call: call2 }) => eff.O.fromNullable(call2.arguments[0]))
|
|
1295
|
-
);
|
|
1296
|
-
if (eff.O.isNone(mbEntry)) {
|
|
1297
|
-
return;
|
|
1298
|
-
}
|
|
1299
|
-
const { arg0, call, iter } = mbEntry.value;
|
|
1283
|
+
const call = AST11__namespace.findParentNodeGuard(jsxElement, AST11__namespace.isMapCallLoose);
|
|
1284
|
+
const iter = call && AST11__namespace.findParentNodeStop(jsxElement, call, AST11__namespace.isFunction);
|
|
1285
|
+
const arg0 = call?.arguments[0];
|
|
1286
|
+
if (!call || !iter || !arg0) return;
|
|
1300
1287
|
if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) {
|
|
1301
1288
|
return;
|
|
1302
1289
|
}
|
|
@@ -1397,21 +1384,19 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1397
1384
|
if (arg0 == null) {
|
|
1398
1385
|
return [];
|
|
1399
1386
|
}
|
|
1400
|
-
const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) =>
|
|
1401
|
-
const fixedArg1Text = tsPattern.match(arg1).with(tsPattern.P.nullish, () =>
|
|
1402
|
-
if (
|
|
1387
|
+
const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: types.AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => eff._);
|
|
1388
|
+
const fixedArg1Text = tsPattern.match(arg1).with(tsPattern.P.nullish, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.not("ref") }, (n) => `ref: ${n.name}`).otherwise(() => eff._);
|
|
1389
|
+
if (fixedArg0Text == null || fixedArg1Text == null) {
|
|
1403
1390
|
return [];
|
|
1404
1391
|
}
|
|
1405
|
-
const fixedPropsText = fixedArg0Text.value;
|
|
1406
|
-
const fixedRefText = fixedArg1Text.value;
|
|
1407
1392
|
if (typeArg0 == null || typeArg1 == null) {
|
|
1408
1393
|
return [
|
|
1409
1394
|
fixer.replaceText(
|
|
1410
1395
|
arg0,
|
|
1411
1396
|
[
|
|
1412
1397
|
"{",
|
|
1413
|
-
|
|
1414
|
-
|
|
1398
|
+
fixedArg1Text + ",",
|
|
1399
|
+
fixedArg0Text,
|
|
1415
1400
|
"}"
|
|
1416
1401
|
].join(" ")
|
|
1417
1402
|
),
|
|
@@ -1423,8 +1408,8 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1423
1408
|
arg0,
|
|
1424
1409
|
[
|
|
1425
1410
|
"{",
|
|
1426
|
-
|
|
1427
|
-
|
|
1411
|
+
fixedArg1Text + ",",
|
|
1412
|
+
fixedArg0Text,
|
|
1428
1413
|
"}:",
|
|
1429
1414
|
getText(typeArg1),
|
|
1430
1415
|
"&",
|
|
@@ -1455,17 +1440,17 @@ var no_implicit_key_default = createRule({
|
|
|
1455
1440
|
},
|
|
1456
1441
|
name: RULE_NAME26,
|
|
1457
1442
|
create(context) {
|
|
1458
|
-
function getReportDescriptor(node) {
|
|
1459
|
-
const initialScope = context.sourceCode.getScope(node);
|
|
1460
|
-
const keyPropFound = JSX7__namespace.findPropInAttributes(node.attributes, initialScope)("key");
|
|
1461
|
-
const keyPropOnElement = node.attributes.some((n) => AST11__namespace.is(types.AST_NODE_TYPES.JSXAttribute)(n) && n.name.name === "key");
|
|
1462
|
-
if (eff.O.isSome(keyPropFound) && !keyPropOnElement) {
|
|
1463
|
-
return eff.O.some({ messageId: "noImplicitKey", node: keyPropFound.value });
|
|
1464
|
-
}
|
|
1465
|
-
return eff.O.none();
|
|
1466
|
-
}
|
|
1467
1443
|
return {
|
|
1468
|
-
JSXOpeningElement
|
|
1444
|
+
JSXOpeningElement(node) {
|
|
1445
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
1446
|
+
const keyPropFound = JSX7__namespace.findPropInAttributes("key", initialScope, node.attributes);
|
|
1447
|
+
const keyPropOnElement = node.attributes.some(
|
|
1448
|
+
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1449
|
+
);
|
|
1450
|
+
if (keyPropFound && !keyPropOnElement) {
|
|
1451
|
+
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1469
1454
|
};
|
|
1470
1455
|
},
|
|
1471
1456
|
defaultOptions: []
|
|
@@ -1511,11 +1496,12 @@ function inspectVariantTypes(types) {
|
|
|
1511
1496
|
const booleans = types.filter(tsHelpers.isBooleanType);
|
|
1512
1497
|
switch (true) {
|
|
1513
1498
|
case (booleans.length === 1 && booleans[0] != null): {
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
)
|
|
1518
|
-
|
|
1499
|
+
const first = booleans[0];
|
|
1500
|
+
if (tsApiUtils.isTrueLiteralType(first)) {
|
|
1501
|
+
variantTypes.add("truthy boolean");
|
|
1502
|
+
} else if (tsApiUtils.isFalseLiteralType(first)) {
|
|
1503
|
+
variantTypes.add("falsy boolean");
|
|
1504
|
+
}
|
|
1519
1505
|
break;
|
|
1520
1506
|
}
|
|
1521
1507
|
case booleans.length === 2: {
|
|
@@ -1525,17 +1511,17 @@ function inspectVariantTypes(types) {
|
|
|
1525
1511
|
}
|
|
1526
1512
|
const strings = types.filter(tsHelpers.isStringType);
|
|
1527
1513
|
if (strings.length > 0) {
|
|
1528
|
-
const evaluated = tsPattern.match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType),
|
|
1514
|
+
const evaluated = tsPattern.match(strings).when((types2) => types2.every(tsHelpers.isTruthyStringType), () => "truthy string").when((types2) => types2.every(tsHelpers.isFalsyStringType), () => "falsy string").otherwise(() => "string");
|
|
1529
1515
|
variantTypes.add(evaluated);
|
|
1530
1516
|
}
|
|
1531
1517
|
const bigints = types.filter(tsHelpers.isBigIntType);
|
|
1532
1518
|
if (bigints.length > 0) {
|
|
1533
|
-
const evaluated = tsPattern.match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType),
|
|
1519
|
+
const evaluated = tsPattern.match(bigints).when((types2) => types2.every(tsHelpers.isTruthyBigIntType), () => "truthy bigint").when((types2) => types2.every(tsHelpers.isFalsyBigIntType), () => "falsy bigint").otherwise(() => "bigint");
|
|
1534
1520
|
variantTypes.add(evaluated);
|
|
1535
1521
|
}
|
|
1536
1522
|
const numbers = types.filter(tsHelpers.isNumberType);
|
|
1537
1523
|
if (numbers.length > 0) {
|
|
1538
|
-
const evaluated = tsPattern.match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType),
|
|
1524
|
+
const evaluated = tsPattern.match(numbers).when((types2) => types2.every(tsHelpers.isTruthyNumberType), () => "truthy number").when((types2) => types2.every(tsHelpers.isFalsyNumberType), () => "falsy number").otherwise(() => "number");
|
|
1539
1525
|
variantTypes.add(evaluated);
|
|
1540
1526
|
}
|
|
1541
1527
|
if (types.some(tsHelpers.isEnumType)) {
|
|
@@ -1553,19 +1539,15 @@ function inspectVariantTypes(types) {
|
|
|
1553
1539
|
return variantTypes;
|
|
1554
1540
|
}
|
|
1555
1541
|
function isInitExpression(node) {
|
|
1542
|
+
if (node == null) return false;
|
|
1556
1543
|
return node.type !== types.AST_NODE_TYPES.VariableDeclaration;
|
|
1557
1544
|
}
|
|
1558
|
-
function getVariableInitExpression(at) {
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
(d) => "init" in d.node ? eff.O.fromNullable(d.node.init) : eff.O.none()
|
|
1565
|
-
),
|
|
1566
|
-
eff.O.filter(isInitExpression)
|
|
1567
|
-
);
|
|
1568
|
-
};
|
|
1545
|
+
function getVariableInitExpression(variable, at) {
|
|
1546
|
+
const def = variable?.defs[at];
|
|
1547
|
+
if (def?.node === eff._ || !("init" in def.node)) {
|
|
1548
|
+
return eff._;
|
|
1549
|
+
}
|
|
1550
|
+
return isInitExpression(def.node.init) ? def.node.init : eff._;
|
|
1569
1551
|
}
|
|
1570
1552
|
var no_leaked_conditional_rendering_default = createRule({
|
|
1571
1553
|
meta: {
|
|
@@ -1599,19 +1581,20 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1599
1581
|
];
|
|
1600
1582
|
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
1601
1583
|
function getReportDescriptor(node) {
|
|
1602
|
-
|
|
1584
|
+
if (node === eff._) return eff._;
|
|
1585
|
+
return tsPattern.match(node).when(AST11__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1603
1586
|
const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1604
1587
|
if (isLeftUnaryNot) {
|
|
1605
1588
|
return getReportDescriptor(right);
|
|
1606
1589
|
}
|
|
1607
1590
|
const initialScope = context.sourceCode.getScope(left);
|
|
1608
|
-
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" ||
|
|
1591
|
+
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.toResolved({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1609
1592
|
if (isLeftNan) {
|
|
1610
|
-
return
|
|
1593
|
+
return {
|
|
1611
1594
|
messageId: "noLeakedConditionalRendering",
|
|
1612
1595
|
node: left,
|
|
1613
1596
|
data: { value: context.sourceCode.getText(left) }
|
|
1614
|
-
}
|
|
1597
|
+
};
|
|
1615
1598
|
}
|
|
1616
1599
|
const leftType = typeUtils.getConstrainedTypeAtLocation(services, left);
|
|
1617
1600
|
const leftTypeVariants = inspectVariantTypes(tsApiUtils.unionTypeParts(leftType));
|
|
@@ -1619,22 +1602,24 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1619
1602
|
if (isLeftValid) {
|
|
1620
1603
|
return getReportDescriptor(right);
|
|
1621
1604
|
}
|
|
1622
|
-
return
|
|
1605
|
+
return {
|
|
1623
1606
|
messageId: "noLeakedConditionalRendering",
|
|
1624
1607
|
node: left,
|
|
1625
1608
|
data: { value: context.sourceCode.getText(left) }
|
|
1626
|
-
}
|
|
1609
|
+
};
|
|
1627
1610
|
}).with({ type: types.AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
|
|
1628
|
-
return
|
|
1611
|
+
return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
|
|
1629
1612
|
}).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
);
|
|
1635
|
-
}).otherwise(eff.O.none);
|
|
1613
|
+
const variable = VAR__namespace.findVariable(n.name, context.sourceCode.getScope(n));
|
|
1614
|
+
const initExpression = getVariableInitExpression(variable, 0);
|
|
1615
|
+
return getReportDescriptor(initExpression);
|
|
1616
|
+
}).otherwise(() => eff._);
|
|
1636
1617
|
}
|
|
1637
|
-
const visitorFunction =
|
|
1618
|
+
const visitorFunction = (node) => {
|
|
1619
|
+
const descriptor = getReportDescriptor(node);
|
|
1620
|
+
if (descriptor === eff._) return;
|
|
1621
|
+
context.report(descriptor);
|
|
1622
|
+
};
|
|
1638
1623
|
return {
|
|
1639
1624
|
"JSXExpressionContainer > ConditionalExpression": visitorFunction,
|
|
1640
1625
|
"JSXExpressionContainer > LogicalExpression": visitorFunction
|
|
@@ -1670,13 +1655,13 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1670
1655
|
const components = ctx.getAllComponents(node);
|
|
1671
1656
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1672
1657
|
const isMemoOrForwardRef = (flag & (core.ERFunctionComponentFlag.ForwardRef | core.ERFunctionComponentFlag.Memo)) > 0n;
|
|
1673
|
-
if (
|
|
1658
|
+
if (AST11__namespace.getFunctionIdentifier(node2)) {
|
|
1674
1659
|
continue;
|
|
1675
1660
|
}
|
|
1676
1661
|
if (!isMemoOrForwardRef) {
|
|
1677
1662
|
continue;
|
|
1678
1663
|
}
|
|
1679
|
-
if (
|
|
1664
|
+
if (!displayName) {
|
|
1680
1665
|
context.report({
|
|
1681
1666
|
messageId: "noMissingComponentDisplayName",
|
|
1682
1667
|
node: node2
|
|
@@ -1712,51 +1697,55 @@ var no_missing_key_default = createRule({
|
|
|
1712
1697
|
switch (node.type) {
|
|
1713
1698
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1714
1699
|
const initialScope = context.sourceCode.getScope(node);
|
|
1715
|
-
if (!JSX7__namespace.hasProp(
|
|
1716
|
-
return
|
|
1700
|
+
if (!JSX7__namespace.hasProp("key", initialScope, node.openingElement.attributes)) {
|
|
1701
|
+
return {
|
|
1717
1702
|
messageId: "noMissingKey",
|
|
1718
1703
|
node
|
|
1719
|
-
}
|
|
1704
|
+
};
|
|
1720
1705
|
}
|
|
1721
|
-
return
|
|
1706
|
+
return null;
|
|
1722
1707
|
}
|
|
1723
1708
|
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1724
|
-
return
|
|
1709
|
+
return {
|
|
1725
1710
|
messageId: "noMissingKeyWithFragment",
|
|
1726
1711
|
node
|
|
1727
|
-
}
|
|
1712
|
+
};
|
|
1728
1713
|
}
|
|
1729
1714
|
default:
|
|
1730
|
-
return
|
|
1715
|
+
return null;
|
|
1731
1716
|
}
|
|
1732
1717
|
}
|
|
1733
1718
|
function checkExpression(node) {
|
|
1734
1719
|
switch (node.type) {
|
|
1735
1720
|
case types.AST_NODE_TYPES.ConditionalExpression:
|
|
1736
|
-
if (
|
|
1737
|
-
return
|
|
1721
|
+
if ("consequent" in node) {
|
|
1722
|
+
return checkIteratorElement(node.consequent) ?? checkIteratorElement(node.alternate);
|
|
1738
1723
|
}
|
|
1739
|
-
return
|
|
1724
|
+
return null;
|
|
1740
1725
|
case types.AST_NODE_TYPES.JSXElement:
|
|
1741
1726
|
case types.AST_NODE_TYPES.JSXFragment:
|
|
1742
1727
|
return checkIteratorElement(node);
|
|
1743
1728
|
case types.AST_NODE_TYPES.LogicalExpression:
|
|
1744
|
-
if (
|
|
1745
|
-
return
|
|
1729
|
+
if ("left" in node) {
|
|
1730
|
+
return checkIteratorElement(node.left) ?? checkIteratorElement(node.right);
|
|
1746
1731
|
}
|
|
1747
|
-
return
|
|
1732
|
+
return null;
|
|
1748
1733
|
default:
|
|
1749
|
-
return
|
|
1734
|
+
return null;
|
|
1750
1735
|
}
|
|
1751
1736
|
}
|
|
1752
1737
|
function checkBlockStatement(node) {
|
|
1753
|
-
|
|
1738
|
+
const descriptors = [];
|
|
1739
|
+
for (const statement of AST11__namespace.getNestedReturnStatements(node)) {
|
|
1754
1740
|
if (statement.argument == null) {
|
|
1755
|
-
|
|
1741
|
+
continue;
|
|
1756
1742
|
}
|
|
1757
|
-
const
|
|
1758
|
-
|
|
1759
|
-
|
|
1743
|
+
const descriptor = checkIteratorElement(statement.argument);
|
|
1744
|
+
if (descriptor != null) {
|
|
1745
|
+
descriptors.push(descriptor);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
return descriptors;
|
|
1760
1749
|
}
|
|
1761
1750
|
return {
|
|
1762
1751
|
ArrayExpression(node) {
|
|
@@ -1769,7 +1758,7 @@ var no_missing_key_default = createRule({
|
|
|
1769
1758
|
}
|
|
1770
1759
|
const initialScope = context.sourceCode.getScope(node);
|
|
1771
1760
|
for (const element of elements) {
|
|
1772
|
-
if (!JSX7__namespace.hasProp(
|
|
1761
|
+
if (!JSX7__namespace.hasProp("key", initialScope, element.openingElement.attributes)) {
|
|
1773
1762
|
context.report({
|
|
1774
1763
|
messageId: "noMissingKey",
|
|
1775
1764
|
node: element
|
|
@@ -1782,30 +1771,24 @@ var no_missing_key_default = createRule({
|
|
|
1782
1771
|
if (state.isWithinChildrenToArray) {
|
|
1783
1772
|
return;
|
|
1784
1773
|
}
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1787
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
1788
|
-
callee: {
|
|
1789
|
-
type: types.AST_NODE_TYPES.MemberExpression,
|
|
1790
|
-
property: {
|
|
1791
|
-
name: "from"
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
}, node);
|
|
1795
|
-
if (!isMapCall && !isArrayFromCall) {
|
|
1774
|
+
const isMapCallLike = AST11__namespace.isMapCallLoose(node);
|
|
1775
|
+
if (!isMapCallLike && !isArrayFromCall(node)) {
|
|
1796
1776
|
return;
|
|
1797
1777
|
}
|
|
1798
|
-
const fn = node.arguments[
|
|
1799
|
-
if (
|
|
1778
|
+
const fn = node.arguments[isMapCallLike ? 0 : 1];
|
|
1779
|
+
if (fn?.type !== types.AST_NODE_TYPES.ArrowFunctionExpression && fn?.type !== types.AST_NODE_TYPES.FunctionExpression) {
|
|
1800
1780
|
return;
|
|
1801
1781
|
}
|
|
1802
1782
|
if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
|
|
1803
|
-
for (const
|
|
1804
|
-
context.report(
|
|
1783
|
+
for (const descriptor2 of checkBlockStatement(fn.body)) {
|
|
1784
|
+
context.report(descriptor2);
|
|
1805
1785
|
}
|
|
1806
1786
|
return;
|
|
1807
1787
|
}
|
|
1808
|
-
|
|
1788
|
+
const descriptor = checkExpression(fn.body);
|
|
1789
|
+
if (descriptor != null) {
|
|
1790
|
+
context.report(descriptor);
|
|
1791
|
+
}
|
|
1809
1792
|
},
|
|
1810
1793
|
"CallExpression:exit"(node) {
|
|
1811
1794
|
if (!core.isChildrenToArrayCall(node, context)) {
|
|
@@ -1828,6 +1811,9 @@ var no_missing_key_default = createRule({
|
|
|
1828
1811
|
},
|
|
1829
1812
|
defaultOptions: []
|
|
1830
1813
|
});
|
|
1814
|
+
function isArrayFromCall(node) {
|
|
1815
|
+
return node.type === types.AST_NODE_TYPES.CallExpression && node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "from";
|
|
1816
|
+
}
|
|
1831
1817
|
var RULE_NAME30 = "no-nested-components";
|
|
1832
1818
|
var RULE_FEATURES30 = [
|
|
1833
1819
|
"CHK"
|
|
@@ -1854,24 +1840,27 @@ var no_nested_components_default = createRule({
|
|
|
1854
1840
|
...collector.listeners,
|
|
1855
1841
|
...collectorLegacy.listeners,
|
|
1856
1842
|
"Program:exit"(node) {
|
|
1857
|
-
const functionComponents =
|
|
1858
|
-
|
|
1843
|
+
const functionComponents = [
|
|
1844
|
+
...collector.ctx.getAllComponents(node).values()
|
|
1845
|
+
];
|
|
1846
|
+
const classComponents = [
|
|
1847
|
+
...collectorLegacy.ctx.getAllComponents(node).values()
|
|
1848
|
+
];
|
|
1859
1849
|
const isFunctionComponent = (node2) => {
|
|
1860
1850
|
return AST11__namespace.isFunction(node2) && functionComponents.some((component) => component.node === node2);
|
|
1861
1851
|
};
|
|
1862
1852
|
const isClassComponent11 = (node2) => {
|
|
1863
1853
|
return AST11__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1864
1854
|
};
|
|
1865
|
-
for (const { name:
|
|
1855
|
+
for (const { name: name2, node: component } of functionComponents) {
|
|
1866
1856
|
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
1867
1857
|
continue;
|
|
1868
1858
|
}
|
|
1869
|
-
if (eff.
|
|
1859
|
+
if (name2 === eff._) {
|
|
1870
1860
|
continue;
|
|
1871
1861
|
}
|
|
1872
|
-
const name2 = componentName.value;
|
|
1873
1862
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1874
|
-
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute ||
|
|
1863
|
+
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || !!JSX7__namespace.findParentProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer);
|
|
1875
1864
|
if (isInsideJSXPropValue) {
|
|
1876
1865
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1877
1866
|
context.report({
|
|
@@ -1894,13 +1883,8 @@ var no_nested_components_default = createRule({
|
|
|
1894
1883
|
});
|
|
1895
1884
|
continue;
|
|
1896
1885
|
}
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
component,
|
|
1900
|
-
isFunctionComponent
|
|
1901
|
-
),
|
|
1902
|
-
eff.not(core.isDirectValueOfRenderPropertyLoose)
|
|
1903
|
-
);
|
|
1886
|
+
const parentComponent = AST11__namespace.findParentNodeGuard(component, isFunctionComponent);
|
|
1887
|
+
const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1904
1888
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1905
1889
|
context.report({
|
|
1906
1890
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
@@ -1921,15 +1905,15 @@ var no_nested_components_default = createRule({
|
|
|
1921
1905
|
});
|
|
1922
1906
|
}
|
|
1923
1907
|
}
|
|
1924
|
-
for (const { name: name2, node: component } of classComponents) {
|
|
1925
|
-
if (
|
|
1908
|
+
for (const { name: name2 = "unknown", node: component } of classComponents) {
|
|
1909
|
+
if (!AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
|
|
1926
1910
|
continue;
|
|
1927
1911
|
}
|
|
1928
1912
|
context.report({
|
|
1929
1913
|
messageId: "nestedComponent",
|
|
1930
1914
|
node: component,
|
|
1931
1915
|
data: {
|
|
1932
|
-
name:
|
|
1916
|
+
name: name2
|
|
1933
1917
|
}
|
|
1934
1918
|
});
|
|
1935
1919
|
}
|
|
@@ -1974,15 +1958,11 @@ var no_prop_types_default = createRule({
|
|
|
1974
1958
|
if (!core.isComponentName(object.name)) {
|
|
1975
1959
|
return;
|
|
1976
1960
|
}
|
|
1977
|
-
const
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
);
|
|
1982
|
-
if (!isComponent) {
|
|
1983
|
-
return;
|
|
1961
|
+
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1962
|
+
const variableNode = variable && VAR__namespace.getVariableNode(variable, 0);
|
|
1963
|
+
if (variableNode && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
1964
|
+
context.report({ messageId: "noPropTypes", node: property });
|
|
1984
1965
|
}
|
|
1985
|
-
context.report({ messageId: "noPropTypes", node: property });
|
|
1986
1966
|
},
|
|
1987
1967
|
PropertyDefinition(node) {
|
|
1988
1968
|
if (!core.isClassComponent(node.parent.parent)) {
|
|
@@ -2026,7 +2006,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2026
2006
|
...listeners,
|
|
2027
2007
|
"Program:exit"(node) {
|
|
2028
2008
|
const components = ctx.getAllComponents(node);
|
|
2029
|
-
for (const { name: name2, node: component, flag } of components.values()) {
|
|
2009
|
+
for (const { name: name2 = "PureComponent", node: component, flag } of components.values()) {
|
|
2030
2010
|
if ((flag & core.ERClassComponentFlag.PureComponent) === 0n) {
|
|
2031
2011
|
continue;
|
|
2032
2012
|
}
|
|
@@ -2037,7 +2017,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2037
2017
|
messageId: "noRedundantShouldComponentUpdate",
|
|
2038
2018
|
node: member,
|
|
2039
2019
|
data: {
|
|
2040
|
-
componentName:
|
|
2020
|
+
componentName: name2
|
|
2041
2021
|
}
|
|
2042
2022
|
});
|
|
2043
2023
|
}
|
|
@@ -2072,32 +2052,22 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2072
2052
|
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2073
2053
|
return {};
|
|
2074
2054
|
}
|
|
2075
|
-
function getReportDescriptor(node) {
|
|
2076
|
-
if (!core.isThisSetState(node)) {
|
|
2077
|
-
return eff.O.none();
|
|
2078
|
-
}
|
|
2079
|
-
return eff.F.pipe(
|
|
2080
|
-
eff.O.Do,
|
|
2081
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2082
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentDidMount)),
|
|
2083
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2084
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2085
|
-
eff.O.filter(
|
|
2086
|
-
({
|
|
2087
|
-
clazz,
|
|
2088
|
-
method,
|
|
2089
|
-
methodScope,
|
|
2090
|
-
upperScope
|
|
2091
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2092
|
-
),
|
|
2093
|
-
eff.O.map(() => ({
|
|
2094
|
-
messageId: "noSetStateInComponentDidMount",
|
|
2095
|
-
node
|
|
2096
|
-
}))
|
|
2097
|
-
);
|
|
2098
|
-
}
|
|
2099
2055
|
return {
|
|
2100
|
-
CallExpression
|
|
2056
|
+
CallExpression(node) {
|
|
2057
|
+
if (!core.isThisSetState(node)) {
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2061
|
+
const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentDidMount);
|
|
2062
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2063
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2064
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2065
|
+
context.report({
|
|
2066
|
+
messageId: "noSetStateInComponentDidMount",
|
|
2067
|
+
node
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2101
2071
|
};
|
|
2102
2072
|
},
|
|
2103
2073
|
defaultOptions: []
|
|
@@ -2126,32 +2096,22 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2126
2096
|
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2127
2097
|
return {};
|
|
2128
2098
|
}
|
|
2129
|
-
function getReportDescriptor(node) {
|
|
2130
|
-
if (!core.isThisSetState(node)) {
|
|
2131
|
-
return eff.O.none();
|
|
2132
|
-
}
|
|
2133
|
-
return eff.F.pipe(
|
|
2134
|
-
eff.O.Do,
|
|
2135
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2136
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentDidUpdate)),
|
|
2137
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2138
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2139
|
-
eff.O.filter(
|
|
2140
|
-
({
|
|
2141
|
-
clazz,
|
|
2142
|
-
method,
|
|
2143
|
-
methodScope,
|
|
2144
|
-
upperScope
|
|
2145
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2146
|
-
),
|
|
2147
|
-
eff.O.map(() => ({
|
|
2148
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
2149
|
-
node
|
|
2150
|
-
}))
|
|
2151
|
-
);
|
|
2152
|
-
}
|
|
2153
2099
|
return {
|
|
2154
|
-
CallExpression
|
|
2100
|
+
CallExpression(node) {
|
|
2101
|
+
if (!core.isThisSetState(node)) {
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2105
|
+
const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentDidUpdate);
|
|
2106
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2107
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2108
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2109
|
+
context.report({
|
|
2110
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
2111
|
+
node
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2155
2115
|
};
|
|
2156
2116
|
},
|
|
2157
2117
|
defaultOptions: []
|
|
@@ -2180,32 +2140,22 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2180
2140
|
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2181
2141
|
return {};
|
|
2182
2142
|
}
|
|
2183
|
-
function getReportDescriptor(node) {
|
|
2184
|
-
if (!core.isThisSetState(node)) {
|
|
2185
|
-
return eff.O.none();
|
|
2186
|
-
}
|
|
2187
|
-
return eff.F.pipe(
|
|
2188
|
-
eff.O.Do,
|
|
2189
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2190
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentWillUpdate3)),
|
|
2191
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2192
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2193
|
-
eff.O.filter(
|
|
2194
|
-
({
|
|
2195
|
-
clazz,
|
|
2196
|
-
method,
|
|
2197
|
-
methodScope,
|
|
2198
|
-
upperScope
|
|
2199
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2200
|
-
),
|
|
2201
|
-
eff.O.map(() => ({
|
|
2202
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
2203
|
-
node
|
|
2204
|
-
}))
|
|
2205
|
-
);
|
|
2206
|
-
}
|
|
2207
2143
|
return {
|
|
2208
|
-
CallExpression
|
|
2144
|
+
CallExpression(node) {
|
|
2145
|
+
if (!core.isThisSetState(node)) {
|
|
2146
|
+
return;
|
|
2147
|
+
}
|
|
2148
|
+
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2149
|
+
const method = clazz && AST11__namespace.findParentNodeStop(node, clazz, isComponentWillUpdate3);
|
|
2150
|
+
const methodScope = method && context.sourceCode.getScope(method);
|
|
2151
|
+
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2152
|
+
if (clazz && method && method.parent === clazz.body && upperScope === methodScope) {
|
|
2153
|
+
context.report({
|
|
2154
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
2155
|
+
node
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2209
2159
|
};
|
|
2210
2160
|
},
|
|
2211
2161
|
defaultOptions: []
|
|
@@ -2215,14 +2165,14 @@ var RULE_FEATURES36 = [
|
|
|
2215
2165
|
"CHK"
|
|
2216
2166
|
];
|
|
2217
2167
|
function containsStringLiteral({ value }) {
|
|
2218
|
-
return value?.type === types.AST_NODE_TYPES.Literal &&
|
|
2168
|
+
return value?.type === types.AST_NODE_TYPES.Literal && typeof value.value === "string";
|
|
2219
2169
|
}
|
|
2220
2170
|
function containsStringExpressionContainer({ value }) {
|
|
2221
2171
|
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2222
2172
|
return false;
|
|
2223
2173
|
}
|
|
2224
2174
|
if (value.expression.type === types.AST_NODE_TYPES.Literal) {
|
|
2225
|
-
return
|
|
2175
|
+
return typeof value.expression.value === "string";
|
|
2226
2176
|
}
|
|
2227
2177
|
return value.expression.type === types.AST_NODE_TYPES.TemplateLiteral;
|
|
2228
2178
|
}
|
|
@@ -2423,39 +2373,28 @@ var no_unstable_context_value_default = createRule({
|
|
|
2423
2373
|
if (openingElementName.property.name !== "Provider") {
|
|
2424
2374
|
return;
|
|
2425
2375
|
}
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
node.attributes.find((attribute) => {
|
|
2431
|
-
return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
|
|
2432
|
-
})
|
|
2433
|
-
)),
|
|
2434
|
-
eff.O.bind("value", ({ attribute }) => "value" in attribute ? eff.O.some(attribute.value) : eff.O.none()),
|
|
2435
|
-
eff.O.bind("valueExpression", ({ value }) => value?.type === types.AST_NODE_TYPES.JSXExpressionContainer ? eff.O.some(value.expression) : eff.O.none()),
|
|
2436
|
-
eff.O.bind("construction", ({ valueExpression }) => {
|
|
2437
|
-
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2438
|
-
return eff.O.some(VAR__namespace.getValueConstruction(valueExpression, initialScope));
|
|
2439
|
-
}),
|
|
2440
|
-
eff.O.map((vc) => {
|
|
2441
|
-
if (vc.construction.kind === "None") {
|
|
2442
|
-
return;
|
|
2443
|
-
}
|
|
2444
|
-
if (core.isReactHookCall(vc.construction.node)) {
|
|
2445
|
-
return;
|
|
2446
|
-
}
|
|
2447
|
-
const prevs = constructions.get(vc.function.node) ?? [];
|
|
2448
|
-
constructions.set(vc.function.node, [...prevs, vc.construction]);
|
|
2449
|
-
})
|
|
2376
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2377
|
+
if (functionEntry === eff._) return;
|
|
2378
|
+
const attribute = node.attributes.find(
|
|
2379
|
+
(attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2450
2380
|
);
|
|
2381
|
+
if (attribute === eff._ || !("value" in attribute)) return;
|
|
2382
|
+
const value = attribute.value;
|
|
2383
|
+
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2384
|
+
const valueExpression = value.expression;
|
|
2385
|
+
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2386
|
+
const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
|
|
2387
|
+
if (construction === eff._) return;
|
|
2388
|
+
if (core.isReactHookCall(construction.node)) {
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
const prevs = constructions.get(functionEntry.node) ?? [];
|
|
2392
|
+
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2451
2393
|
},
|
|
2452
2394
|
"Program:exit"(node) {
|
|
2453
2395
|
const components = ctx.getAllComponents(node).values();
|
|
2454
2396
|
for (const { node: component } of components) {
|
|
2455
2397
|
for (const construction of constructions.get(component) ?? []) {
|
|
2456
|
-
if (construction.kind === "None") {
|
|
2457
|
-
continue;
|
|
2458
|
-
}
|
|
2459
2398
|
const { kind, node: constructionNode } = construction;
|
|
2460
2399
|
const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
2461
2400
|
context.report({
|
|
@@ -2517,7 +2456,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2517
2456
|
initialScope,
|
|
2518
2457
|
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2519
2458
|
);
|
|
2520
|
-
if (construction
|
|
2459
|
+
if (construction === eff._) {
|
|
2521
2460
|
continue;
|
|
2522
2461
|
}
|
|
2523
2462
|
if (core.isReactHookCall(construction.node)) {
|
|
@@ -2535,13 +2474,10 @@ var no_unstable_default_props_default = createRule({
|
|
|
2535
2474
|
}
|
|
2536
2475
|
},
|
|
2537
2476
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2538
|
-
const
|
|
2539
|
-
if (
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
const entry = mbEntry.value;
|
|
2543
|
-
const prevs = declarators.get(entry.node) ?? [];
|
|
2544
|
-
declarators.set(entry.node, [...prevs, node]);
|
|
2477
|
+
const functionEntry = ctx.getCurrentEntry();
|
|
2478
|
+
if (!functionEntry) return;
|
|
2479
|
+
const prevs = declarators.get(functionEntry.node) ?? [];
|
|
2480
|
+
declarators.set(functionEntry.node, [...prevs, node]);
|
|
2545
2481
|
}
|
|
2546
2482
|
};
|
|
2547
2483
|
},
|
|
@@ -2573,15 +2509,15 @@ function getName3(node) {
|
|
|
2573
2509
|
return getName3(node.expression);
|
|
2574
2510
|
}
|
|
2575
2511
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2576
|
-
return
|
|
2512
|
+
return node.name;
|
|
2577
2513
|
}
|
|
2578
2514
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2579
|
-
return
|
|
2515
|
+
return node.value?.toString();
|
|
2580
2516
|
}
|
|
2581
2517
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2582
|
-
return
|
|
2518
|
+
return node.quasis[0]?.value.raw;
|
|
2583
2519
|
}
|
|
2584
|
-
return eff.
|
|
2520
|
+
return eff._;
|
|
2585
2521
|
}
|
|
2586
2522
|
var no_unused_class_component_members_default = createRule({
|
|
2587
2523
|
meta: {
|
|
@@ -2597,12 +2533,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2597
2533
|
},
|
|
2598
2534
|
name: RULE_NAME42,
|
|
2599
2535
|
create(context) {
|
|
2600
|
-
const
|
|
2601
|
-
const
|
|
2536
|
+
const classEntries = [];
|
|
2537
|
+
const methodEntries = [];
|
|
2602
2538
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
2603
2539
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2604
2540
|
function classEnter(node) {
|
|
2605
|
-
|
|
2541
|
+
classEntries.push(node);
|
|
2606
2542
|
if (!core.isClassComponent(node)) {
|
|
2607
2543
|
return;
|
|
2608
2544
|
}
|
|
@@ -2610,37 +2546,37 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2610
2546
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2611
2547
|
}
|
|
2612
2548
|
function classExit() {
|
|
2613
|
-
const currentClass =
|
|
2549
|
+
const currentClass = classEntries.pop();
|
|
2614
2550
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2615
2551
|
return;
|
|
2616
2552
|
}
|
|
2617
|
-
const className =
|
|
2553
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2618
2554
|
const defs = propertyDefs.get(currentClass);
|
|
2619
2555
|
const usages = propertyUsages.get(currentClass);
|
|
2620
2556
|
if (defs == null) {
|
|
2621
2557
|
return;
|
|
2622
2558
|
}
|
|
2623
2559
|
for (const def of defs) {
|
|
2624
|
-
const
|
|
2625
|
-
if (
|
|
2560
|
+
const methodName = getName3(def);
|
|
2561
|
+
if (methodName == null) {
|
|
2626
2562
|
continue;
|
|
2627
2563
|
}
|
|
2628
|
-
if (usages?.has(
|
|
2564
|
+
if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
|
|
2629
2565
|
continue;
|
|
2630
2566
|
}
|
|
2631
2567
|
context.report({
|
|
2632
2568
|
messageId: "noUnusedClassComponentMembers",
|
|
2633
2569
|
node: def,
|
|
2634
2570
|
data: {
|
|
2635
|
-
className:
|
|
2636
|
-
methodName
|
|
2571
|
+
className: className ?? "Component",
|
|
2572
|
+
methodName
|
|
2637
2573
|
}
|
|
2638
2574
|
});
|
|
2639
2575
|
}
|
|
2640
2576
|
}
|
|
2641
2577
|
function methodEnter(node) {
|
|
2642
|
-
|
|
2643
|
-
const currentClass =
|
|
2578
|
+
methodEntries.push(node);
|
|
2579
|
+
const currentClass = classEntries.at(-1);
|
|
2644
2580
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2645
2581
|
return;
|
|
2646
2582
|
}
|
|
@@ -2652,7 +2588,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2652
2588
|
}
|
|
2653
2589
|
}
|
|
2654
2590
|
function methodExit() {
|
|
2655
|
-
|
|
2591
|
+
methodEntries.pop();
|
|
2656
2592
|
}
|
|
2657
2593
|
return {
|
|
2658
2594
|
ClassDeclaration: classEnter,
|
|
@@ -2660,8 +2596,8 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2660
2596
|
ClassExpression: classEnter,
|
|
2661
2597
|
"ClassExpression:exit": classExit,
|
|
2662
2598
|
MemberExpression(node) {
|
|
2663
|
-
const currentClass =
|
|
2664
|
-
const currentMethod =
|
|
2599
|
+
const currentClass = classEntries.at(-1);
|
|
2600
|
+
const currentMethod = methodEntries.at(-1);
|
|
2665
2601
|
if (currentClass == null || currentMethod == null) {
|
|
2666
2602
|
return;
|
|
2667
2603
|
}
|
|
@@ -2675,15 +2611,18 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2675
2611
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2676
2612
|
return;
|
|
2677
2613
|
}
|
|
2678
|
-
|
|
2614
|
+
const propertyName = getName3(node.property);
|
|
2615
|
+
if (propertyName != null) {
|
|
2616
|
+
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2617
|
+
}
|
|
2679
2618
|
},
|
|
2680
2619
|
MethodDefinition: methodEnter,
|
|
2681
2620
|
"MethodDefinition:exit": methodExit,
|
|
2682
2621
|
PropertyDefinition: methodEnter,
|
|
2683
2622
|
"PropertyDefinition:exit": methodExit,
|
|
2684
2623
|
VariableDeclarator(node) {
|
|
2685
|
-
const currentClass =
|
|
2686
|
-
const currentMethod =
|
|
2624
|
+
const currentClass = classEntries.at(-1);
|
|
2625
|
+
const currentMethod = methodEntries.at(-1);
|
|
2687
2626
|
if (currentClass == null || currentMethod == null) {
|
|
2688
2627
|
return;
|
|
2689
2628
|
}
|
|
@@ -2693,10 +2632,9 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2693
2632
|
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2694
2633
|
for (const prop of node.id.properties) {
|
|
2695
2634
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2696
|
-
const
|
|
2697
|
-
if (
|
|
2698
|
-
|
|
2699
|
-
propertyUsages.get(currentClass)?.add(name2);
|
|
2635
|
+
const keyName = getName3(prop.key);
|
|
2636
|
+
if (keyName != null) {
|
|
2637
|
+
propertyUsages.get(currentClass)?.add(keyName);
|
|
2700
2638
|
}
|
|
2701
2639
|
}
|
|
2702
2640
|
}
|
|
@@ -2715,19 +2653,19 @@ function getName4(node) {
|
|
|
2715
2653
|
return getName4(node.expression);
|
|
2716
2654
|
}
|
|
2717
2655
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2718
|
-
return
|
|
2656
|
+
return node.name;
|
|
2719
2657
|
}
|
|
2720
2658
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2721
|
-
return
|
|
2659
|
+
return String(node.value);
|
|
2722
2660
|
}
|
|
2723
2661
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2724
|
-
return
|
|
2662
|
+
return node.quasis[0]?.value.raw;
|
|
2725
2663
|
}
|
|
2726
|
-
return eff.
|
|
2664
|
+
return eff._;
|
|
2727
2665
|
}
|
|
2728
2666
|
function isAssignmentToThisState2(node) {
|
|
2729
2667
|
const { left } = node;
|
|
2730
|
-
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) &&
|
|
2668
|
+
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2731
2669
|
}
|
|
2732
2670
|
var isGetDerivedStateFromProps = tsPattern.isMatching({
|
|
2733
2671
|
key: {
|
|
@@ -2752,72 +2690,72 @@ var no_unused_state_default = createRule({
|
|
|
2752
2690
|
},
|
|
2753
2691
|
name: RULE_NAME43,
|
|
2754
2692
|
create(context) {
|
|
2755
|
-
const
|
|
2756
|
-
const
|
|
2757
|
-
const
|
|
2693
|
+
const classEntries = [];
|
|
2694
|
+
const methodEntries = [];
|
|
2695
|
+
const constructorEntries = [];
|
|
2758
2696
|
const stateDefs = /* @__PURE__ */ new WeakMap();
|
|
2759
2697
|
function classEnter(node) {
|
|
2760
|
-
|
|
2698
|
+
classEntries.push(node);
|
|
2761
2699
|
}
|
|
2762
2700
|
function classExit() {
|
|
2763
|
-
const currentClass =
|
|
2701
|
+
const currentClass = classEntries.pop();
|
|
2764
2702
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2765
2703
|
return;
|
|
2766
2704
|
}
|
|
2767
|
-
const className =
|
|
2768
|
-
const
|
|
2769
|
-
if (
|
|
2705
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2706
|
+
const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
|
|
2707
|
+
if (!defNode || isUsed) {
|
|
2770
2708
|
return;
|
|
2771
2709
|
}
|
|
2772
2710
|
context.report({
|
|
2773
2711
|
messageId: "noUnusedState",
|
|
2774
|
-
node:
|
|
2712
|
+
node: defNode,
|
|
2775
2713
|
data: {
|
|
2776
|
-
className:
|
|
2714
|
+
className: className ?? "Component"
|
|
2777
2715
|
}
|
|
2778
2716
|
});
|
|
2779
2717
|
}
|
|
2780
2718
|
function methodEnter(node) {
|
|
2781
|
-
|
|
2782
|
-
const currentClass =
|
|
2719
|
+
methodEntries.push(node);
|
|
2720
|
+
const currentClass = classEntries.at(-1);
|
|
2783
2721
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2784
2722
|
return;
|
|
2785
2723
|
}
|
|
2786
2724
|
if (node.static) {
|
|
2787
2725
|
if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
|
|
2788
|
-
const
|
|
2789
|
-
stateDefs.set(currentClass,
|
|
2726
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2727
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2790
2728
|
}
|
|
2791
2729
|
return;
|
|
2792
2730
|
}
|
|
2793
|
-
if (
|
|
2794
|
-
stateDefs.set(currentClass,
|
|
2731
|
+
if (getName4(node.key) === "state") {
|
|
2732
|
+
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2795
2733
|
}
|
|
2796
2734
|
}
|
|
2797
2735
|
function methodExit() {
|
|
2798
|
-
|
|
2736
|
+
methodEntries.pop();
|
|
2799
2737
|
}
|
|
2800
2738
|
function constructorEnter(node) {
|
|
2801
|
-
|
|
2739
|
+
constructorEntries.push(node);
|
|
2802
2740
|
}
|
|
2803
2741
|
function constructorExit() {
|
|
2804
|
-
|
|
2742
|
+
constructorEntries.pop();
|
|
2805
2743
|
}
|
|
2806
2744
|
return {
|
|
2807
2745
|
AssignmentExpression(node) {
|
|
2808
2746
|
if (!isAssignmentToThisState2(node)) {
|
|
2809
2747
|
return;
|
|
2810
2748
|
}
|
|
2811
|
-
const currentClass =
|
|
2749
|
+
const currentClass = classEntries.at(-1);
|
|
2812
2750
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2813
2751
|
return;
|
|
2814
2752
|
}
|
|
2815
|
-
const currentConstructor =
|
|
2753
|
+
const currentConstructor = constructorEntries.at(-1);
|
|
2816
2754
|
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2817
2755
|
return;
|
|
2818
2756
|
}
|
|
2819
|
-
const
|
|
2820
|
-
stateDefs.set(currentClass,
|
|
2757
|
+
const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
|
|
2758
|
+
stateDefs.set(currentClass, { node: node.left, isUsed });
|
|
2821
2759
|
},
|
|
2822
2760
|
ClassDeclaration: classEnter,
|
|
2823
2761
|
"ClassDeclaration:exit": classExit,
|
|
@@ -2827,25 +2765,25 @@ var no_unused_state_default = createRule({
|
|
|
2827
2765
|
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
2828
2766
|
return;
|
|
2829
2767
|
}
|
|
2830
|
-
if (
|
|
2768
|
+
if (getName4(node.property) !== "state") {
|
|
2831
2769
|
return;
|
|
2832
2770
|
}
|
|
2833
|
-
const currentClass =
|
|
2771
|
+
const currentClass = classEntries.at(-1);
|
|
2834
2772
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2835
2773
|
return;
|
|
2836
2774
|
}
|
|
2837
|
-
const currentMethod =
|
|
2775
|
+
const currentMethod = methodEntries.at(-1);
|
|
2838
2776
|
if (currentMethod == null || currentMethod.static) {
|
|
2839
2777
|
return;
|
|
2840
2778
|
}
|
|
2841
|
-
if (currentMethod ===
|
|
2779
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2842
2780
|
return;
|
|
2843
2781
|
}
|
|
2844
2782
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2845
2783
|
return;
|
|
2846
2784
|
}
|
|
2847
|
-
const
|
|
2848
|
-
stateDefs.set(currentClass,
|
|
2785
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2786
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2849
2787
|
},
|
|
2850
2788
|
MethodDefinition: methodEnter,
|
|
2851
2789
|
"MethodDefinition:exit": methodExit,
|
|
@@ -2854,15 +2792,15 @@ var no_unused_state_default = createRule({
|
|
|
2854
2792
|
PropertyDefinition: methodEnter,
|
|
2855
2793
|
"PropertyDefinition:exit": methodExit,
|
|
2856
2794
|
VariableDeclarator(node) {
|
|
2857
|
-
const currentClass =
|
|
2795
|
+
const currentClass = classEntries.at(-1);
|
|
2858
2796
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2859
2797
|
return;
|
|
2860
2798
|
}
|
|
2861
|
-
const currentMethod =
|
|
2799
|
+
const currentMethod = methodEntries.at(-1);
|
|
2862
2800
|
if (currentMethod == null || currentMethod.static) {
|
|
2863
2801
|
return;
|
|
2864
2802
|
}
|
|
2865
|
-
if (currentMethod ===
|
|
2803
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2866
2804
|
return;
|
|
2867
2805
|
}
|
|
2868
2806
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
@@ -2873,15 +2811,15 @@ var no_unused_state_default = createRule({
|
|
|
2873
2811
|
}
|
|
2874
2812
|
const hasState = node.id.properties.some((prop) => {
|
|
2875
2813
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2876
|
-
return
|
|
2814
|
+
return getName4(prop.key) === "state";
|
|
2877
2815
|
}
|
|
2878
2816
|
return false;
|
|
2879
2817
|
});
|
|
2880
2818
|
if (!hasState) {
|
|
2881
2819
|
return;
|
|
2882
2820
|
}
|
|
2883
|
-
const
|
|
2884
|
-
stateDefs.set(currentClass,
|
|
2821
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2822
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2885
2823
|
}
|
|
2886
2824
|
};
|
|
2887
2825
|
},
|
|
@@ -3001,15 +2939,15 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3001
2939
|
}
|
|
3002
2940
|
},
|
|
3003
2941
|
"Program:exit"(node) {
|
|
3004
|
-
const components =
|
|
2942
|
+
const components = [
|
|
2943
|
+
...ctx.getAllComponents(node).values()
|
|
2944
|
+
];
|
|
3005
2945
|
function isFunctionComponent(block) {
|
|
3006
2946
|
if (!AST11__namespace.isFunction(block)) {
|
|
3007
2947
|
return false;
|
|
3008
2948
|
}
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
(id) => core.isComponentName(id.name) && components.some((component) => component.node === block)
|
|
3012
|
-
);
|
|
2949
|
+
const id = AST11__namespace.getFunctionIdentifier(block);
|
|
2950
|
+
return !!id && core.isComponentName(id.name) && components.some((component) => component.node === block);
|
|
3013
2951
|
}
|
|
3014
2952
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3015
2953
|
let scope = initialScope;
|
|
@@ -3138,7 +3076,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3138
3076
|
...listeners,
|
|
3139
3077
|
"Program:exit"(node) {
|
|
3140
3078
|
const components = ctx.getAllComponents(node);
|
|
3141
|
-
for (const [
|
|
3079
|
+
for (const [, component] of components) {
|
|
3142
3080
|
const [props] = component.node.params;
|
|
3143
3081
|
if (props == null) {
|
|
3144
3082
|
continue;
|
|
@@ -3174,24 +3112,23 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3174
3112
|
},
|
|
3175
3113
|
name: RULE_NAME48,
|
|
3176
3114
|
create(context) {
|
|
3177
|
-
function getReportDescriptor(node) {
|
|
3178
|
-
const { value } = node;
|
|
3179
|
-
const propName = JSX7__namespace.getPropName(node);
|
|
3180
|
-
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3181
|
-
if (!hasValueTrue) {
|
|
3182
|
-
return eff.O.none();
|
|
3183
|
-
}
|
|
3184
|
-
return eff.O.some({
|
|
3185
|
-
messageId: "preferShorthandBoolean",
|
|
3186
|
-
node,
|
|
3187
|
-
data: {
|
|
3188
|
-
propName
|
|
3189
|
-
},
|
|
3190
|
-
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3191
|
-
});
|
|
3192
|
-
}
|
|
3193
3115
|
return {
|
|
3194
|
-
JSXAttribute
|
|
3116
|
+
JSXAttribute(node) {
|
|
3117
|
+
const { value } = node;
|
|
3118
|
+
const propName = JSX7__namespace.getPropName(node);
|
|
3119
|
+
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3120
|
+
if (!hasValueTrue) {
|
|
3121
|
+
return;
|
|
3122
|
+
}
|
|
3123
|
+
context.report({
|
|
3124
|
+
messageId: "preferShorthandBoolean",
|
|
3125
|
+
node,
|
|
3126
|
+
data: {
|
|
3127
|
+
propName
|
|
3128
|
+
},
|
|
3129
|
+
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3195
3132
|
};
|
|
3196
3133
|
},
|
|
3197
3134
|
defaultOptions: []
|
|
@@ -3216,31 +3153,32 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3216
3153
|
},
|
|
3217
3154
|
name: RULE_NAME49,
|
|
3218
3155
|
create(context) {
|
|
3219
|
-
function getReportDescriptor(node) {
|
|
3220
|
-
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3221
|
-
return eff.O.none();
|
|
3222
|
-
}
|
|
3223
|
-
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3224
|
-
if (hasAttributes) {
|
|
3225
|
-
return eff.O.none();
|
|
3226
|
-
}
|
|
3227
|
-
return eff.O.some({
|
|
3228
|
-
messageId: "preferShorthandFragment",
|
|
3229
|
-
node,
|
|
3230
|
-
fix: (fixer) => {
|
|
3231
|
-
const { closingElement, openingElement } = node;
|
|
3232
|
-
if (closingElement == null) {
|
|
3233
|
-
return [];
|
|
3234
|
-
}
|
|
3235
|
-
return [
|
|
3236
|
-
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3237
|
-
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3238
|
-
];
|
|
3239
|
-
}
|
|
3240
|
-
});
|
|
3241
|
-
}
|
|
3242
3156
|
return {
|
|
3243
|
-
JSXElement
|
|
3157
|
+
JSXElement(node) {
|
|
3158
|
+
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3159
|
+
return;
|
|
3160
|
+
}
|
|
3161
|
+
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3162
|
+
if (hasAttributes) {
|
|
3163
|
+
return;
|
|
3164
|
+
}
|
|
3165
|
+
context.report({
|
|
3166
|
+
messageId: "preferShorthandFragment",
|
|
3167
|
+
node,
|
|
3168
|
+
fix: (fixer) => {
|
|
3169
|
+
const { closingElement, openingElement } = node;
|
|
3170
|
+
if (closingElement == null) {
|
|
3171
|
+
return [];
|
|
3172
|
+
}
|
|
3173
|
+
return [
|
|
3174
|
+
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3175
|
+
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3176
|
+
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3177
|
+
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3178
|
+
];
|
|
3179
|
+
}
|
|
3180
|
+
});
|
|
3181
|
+
}
|
|
3244
3182
|
};
|
|
3245
3183
|
},
|
|
3246
3184
|
defaultOptions: []
|
|
@@ -3262,23 +3200,23 @@ var use_jsx_vars_default = createRule({
|
|
|
3262
3200
|
},
|
|
3263
3201
|
name: RULE_NAME50,
|
|
3264
3202
|
create(context) {
|
|
3265
|
-
function getName5(node) {
|
|
3266
|
-
switch (node.type) {
|
|
3267
|
-
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
3268
|
-
return eff.O.some(node.name);
|
|
3269
|
-
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
3270
|
-
return getName5(node.object);
|
|
3271
|
-
default:
|
|
3272
|
-
return eff.O.none();
|
|
3273
|
-
}
|
|
3274
|
-
}
|
|
3275
3203
|
return {
|
|
3276
3204
|
JSXOpeningElement(node) {
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3205
|
+
switch (node.name.type) {
|
|
3206
|
+
case types.AST_NODE_TYPES.JSXIdentifier: {
|
|
3207
|
+
if (/^[a-z]/u.test(node.name.name)) {
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
context.sourceCode.markVariableAsUsed(node.name.name, node);
|
|
3211
|
+
break;
|
|
3212
|
+
}
|
|
3213
|
+
case types.AST_NODE_TYPES.JSXMemberExpression: {
|
|
3214
|
+
const { object } = node.name;
|
|
3215
|
+
if (object.type === types.AST_NODE_TYPES.JSXIdentifier) {
|
|
3216
|
+
context.sourceCode.markVariableAsUsed(object.name, node);
|
|
3217
|
+
}
|
|
3218
|
+
break;
|
|
3219
|
+
}
|
|
3282
3220
|
}
|
|
3283
3221
|
}
|
|
3284
3222
|
};
|