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.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-beta.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"
|
|
@@ -1866,16 +1852,15 @@ var no_nested_components_default = createRule({
|
|
|
1866
1852
|
const isClassComponent11 = (node2) => {
|
|
1867
1853
|
return AST11__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1868
1854
|
};
|
|
1869
|
-
for (const { name:
|
|
1855
|
+
for (const { name: name2, node: component } of functionComponents) {
|
|
1870
1856
|
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
1871
1857
|
continue;
|
|
1872
1858
|
}
|
|
1873
|
-
if (eff.
|
|
1859
|
+
if (name2 === eff._) {
|
|
1874
1860
|
continue;
|
|
1875
1861
|
}
|
|
1876
|
-
const name2 = componentName.value;
|
|
1877
1862
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1878
|
-
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);
|
|
1879
1864
|
if (isInsideJSXPropValue) {
|
|
1880
1865
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1881
1866
|
context.report({
|
|
@@ -1898,13 +1883,8 @@ var no_nested_components_default = createRule({
|
|
|
1898
1883
|
});
|
|
1899
1884
|
continue;
|
|
1900
1885
|
}
|
|
1901
|
-
const
|
|
1902
|
-
|
|
1903
|
-
component,
|
|
1904
|
-
isFunctionComponent
|
|
1905
|
-
),
|
|
1906
|
-
eff.not(core.isDirectValueOfRenderPropertyLoose)
|
|
1907
|
-
);
|
|
1886
|
+
const parentComponent = AST11__namespace.findParentNodeGuard(component, isFunctionComponent);
|
|
1887
|
+
const isParnetComponentNotDirectValueOfRenderProperty = !!parentComponent && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1908
1888
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1909
1889
|
context.report({
|
|
1910
1890
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
@@ -1925,15 +1905,15 @@ var no_nested_components_default = createRule({
|
|
|
1925
1905
|
});
|
|
1926
1906
|
}
|
|
1927
1907
|
}
|
|
1928
|
-
for (const { name: name2, node: component } of classComponents) {
|
|
1929
|
-
if (
|
|
1908
|
+
for (const { name: name2 = "unknown", node: component } of classComponents) {
|
|
1909
|
+
if (!AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n))) {
|
|
1930
1910
|
continue;
|
|
1931
1911
|
}
|
|
1932
1912
|
context.report({
|
|
1933
1913
|
messageId: "nestedComponent",
|
|
1934
1914
|
node: component,
|
|
1935
1915
|
data: {
|
|
1936
|
-
name:
|
|
1916
|
+
name: name2
|
|
1937
1917
|
}
|
|
1938
1918
|
});
|
|
1939
1919
|
}
|
|
@@ -1978,15 +1958,11 @@ var no_prop_types_default = createRule({
|
|
|
1978
1958
|
if (!core.isComponentName(object.name)) {
|
|
1979
1959
|
return;
|
|
1980
1960
|
}
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
);
|
|
1986
|
-
if (!isComponent) {
|
|
1987
|
-
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 });
|
|
1988
1965
|
}
|
|
1989
|
-
context.report({ messageId: "noPropTypes", node: property });
|
|
1990
1966
|
},
|
|
1991
1967
|
PropertyDefinition(node) {
|
|
1992
1968
|
if (!core.isClassComponent(node.parent.parent)) {
|
|
@@ -2030,7 +2006,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2030
2006
|
...listeners,
|
|
2031
2007
|
"Program:exit"(node) {
|
|
2032
2008
|
const components = ctx.getAllComponents(node);
|
|
2033
|
-
for (const { name: name2, node: component, flag } of components.values()) {
|
|
2009
|
+
for (const { name: name2 = "PureComponent", node: component, flag } of components.values()) {
|
|
2034
2010
|
if ((flag & core.ERClassComponentFlag.PureComponent) === 0n) {
|
|
2035
2011
|
continue;
|
|
2036
2012
|
}
|
|
@@ -2041,7 +2017,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2041
2017
|
messageId: "noRedundantShouldComponentUpdate",
|
|
2042
2018
|
node: member,
|
|
2043
2019
|
data: {
|
|
2044
|
-
componentName:
|
|
2020
|
+
componentName: name2
|
|
2045
2021
|
}
|
|
2046
2022
|
});
|
|
2047
2023
|
}
|
|
@@ -2076,32 +2052,22 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2076
2052
|
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2077
2053
|
return {};
|
|
2078
2054
|
}
|
|
2079
|
-
function getReportDescriptor(node) {
|
|
2080
|
-
if (!core.isThisSetState(node)) {
|
|
2081
|
-
return eff.O.none();
|
|
2082
|
-
}
|
|
2083
|
-
return eff.F.pipe(
|
|
2084
|
-
eff.O.Do,
|
|
2085
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2086
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentDidMount)),
|
|
2087
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2088
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2089
|
-
eff.O.filter(
|
|
2090
|
-
({
|
|
2091
|
-
clazz,
|
|
2092
|
-
method,
|
|
2093
|
-
methodScope,
|
|
2094
|
-
upperScope
|
|
2095
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2096
|
-
),
|
|
2097
|
-
eff.O.map(() => ({
|
|
2098
|
-
messageId: "noSetStateInComponentDidMount",
|
|
2099
|
-
node
|
|
2100
|
-
}))
|
|
2101
|
-
);
|
|
2102
|
-
}
|
|
2103
2055
|
return {
|
|
2104
|
-
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
|
+
}
|
|
2105
2071
|
};
|
|
2106
2072
|
},
|
|
2107
2073
|
defaultOptions: []
|
|
@@ -2130,32 +2096,22 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2130
2096
|
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2131
2097
|
return {};
|
|
2132
2098
|
}
|
|
2133
|
-
function getReportDescriptor(node) {
|
|
2134
|
-
if (!core.isThisSetState(node)) {
|
|
2135
|
-
return eff.O.none();
|
|
2136
|
-
}
|
|
2137
|
-
return eff.F.pipe(
|
|
2138
|
-
eff.O.Do,
|
|
2139
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2140
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentDidUpdate)),
|
|
2141
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2142
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2143
|
-
eff.O.filter(
|
|
2144
|
-
({
|
|
2145
|
-
clazz,
|
|
2146
|
-
method,
|
|
2147
|
-
methodScope,
|
|
2148
|
-
upperScope
|
|
2149
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2150
|
-
),
|
|
2151
|
-
eff.O.map(() => ({
|
|
2152
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
2153
|
-
node
|
|
2154
|
-
}))
|
|
2155
|
-
);
|
|
2156
|
-
}
|
|
2157
2099
|
return {
|
|
2158
|
-
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
|
+
}
|
|
2159
2115
|
};
|
|
2160
2116
|
},
|
|
2161
2117
|
defaultOptions: []
|
|
@@ -2184,32 +2140,22 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2184
2140
|
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2185
2141
|
return {};
|
|
2186
2142
|
}
|
|
2187
|
-
function getReportDescriptor(node) {
|
|
2188
|
-
if (!core.isThisSetState(node)) {
|
|
2189
|
-
return eff.O.none();
|
|
2190
|
-
}
|
|
2191
|
-
return eff.F.pipe(
|
|
2192
|
-
eff.O.Do,
|
|
2193
|
-
eff.O.bind("clazz", () => AST11__namespace.findParentNodeGuard(node, core.isClassComponent)),
|
|
2194
|
-
eff.O.bind("method", ({ clazz }) => AST11__namespace.findParentNodeStop(node, clazz, isComponentWillUpdate3)),
|
|
2195
|
-
eff.O.bind("methodScope", ({ method }) => eff.O.some(context.sourceCode.getScope(method))),
|
|
2196
|
-
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
2197
|
-
eff.O.filter(
|
|
2198
|
-
({
|
|
2199
|
-
clazz,
|
|
2200
|
-
method,
|
|
2201
|
-
methodScope,
|
|
2202
|
-
upperScope
|
|
2203
|
-
}) => method.parent === clazz.body && upperScope === methodScope
|
|
2204
|
-
),
|
|
2205
|
-
eff.O.map(() => ({
|
|
2206
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
2207
|
-
node
|
|
2208
|
-
}))
|
|
2209
|
-
);
|
|
2210
|
-
}
|
|
2211
2143
|
return {
|
|
2212
|
-
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
|
+
}
|
|
2213
2159
|
};
|
|
2214
2160
|
},
|
|
2215
2161
|
defaultOptions: []
|
|
@@ -2219,14 +2165,14 @@ var RULE_FEATURES36 = [
|
|
|
2219
2165
|
"CHK"
|
|
2220
2166
|
];
|
|
2221
2167
|
function containsStringLiteral({ value }) {
|
|
2222
|
-
return value?.type === types.AST_NODE_TYPES.Literal &&
|
|
2168
|
+
return value?.type === types.AST_NODE_TYPES.Literal && typeof value.value === "string";
|
|
2223
2169
|
}
|
|
2224
2170
|
function containsStringExpressionContainer({ value }) {
|
|
2225
2171
|
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2226
2172
|
return false;
|
|
2227
2173
|
}
|
|
2228
2174
|
if (value.expression.type === types.AST_NODE_TYPES.Literal) {
|
|
2229
|
-
return
|
|
2175
|
+
return typeof value.expression.value === "string";
|
|
2230
2176
|
}
|
|
2231
2177
|
return value.expression.type === types.AST_NODE_TYPES.TemplateLiteral;
|
|
2232
2178
|
}
|
|
@@ -2427,39 +2373,28 @@ var no_unstable_context_value_default = createRule({
|
|
|
2427
2373
|
if (openingElementName.property.name !== "Provider") {
|
|
2428
2374
|
return;
|
|
2429
2375
|
}
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
node.attributes.find((attribute) => {
|
|
2435
|
-
return attribute.type === types.AST_NODE_TYPES.JSXAttribute && attribute.name.name === "value";
|
|
2436
|
-
})
|
|
2437
|
-
)),
|
|
2438
|
-
eff.O.bind("value", ({ attribute }) => "value" in attribute ? eff.O.some(attribute.value) : eff.O.none()),
|
|
2439
|
-
eff.O.bind("valueExpression", ({ value }) => value?.type === types.AST_NODE_TYPES.JSXExpressionContainer ? eff.O.some(value.expression) : eff.O.none()),
|
|
2440
|
-
eff.O.bind("construction", ({ valueExpression }) => {
|
|
2441
|
-
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2442
|
-
return eff.O.some(VAR__namespace.getValueConstruction(valueExpression, initialScope));
|
|
2443
|
-
}),
|
|
2444
|
-
eff.O.map((vc) => {
|
|
2445
|
-
if (vc.construction.kind === "None") {
|
|
2446
|
-
return;
|
|
2447
|
-
}
|
|
2448
|
-
if (core.isReactHookCall(vc.construction.node)) {
|
|
2449
|
-
return;
|
|
2450
|
-
}
|
|
2451
|
-
const prevs = constructions.get(vc.function.node) ?? [];
|
|
2452
|
-
constructions.set(vc.function.node, [...prevs, vc.construction]);
|
|
2453
|
-
})
|
|
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"
|
|
2454
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]);
|
|
2455
2393
|
},
|
|
2456
2394
|
"Program:exit"(node) {
|
|
2457
2395
|
const components = ctx.getAllComponents(node).values();
|
|
2458
2396
|
for (const { node: component } of components) {
|
|
2459
2397
|
for (const construction of constructions.get(component) ?? []) {
|
|
2460
|
-
if (construction.kind === "None") {
|
|
2461
|
-
continue;
|
|
2462
|
-
}
|
|
2463
2398
|
const { kind, node: constructionNode } = construction;
|
|
2464
2399
|
const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
2465
2400
|
context.report({
|
|
@@ -2521,7 +2456,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2521
2456
|
initialScope,
|
|
2522
2457
|
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2523
2458
|
);
|
|
2524
|
-
if (construction
|
|
2459
|
+
if (construction === eff._) {
|
|
2525
2460
|
continue;
|
|
2526
2461
|
}
|
|
2527
2462
|
if (core.isReactHookCall(construction.node)) {
|
|
@@ -2539,13 +2474,10 @@ var no_unstable_default_props_default = createRule({
|
|
|
2539
2474
|
}
|
|
2540
2475
|
},
|
|
2541
2476
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2542
|
-
const
|
|
2543
|
-
if (
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
const entry = mbEntry.value;
|
|
2547
|
-
const prevs = declarators.get(entry.node) ?? [];
|
|
2548
|
-
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]);
|
|
2549
2481
|
}
|
|
2550
2482
|
};
|
|
2551
2483
|
},
|
|
@@ -2577,15 +2509,15 @@ function getName3(node) {
|
|
|
2577
2509
|
return getName3(node.expression);
|
|
2578
2510
|
}
|
|
2579
2511
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2580
|
-
return
|
|
2512
|
+
return node.name;
|
|
2581
2513
|
}
|
|
2582
2514
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2583
|
-
return
|
|
2515
|
+
return node.value?.toString();
|
|
2584
2516
|
}
|
|
2585
2517
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2586
|
-
return
|
|
2518
|
+
return node.quasis[0]?.value.raw;
|
|
2587
2519
|
}
|
|
2588
|
-
return eff.
|
|
2520
|
+
return eff._;
|
|
2589
2521
|
}
|
|
2590
2522
|
var no_unused_class_component_members_default = createRule({
|
|
2591
2523
|
meta: {
|
|
@@ -2601,12 +2533,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2601
2533
|
},
|
|
2602
2534
|
name: RULE_NAME42,
|
|
2603
2535
|
create(context) {
|
|
2604
|
-
const
|
|
2605
|
-
const
|
|
2536
|
+
const classEntries = [];
|
|
2537
|
+
const methodEntries = [];
|
|
2606
2538
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
2607
2539
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2608
2540
|
function classEnter(node) {
|
|
2609
|
-
|
|
2541
|
+
classEntries.push(node);
|
|
2610
2542
|
if (!core.isClassComponent(node)) {
|
|
2611
2543
|
return;
|
|
2612
2544
|
}
|
|
@@ -2614,37 +2546,37 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2614
2546
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2615
2547
|
}
|
|
2616
2548
|
function classExit() {
|
|
2617
|
-
const currentClass =
|
|
2549
|
+
const currentClass = classEntries.pop();
|
|
2618
2550
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2619
2551
|
return;
|
|
2620
2552
|
}
|
|
2621
|
-
const className =
|
|
2553
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2622
2554
|
const defs = propertyDefs.get(currentClass);
|
|
2623
2555
|
const usages = propertyUsages.get(currentClass);
|
|
2624
2556
|
if (defs == null) {
|
|
2625
2557
|
return;
|
|
2626
2558
|
}
|
|
2627
2559
|
for (const def of defs) {
|
|
2628
|
-
const
|
|
2629
|
-
if (
|
|
2560
|
+
const methodName = getName3(def);
|
|
2561
|
+
if (methodName == null) {
|
|
2630
2562
|
continue;
|
|
2631
2563
|
}
|
|
2632
|
-
if (usages?.has(
|
|
2564
|
+
if (usages?.has(methodName) || LIFECYCLE_METHODS.has(methodName)) {
|
|
2633
2565
|
continue;
|
|
2634
2566
|
}
|
|
2635
2567
|
context.report({
|
|
2636
2568
|
messageId: "noUnusedClassComponentMembers",
|
|
2637
2569
|
node: def,
|
|
2638
2570
|
data: {
|
|
2639
|
-
className:
|
|
2640
|
-
methodName
|
|
2571
|
+
className: className ?? "Component",
|
|
2572
|
+
methodName
|
|
2641
2573
|
}
|
|
2642
2574
|
});
|
|
2643
2575
|
}
|
|
2644
2576
|
}
|
|
2645
2577
|
function methodEnter(node) {
|
|
2646
|
-
|
|
2647
|
-
const currentClass =
|
|
2578
|
+
methodEntries.push(node);
|
|
2579
|
+
const currentClass = classEntries.at(-1);
|
|
2648
2580
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2649
2581
|
return;
|
|
2650
2582
|
}
|
|
@@ -2656,7 +2588,7 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2656
2588
|
}
|
|
2657
2589
|
}
|
|
2658
2590
|
function methodExit() {
|
|
2659
|
-
|
|
2591
|
+
methodEntries.pop();
|
|
2660
2592
|
}
|
|
2661
2593
|
return {
|
|
2662
2594
|
ClassDeclaration: classEnter,
|
|
@@ -2664,8 +2596,8 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2664
2596
|
ClassExpression: classEnter,
|
|
2665
2597
|
"ClassExpression:exit": classExit,
|
|
2666
2598
|
MemberExpression(node) {
|
|
2667
|
-
const currentClass =
|
|
2668
|
-
const currentMethod =
|
|
2599
|
+
const currentClass = classEntries.at(-1);
|
|
2600
|
+
const currentMethod = methodEntries.at(-1);
|
|
2669
2601
|
if (currentClass == null || currentMethod == null) {
|
|
2670
2602
|
return;
|
|
2671
2603
|
}
|
|
@@ -2679,15 +2611,18 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2679
2611
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2680
2612
|
return;
|
|
2681
2613
|
}
|
|
2682
|
-
|
|
2614
|
+
const propertyName = getName3(node.property);
|
|
2615
|
+
if (propertyName != null) {
|
|
2616
|
+
propertyUsages.get(currentClass)?.add(propertyName);
|
|
2617
|
+
}
|
|
2683
2618
|
},
|
|
2684
2619
|
MethodDefinition: methodEnter,
|
|
2685
2620
|
"MethodDefinition:exit": methodExit,
|
|
2686
2621
|
PropertyDefinition: methodEnter,
|
|
2687
2622
|
"PropertyDefinition:exit": methodExit,
|
|
2688
2623
|
VariableDeclarator(node) {
|
|
2689
|
-
const currentClass =
|
|
2690
|
-
const currentMethod =
|
|
2624
|
+
const currentClass = classEntries.at(-1);
|
|
2625
|
+
const currentMethod = methodEntries.at(-1);
|
|
2691
2626
|
if (currentClass == null || currentMethod == null) {
|
|
2692
2627
|
return;
|
|
2693
2628
|
}
|
|
@@ -2697,10 +2632,9 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2697
2632
|
if (node.init != null && AST11__namespace.isThisExpression(node.init) && node.id.type === types.AST_NODE_TYPES.ObjectPattern) {
|
|
2698
2633
|
for (const prop of node.id.properties) {
|
|
2699
2634
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2700
|
-
const
|
|
2701
|
-
if (
|
|
2702
|
-
|
|
2703
|
-
propertyUsages.get(currentClass)?.add(name2);
|
|
2635
|
+
const keyName = getName3(prop.key);
|
|
2636
|
+
if (keyName != null) {
|
|
2637
|
+
propertyUsages.get(currentClass)?.add(keyName);
|
|
2704
2638
|
}
|
|
2705
2639
|
}
|
|
2706
2640
|
}
|
|
@@ -2719,19 +2653,19 @@ function getName4(node) {
|
|
|
2719
2653
|
return getName4(node.expression);
|
|
2720
2654
|
}
|
|
2721
2655
|
if (node.type === types.AST_NODE_TYPES.Identifier || node.type === types.AST_NODE_TYPES.PrivateIdentifier) {
|
|
2722
|
-
return
|
|
2656
|
+
return node.name;
|
|
2723
2657
|
}
|
|
2724
2658
|
if (node.type === types.AST_NODE_TYPES.Literal) {
|
|
2725
|
-
return
|
|
2659
|
+
return String(node.value);
|
|
2726
2660
|
}
|
|
2727
2661
|
if (node.type === types.AST_NODE_TYPES.TemplateLiteral && node.expressions.length === 0) {
|
|
2728
|
-
return
|
|
2662
|
+
return node.quasis[0]?.value.raw;
|
|
2729
2663
|
}
|
|
2730
|
-
return eff.
|
|
2664
|
+
return eff._;
|
|
2731
2665
|
}
|
|
2732
2666
|
function isAssignmentToThisState2(node) {
|
|
2733
2667
|
const { left } = node;
|
|
2734
|
-
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";
|
|
2735
2669
|
}
|
|
2736
2670
|
var isGetDerivedStateFromProps = tsPattern.isMatching({
|
|
2737
2671
|
key: {
|
|
@@ -2756,72 +2690,72 @@ var no_unused_state_default = createRule({
|
|
|
2756
2690
|
},
|
|
2757
2691
|
name: RULE_NAME43,
|
|
2758
2692
|
create(context) {
|
|
2759
|
-
const
|
|
2760
|
-
const
|
|
2761
|
-
const
|
|
2693
|
+
const classEntries = [];
|
|
2694
|
+
const methodEntries = [];
|
|
2695
|
+
const constructorEntries = [];
|
|
2762
2696
|
const stateDefs = /* @__PURE__ */ new WeakMap();
|
|
2763
2697
|
function classEnter(node) {
|
|
2764
|
-
|
|
2698
|
+
classEntries.push(node);
|
|
2765
2699
|
}
|
|
2766
2700
|
function classExit() {
|
|
2767
|
-
const currentClass =
|
|
2701
|
+
const currentClass = classEntries.pop();
|
|
2768
2702
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2769
2703
|
return;
|
|
2770
2704
|
}
|
|
2771
|
-
const className =
|
|
2772
|
-
const
|
|
2773
|
-
if (
|
|
2705
|
+
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2706
|
+
const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
|
|
2707
|
+
if (!defNode || isUsed) {
|
|
2774
2708
|
return;
|
|
2775
2709
|
}
|
|
2776
2710
|
context.report({
|
|
2777
2711
|
messageId: "noUnusedState",
|
|
2778
|
-
node:
|
|
2712
|
+
node: defNode,
|
|
2779
2713
|
data: {
|
|
2780
|
-
className:
|
|
2714
|
+
className: className ?? "Component"
|
|
2781
2715
|
}
|
|
2782
2716
|
});
|
|
2783
2717
|
}
|
|
2784
2718
|
function methodEnter(node) {
|
|
2785
|
-
|
|
2786
|
-
const currentClass =
|
|
2719
|
+
methodEntries.push(node);
|
|
2720
|
+
const currentClass = classEntries.at(-1);
|
|
2787
2721
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2788
2722
|
return;
|
|
2789
2723
|
}
|
|
2790
2724
|
if (node.static) {
|
|
2791
2725
|
if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
|
|
2792
|
-
const
|
|
2793
|
-
stateDefs.set(currentClass,
|
|
2726
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2727
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2794
2728
|
}
|
|
2795
2729
|
return;
|
|
2796
2730
|
}
|
|
2797
|
-
if (
|
|
2798
|
-
stateDefs.set(currentClass,
|
|
2731
|
+
if (getName4(node.key) === "state") {
|
|
2732
|
+
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
2799
2733
|
}
|
|
2800
2734
|
}
|
|
2801
2735
|
function methodExit() {
|
|
2802
|
-
|
|
2736
|
+
methodEntries.pop();
|
|
2803
2737
|
}
|
|
2804
2738
|
function constructorEnter(node) {
|
|
2805
|
-
|
|
2739
|
+
constructorEntries.push(node);
|
|
2806
2740
|
}
|
|
2807
2741
|
function constructorExit() {
|
|
2808
|
-
|
|
2742
|
+
constructorEntries.pop();
|
|
2809
2743
|
}
|
|
2810
2744
|
return {
|
|
2811
2745
|
AssignmentExpression(node) {
|
|
2812
2746
|
if (!isAssignmentToThisState2(node)) {
|
|
2813
2747
|
return;
|
|
2814
2748
|
}
|
|
2815
|
-
const currentClass =
|
|
2749
|
+
const currentClass = classEntries.at(-1);
|
|
2816
2750
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2817
2751
|
return;
|
|
2818
2752
|
}
|
|
2819
|
-
const currentConstructor =
|
|
2753
|
+
const currentConstructor = constructorEntries.at(-1);
|
|
2820
2754
|
if (currentConstructor == null || !currentClass.body.body.includes(currentConstructor)) {
|
|
2821
2755
|
return;
|
|
2822
2756
|
}
|
|
2823
|
-
const
|
|
2824
|
-
stateDefs.set(currentClass,
|
|
2757
|
+
const isUsed = stateDefs.get(currentClass)?.isUsed ?? false;
|
|
2758
|
+
stateDefs.set(currentClass, { node: node.left, isUsed });
|
|
2825
2759
|
},
|
|
2826
2760
|
ClassDeclaration: classEnter,
|
|
2827
2761
|
"ClassDeclaration:exit": classExit,
|
|
@@ -2831,25 +2765,25 @@ var no_unused_state_default = createRule({
|
|
|
2831
2765
|
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
2832
2766
|
return;
|
|
2833
2767
|
}
|
|
2834
|
-
if (
|
|
2768
|
+
if (getName4(node.property) !== "state") {
|
|
2835
2769
|
return;
|
|
2836
2770
|
}
|
|
2837
|
-
const currentClass =
|
|
2771
|
+
const currentClass = classEntries.at(-1);
|
|
2838
2772
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2839
2773
|
return;
|
|
2840
2774
|
}
|
|
2841
|
-
const currentMethod =
|
|
2775
|
+
const currentMethod = methodEntries.at(-1);
|
|
2842
2776
|
if (currentMethod == null || currentMethod.static) {
|
|
2843
2777
|
return;
|
|
2844
2778
|
}
|
|
2845
|
-
if (currentMethod ===
|
|
2779
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2846
2780
|
return;
|
|
2847
2781
|
}
|
|
2848
2782
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2849
2783
|
return;
|
|
2850
2784
|
}
|
|
2851
|
-
const
|
|
2852
|
-
stateDefs.set(currentClass,
|
|
2785
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2786
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2853
2787
|
},
|
|
2854
2788
|
MethodDefinition: methodEnter,
|
|
2855
2789
|
"MethodDefinition:exit": methodExit,
|
|
@@ -2858,15 +2792,15 @@ var no_unused_state_default = createRule({
|
|
|
2858
2792
|
PropertyDefinition: methodEnter,
|
|
2859
2793
|
"PropertyDefinition:exit": methodExit,
|
|
2860
2794
|
VariableDeclarator(node) {
|
|
2861
|
-
const currentClass =
|
|
2795
|
+
const currentClass = classEntries.at(-1);
|
|
2862
2796
|
if (currentClass == null || !core.isClassComponent(currentClass)) {
|
|
2863
2797
|
return;
|
|
2864
2798
|
}
|
|
2865
|
-
const currentMethod =
|
|
2799
|
+
const currentMethod = methodEntries.at(-1);
|
|
2866
2800
|
if (currentMethod == null || currentMethod.static) {
|
|
2867
2801
|
return;
|
|
2868
2802
|
}
|
|
2869
|
-
if (currentMethod ===
|
|
2803
|
+
if (currentMethod === constructorEntries.at(-1)) {
|
|
2870
2804
|
return;
|
|
2871
2805
|
}
|
|
2872
2806
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
@@ -2877,15 +2811,15 @@ var no_unused_state_default = createRule({
|
|
|
2877
2811
|
}
|
|
2878
2812
|
const hasState = node.id.properties.some((prop) => {
|
|
2879
2813
|
if (prop.type === types.AST_NODE_TYPES.Property && AST11__namespace.isKeyLiteralLike(prop, prop.key)) {
|
|
2880
|
-
return
|
|
2814
|
+
return getName4(prop.key) === "state";
|
|
2881
2815
|
}
|
|
2882
2816
|
return false;
|
|
2883
2817
|
});
|
|
2884
2818
|
if (!hasState) {
|
|
2885
2819
|
return;
|
|
2886
2820
|
}
|
|
2887
|
-
const
|
|
2888
|
-
stateDefs.set(currentClass,
|
|
2821
|
+
const defNode = stateDefs.get(currentClass)?.node;
|
|
2822
|
+
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2889
2823
|
}
|
|
2890
2824
|
};
|
|
2891
2825
|
},
|
|
@@ -3012,10 +2946,8 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3012
2946
|
if (!AST11__namespace.isFunction(block)) {
|
|
3013
2947
|
return false;
|
|
3014
2948
|
}
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
(id) => core.isComponentName(id.name) && components.some((component) => component.node === block)
|
|
3018
|
-
);
|
|
2949
|
+
const id = AST11__namespace.getFunctionIdentifier(block);
|
|
2950
|
+
return !!id && core.isComponentName(id.name) && components.some((component) => component.node === block);
|
|
3019
2951
|
}
|
|
3020
2952
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3021
2953
|
let scope = initialScope;
|
|
@@ -3144,7 +3076,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3144
3076
|
...listeners,
|
|
3145
3077
|
"Program:exit"(node) {
|
|
3146
3078
|
const components = ctx.getAllComponents(node);
|
|
3147
|
-
for (const [
|
|
3079
|
+
for (const [, component] of components) {
|
|
3148
3080
|
const [props] = component.node.params;
|
|
3149
3081
|
if (props == null) {
|
|
3150
3082
|
continue;
|
|
@@ -3180,24 +3112,23 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3180
3112
|
},
|
|
3181
3113
|
name: RULE_NAME48,
|
|
3182
3114
|
create(context) {
|
|
3183
|
-
function getReportDescriptor(node) {
|
|
3184
|
-
const { value } = node;
|
|
3185
|
-
const propName = JSX7__namespace.getPropName(node);
|
|
3186
|
-
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3187
|
-
if (!hasValueTrue) {
|
|
3188
|
-
return eff.O.none();
|
|
3189
|
-
}
|
|
3190
|
-
return eff.O.some({
|
|
3191
|
-
messageId: "preferShorthandBoolean",
|
|
3192
|
-
node,
|
|
3193
|
-
data: {
|
|
3194
|
-
propName
|
|
3195
|
-
},
|
|
3196
|
-
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
3197
|
-
});
|
|
3198
|
-
}
|
|
3199
3115
|
return {
|
|
3200
|
-
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
|
+
}
|
|
3201
3132
|
};
|
|
3202
3133
|
},
|
|
3203
3134
|
defaultOptions: []
|
|
@@ -3222,31 +3153,32 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3222
3153
|
},
|
|
3223
3154
|
name: RULE_NAME49,
|
|
3224
3155
|
create(context) {
|
|
3225
|
-
function getReportDescriptor(node) {
|
|
3226
|
-
if (JSX7__namespace.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3227
|
-
return eff.O.none();
|
|
3228
|
-
}
|
|
3229
|
-
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3230
|
-
if (hasAttributes) {
|
|
3231
|
-
return eff.O.none();
|
|
3232
|
-
}
|
|
3233
|
-
return eff.O.some({
|
|
3234
|
-
messageId: "preferShorthandFragment",
|
|
3235
|
-
node,
|
|
3236
|
-
fix: (fixer) => {
|
|
3237
|
-
const { closingElement, openingElement } = node;
|
|
3238
|
-
if (closingElement == null) {
|
|
3239
|
-
return [];
|
|
3240
|
-
}
|
|
3241
|
-
return [
|
|
3242
|
-
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3243
|
-
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3244
|
-
];
|
|
3245
|
-
}
|
|
3246
|
-
});
|
|
3247
|
-
}
|
|
3248
3156
|
return {
|
|
3249
|
-
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
|
+
}
|
|
3250
3182
|
};
|
|
3251
3183
|
},
|
|
3252
3184
|
defaultOptions: []
|
|
@@ -3268,23 +3200,23 @@ var use_jsx_vars_default = createRule({
|
|
|
3268
3200
|
},
|
|
3269
3201
|
name: RULE_NAME50,
|
|
3270
3202
|
create(context) {
|
|
3271
|
-
function getName5(node) {
|
|
3272
|
-
switch (node.type) {
|
|
3273
|
-
case types.AST_NODE_TYPES.JSXIdentifier:
|
|
3274
|
-
return eff.O.some(node.name);
|
|
3275
|
-
case types.AST_NODE_TYPES.JSXMemberExpression:
|
|
3276
|
-
return getName5(node.object);
|
|
3277
|
-
default:
|
|
3278
|
-
return eff.O.none();
|
|
3279
|
-
}
|
|
3280
|
-
}
|
|
3281
3203
|
return {
|
|
3282
3204
|
JSXOpeningElement(node) {
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
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
|
+
}
|
|
3288
3220
|
}
|
|
3289
3221
|
}
|
|
3290
3222
|
};
|