eslint-plugin-react-x 1.23.2-next.6 → 1.23.3-beta.2
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 +524 -190
- package/dist/index.mjs +525 -191
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } fro
|
|
|
4
4
|
import * as AST11 from '@eslint-react/ast';
|
|
5
5
|
import { isForwardRefCall, isThisSetState, isClassComponent, isCreateElementCall, isCloneElementCall, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isInitializedFromReact } from '@eslint-react/core';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
|
-
import { isMatching,
|
|
7
|
+
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
9
9
|
import * as VAR from '@eslint-react/var';
|
|
10
10
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var name = "eslint-plugin-react-x";
|
|
18
|
-
var version = "1.23.
|
|
18
|
+
var version = "1.23.3-beta.2";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -105,11 +105,17 @@ var ensure_forward_ref_using_ref_default = createRule({
|
|
|
105
105
|
create(context) {
|
|
106
106
|
return {
|
|
107
107
|
CallExpression(node) {
|
|
108
|
-
if (!isForwardRefCall(node, context))
|
|
108
|
+
if (!isForwardRefCall(node, context)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
109
111
|
const [component] = node.arguments;
|
|
110
|
-
if (!component || !AST11.isFunction(component))
|
|
112
|
+
if (!component || !AST11.isFunction(component)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
111
115
|
const [_, ref] = component.params;
|
|
112
|
-
if (ref)
|
|
116
|
+
if (ref) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
113
119
|
context.report({
|
|
114
120
|
messageId: "ensureForwardRefUsingRef",
|
|
115
121
|
node: component
|
|
@@ -152,17 +158,23 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
152
158
|
},
|
|
153
159
|
name: RULE_NAME4,
|
|
154
160
|
create(context) {
|
|
155
|
-
if (!context.sourceCode.text.includes("setState"))
|
|
161
|
+
if (!context.sourceCode.text.includes("setState")) {
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
156
164
|
const classStack = [];
|
|
157
165
|
const methodStack = [];
|
|
158
166
|
const setStateStack = [];
|
|
159
167
|
return {
|
|
160
168
|
CallExpression(node) {
|
|
161
|
-
if (!isThisSetState(node))
|
|
169
|
+
if (!isThisSetState(node)) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
162
172
|
setStateStack.push([node, false]);
|
|
163
173
|
},
|
|
164
174
|
"CallExpression:exit"(node) {
|
|
165
|
-
if (!isThisSetState(node))
|
|
175
|
+
if (!isThisSetState(node)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
166
178
|
setStateStack.pop();
|
|
167
179
|
},
|
|
168
180
|
ClassDeclaration(node) {
|
|
@@ -178,14 +190,24 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
178
190
|
classStack.pop();
|
|
179
191
|
},
|
|
180
192
|
MemberExpression(node) {
|
|
181
|
-
if (!AST11.isThisExpression(node.object))
|
|
193
|
+
if (!AST11.isThisExpression(node.object)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
182
196
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
183
|
-
if (!currClass || !isComponent)
|
|
197
|
+
if (!currClass || !isComponent) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
184
200
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
185
|
-
if (!currMethod || isStatic)
|
|
201
|
+
if (!currMethod || isStatic) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
186
204
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
187
|
-
if (!setState || hasThisState)
|
|
188
|
-
|
|
205
|
+
if (!setState || hasThisState) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (!O.exists(getName(node.property), (name2) => name2 === "state")) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
189
211
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
190
212
|
},
|
|
191
213
|
MethodDefinition(node) {
|
|
@@ -202,19 +224,29 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
202
224
|
},
|
|
203
225
|
VariableDeclarator(node) {
|
|
204
226
|
const [currClass, isComponent] = classStack.at(-1) ?? [];
|
|
205
|
-
if (!currClass || !isComponent)
|
|
227
|
+
if (!currClass || !isComponent) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
206
230
|
const [currMethod, isStatic] = methodStack.at(-1) ?? [];
|
|
207
|
-
if (!currMethod || isStatic)
|
|
231
|
+
if (!currMethod || isStatic) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
208
234
|
const [setState, hasThisState] = setStateStack.at(-1) ?? [];
|
|
209
|
-
if (!setState || hasThisState)
|
|
210
|
-
|
|
235
|
+
if (!setState || hasThisState) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
211
241
|
const hasState = node.id.properties.some((prop) => {
|
|
212
242
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
213
243
|
return O.exists(getName(prop.key), (name2) => name2 === "state");
|
|
214
244
|
}
|
|
215
245
|
return false;
|
|
216
246
|
});
|
|
217
|
-
if (!hasState)
|
|
247
|
+
if (!hasState) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
218
250
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
219
251
|
}
|
|
220
252
|
};
|
|
@@ -259,9 +291,13 @@ function isUsingReactChildren(node, context) {
|
|
|
259
291
|
if (!("property" in callee) || !("object" in callee) || !("name" in callee.property)) {
|
|
260
292
|
return false;
|
|
261
293
|
}
|
|
262
|
-
if (!isReactChildrenMethod(callee.property.name))
|
|
294
|
+
if (!isReactChildrenMethod(callee.property.name)) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
263
297
|
const initialScope = context.sourceCode.getScope(node);
|
|
264
|
-
if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children")
|
|
298
|
+
if (callee.object.type === AST_NODE_TYPES.Identifier && callee.object.name === "Children") {
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
265
301
|
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
266
302
|
return isInitializedFromReact(callee.object.object.name, initialScope, settings.importSource);
|
|
267
303
|
}
|
|
@@ -269,19 +305,31 @@ function isUsingReactChildren(node, context) {
|
|
|
269
305
|
}
|
|
270
306
|
function getMapIndexParamName(node, context) {
|
|
271
307
|
const { callee } = node;
|
|
272
|
-
if (callee.type !== AST_NODE_TYPES.MemberExpression)
|
|
273
|
-
|
|
308
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
309
|
+
return O.none();
|
|
310
|
+
}
|
|
311
|
+
if (callee.property.type !== AST_NODE_TYPES.Identifier) {
|
|
312
|
+
return O.none();
|
|
313
|
+
}
|
|
274
314
|
const { name: name2 } = callee.property;
|
|
275
|
-
if (!iteratorFunctionIndexParamPosition.has(name2))
|
|
315
|
+
if (!iteratorFunctionIndexParamPosition.has(name2)) {
|
|
316
|
+
return O.none();
|
|
317
|
+
}
|
|
276
318
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
277
|
-
if (!callbackArg)
|
|
319
|
+
if (!callbackArg) {
|
|
320
|
+
return O.none();
|
|
321
|
+
}
|
|
278
322
|
if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
279
323
|
return O.none();
|
|
280
324
|
}
|
|
281
325
|
const { params } = callbackArg;
|
|
282
326
|
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name2);
|
|
283
|
-
if (isNullable(indexParamPosition))
|
|
284
|
-
|
|
327
|
+
if (isNullable(indexParamPosition)) {
|
|
328
|
+
return O.none();
|
|
329
|
+
}
|
|
330
|
+
if (params.length < indexParamPosition + 1) {
|
|
331
|
+
return O.none();
|
|
332
|
+
}
|
|
285
333
|
const param = params.at(indexParamPosition);
|
|
286
334
|
return param && "name" in param ? O.some(param.name) : O.none();
|
|
287
335
|
}
|
|
@@ -305,16 +353,22 @@ var no_array_index_key_default = createRule({
|
|
|
305
353
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
|
|
306
354
|
}
|
|
307
355
|
function getReportDescriptor(node) {
|
|
308
|
-
if (isArrayIndex(node))
|
|
356
|
+
if (isArrayIndex(node)) {
|
|
357
|
+
return [{ messageId: "noArrayIndexKey", node }];
|
|
358
|
+
}
|
|
309
359
|
if (AST11.isOneOf([AST_NODE_TYPES.TemplateLiteral, AST_NODE_TYPES.BinaryExpression])(node)) {
|
|
310
360
|
const exps = AST_NODE_TYPES.TemplateLiteral === node.type ? node.expressions : AST11.getIdentifiersFromBinaryExpression(node);
|
|
311
361
|
return exps.reduce((acc, exp) => {
|
|
312
|
-
if (isArrayIndex(exp))
|
|
362
|
+
if (isArrayIndex(exp)) {
|
|
363
|
+
return [...acc, { messageId: "noArrayIndexKey", node: exp }];
|
|
364
|
+
}
|
|
313
365
|
return acc;
|
|
314
366
|
}, []);
|
|
315
367
|
}
|
|
316
368
|
if (isToStringCall(node)) {
|
|
317
|
-
if (!("object" in node.callee && isArrayIndex(node.callee.object)))
|
|
369
|
+
if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
|
|
370
|
+
return [];
|
|
371
|
+
}
|
|
318
372
|
return [{ messageId: "noArrayIndexKey", node: node.callee.object }];
|
|
319
373
|
}
|
|
320
374
|
const isStringCall = isMatching({
|
|
@@ -326,20 +380,32 @@ var no_array_index_key_default = createRule({
|
|
|
326
380
|
}, node);
|
|
327
381
|
if (isStringCall) {
|
|
328
382
|
const [arg] = node.arguments;
|
|
329
|
-
if (arg && isArrayIndex(arg))
|
|
383
|
+
if (arg && isArrayIndex(arg)) {
|
|
384
|
+
return [{ messageId: "noArrayIndexKey", node: arg }];
|
|
385
|
+
}
|
|
330
386
|
}
|
|
331
387
|
return [];
|
|
332
388
|
}
|
|
333
389
|
return {
|
|
334
390
|
CallExpression(node) {
|
|
335
391
|
indexParamNames.push(getMapIndexParamName(node, context));
|
|
336
|
-
if (node.arguments.length === 0)
|
|
337
|
-
|
|
392
|
+
if (node.arguments.length === 0) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!isCreateOrCloneElementCall(node)) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
338
398
|
const [_, props] = node.arguments;
|
|
339
|
-
if (props?.type !== AST_NODE_TYPES.ObjectExpression)
|
|
399
|
+
if (props?.type !== AST_NODE_TYPES.ObjectExpression) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
340
402
|
for (const prop of props.properties) {
|
|
341
|
-
if (!isMatching({ key: { name: "key" } })(prop))
|
|
342
|
-
|
|
403
|
+
if (!isMatching({ key: { name: "key" } })(prop)) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (!("value" in prop)) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
343
409
|
const descriptors = getReportDescriptor(prop.value);
|
|
344
410
|
for (const descriptor of descriptors) {
|
|
345
411
|
context.report(descriptor);
|
|
@@ -350,10 +416,16 @@ var no_array_index_key_default = createRule({
|
|
|
350
416
|
indexParamNames.pop();
|
|
351
417
|
},
|
|
352
418
|
JSXAttribute(node) {
|
|
353
|
-
if (node.name.name !== "key")
|
|
354
|
-
|
|
419
|
+
if (node.name.name !== "key") {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (indexParamNames.length === 0) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
355
425
|
const { value } = node;
|
|
356
|
-
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer)
|
|
426
|
+
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
357
429
|
const descriptors = getReportDescriptor(value.expression);
|
|
358
430
|
for (const descriptor of descriptors) {
|
|
359
431
|
context.report(descriptor);
|
|
@@ -551,22 +623,12 @@ var RULE_NAME12 = "no-class-component";
|
|
|
551
623
|
var RULE_FEATURES12 = [
|
|
552
624
|
"CHK"
|
|
553
625
|
];
|
|
554
|
-
|
|
555
|
-
key
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
static: false
|
|
561
|
-
});
|
|
562
|
-
var isGetDerivedStateFromError = isMatching({
|
|
563
|
-
key: {
|
|
564
|
-
type: AST_NODE_TYPES.Identifier,
|
|
565
|
-
name: "getDerivedStateFromError"
|
|
566
|
-
},
|
|
567
|
-
type: P.union(AST_NODE_TYPES.MethodDefinition, AST_NODE_TYPES.PropertyDefinition),
|
|
568
|
-
static: true
|
|
569
|
-
});
|
|
626
|
+
function isComponentDidCatch(node) {
|
|
627
|
+
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
628
|
+
}
|
|
629
|
+
function isGetDerivedStateFromError(node) {
|
|
630
|
+
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
631
|
+
}
|
|
570
632
|
var no_class_component_default = createRule({
|
|
571
633
|
meta: {
|
|
572
634
|
type: "problem",
|
|
@@ -581,14 +643,18 @@ var no_class_component_default = createRule({
|
|
|
581
643
|
},
|
|
582
644
|
name: RULE_NAME12,
|
|
583
645
|
create(context) {
|
|
584
|
-
if (!context.sourceCode.text.includes("Component"))
|
|
646
|
+
if (!context.sourceCode.text.includes("Component")) {
|
|
647
|
+
return {};
|
|
648
|
+
}
|
|
585
649
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
586
650
|
return {
|
|
587
651
|
...listeners,
|
|
588
652
|
"Program:exit"(node) {
|
|
589
653
|
const components = ctx.getAllComponents(node);
|
|
590
654
|
for (const { name: name2, node: component } of components.values()) {
|
|
591
|
-
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m)))
|
|
655
|
+
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
592
658
|
context.report({
|
|
593
659
|
messageId: "noClassComponent",
|
|
594
660
|
node: component,
|
|
@@ -623,7 +689,9 @@ var no_clone_element_default = createRule({
|
|
|
623
689
|
create(context) {
|
|
624
690
|
return {
|
|
625
691
|
CallExpression(node) {
|
|
626
|
-
if (!isCloneElementCall(node, context))
|
|
692
|
+
if (!isCloneElementCall(node, context)) {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
627
695
|
context.report({
|
|
628
696
|
messageId: "noCloneElement",
|
|
629
697
|
node
|
|
@@ -652,14 +720,22 @@ var no_comment_textnodes_default = createRule({
|
|
|
652
720
|
name: RULE_NAME14,
|
|
653
721
|
create(context) {
|
|
654
722
|
function hasCommentLike(node) {
|
|
655
|
-
if (AST11.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent))
|
|
723
|
+
if (AST11.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
656
726
|
const rawValue = context.sourceCode.getText(node);
|
|
657
727
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
658
728
|
}
|
|
659
729
|
const getReportDescriptor = (node) => {
|
|
660
|
-
if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent))
|
|
661
|
-
|
|
662
|
-
|
|
730
|
+
if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
731
|
+
return O.none();
|
|
732
|
+
}
|
|
733
|
+
if (!hasCommentLike(node)) {
|
|
734
|
+
return O.none();
|
|
735
|
+
}
|
|
736
|
+
if (!node.parent.type.includes("JSX")) {
|
|
737
|
+
return O.none();
|
|
738
|
+
}
|
|
663
739
|
return O.some({
|
|
664
740
|
messageId: "noCommentTextnodes",
|
|
665
741
|
node
|
|
@@ -693,11 +769,15 @@ var no_complex_conditional_rendering_default = createRule({
|
|
|
693
769
|
create(context) {
|
|
694
770
|
function getReportDescriptor(node) {
|
|
695
771
|
const jsxExpContainer = node.parent?.parent;
|
|
696
|
-
if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer))
|
|
772
|
+
if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
773
|
+
return O.none();
|
|
774
|
+
}
|
|
697
775
|
if (!AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
698
776
|
return O.none();
|
|
699
777
|
}
|
|
700
|
-
if (!jsxExpContainer.parent.children.includes(jsxExpContainer))
|
|
778
|
+
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
779
|
+
return O.none();
|
|
780
|
+
}
|
|
701
781
|
return O.some({ messageId: "noComplexConditionalRendering", node: jsxExpContainer });
|
|
702
782
|
}
|
|
703
783
|
const visitorFunction = F.flow(getReportDescriptor, O.map(context.report), F.constVoid);
|
|
@@ -734,7 +814,9 @@ var no_component_will_mount_default = createRule({
|
|
|
734
814
|
},
|
|
735
815
|
name: RULE_NAME16,
|
|
736
816
|
create(context) {
|
|
737
|
-
if (!context.sourceCode.text.includes("componentWillMount"))
|
|
817
|
+
if (!context.sourceCode.text.includes("componentWillMount")) {
|
|
818
|
+
return {};
|
|
819
|
+
}
|
|
738
820
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
739
821
|
return {
|
|
740
822
|
...listeners,
|
|
@@ -748,7 +830,9 @@ var no_component_will_mount_default = createRule({
|
|
|
748
830
|
messageId: "noComponentWillMount",
|
|
749
831
|
node: member,
|
|
750
832
|
fix(fixer) {
|
|
751
|
-
if (!("key" in member))
|
|
833
|
+
if (!("key" in member)) {
|
|
834
|
+
return null;
|
|
835
|
+
}
|
|
752
836
|
return fixer.replaceText(member.key, "UNSAFE_componentWillMount");
|
|
753
837
|
}
|
|
754
838
|
});
|
|
@@ -783,7 +867,9 @@ var no_component_will_receive_props_default = createRule({
|
|
|
783
867
|
},
|
|
784
868
|
name: RULE_NAME17,
|
|
785
869
|
create(context) {
|
|
786
|
-
if (!context.sourceCode.text.includes("componentWillReceiveProps"))
|
|
870
|
+
if (!context.sourceCode.text.includes("componentWillReceiveProps")) {
|
|
871
|
+
return {};
|
|
872
|
+
}
|
|
787
873
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
788
874
|
return {
|
|
789
875
|
...listeners,
|
|
@@ -797,7 +883,9 @@ var no_component_will_receive_props_default = createRule({
|
|
|
797
883
|
messageId: "noComponentWillReceiveProps",
|
|
798
884
|
node: member,
|
|
799
885
|
fix(fixer) {
|
|
800
|
-
if (!("key" in member))
|
|
886
|
+
if (!("key" in member)) {
|
|
887
|
+
return null;
|
|
888
|
+
}
|
|
801
889
|
return fixer.replaceText(member.key, "UNSAFE_componentWillReceiveProps");
|
|
802
890
|
}
|
|
803
891
|
});
|
|
@@ -832,7 +920,9 @@ var no_component_will_update_default = createRule({
|
|
|
832
920
|
},
|
|
833
921
|
name: RULE_NAME18,
|
|
834
922
|
create(context) {
|
|
835
|
-
if (!context.sourceCode.text.includes("componentWillUpdate"))
|
|
923
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
924
|
+
return {};
|
|
925
|
+
}
|
|
836
926
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
837
927
|
return {
|
|
838
928
|
...listeners,
|
|
@@ -846,7 +936,9 @@ var no_component_will_update_default = createRule({
|
|
|
846
936
|
messageId: "noComponentWillUpdate",
|
|
847
937
|
node: member,
|
|
848
938
|
fix(fixer) {
|
|
849
|
-
if (!("key" in member))
|
|
939
|
+
if (!("key" in member)) {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
850
942
|
return fixer.replaceText(member.key, "UNSAFE_componentWillUpdate");
|
|
851
943
|
}
|
|
852
944
|
});
|
|
@@ -878,13 +970,19 @@ var no_context_provider_default = createRule({
|
|
|
878
970
|
},
|
|
879
971
|
name: RULE_NAME19,
|
|
880
972
|
create(context) {
|
|
881
|
-
if (!context.sourceCode.text.includes(".Provider"))
|
|
973
|
+
if (!context.sourceCode.text.includes(".Provider")) {
|
|
974
|
+
return {};
|
|
975
|
+
}
|
|
882
976
|
const { version: version2 } = getSettingsFromContext(context);
|
|
883
|
-
if (compare(version2, "19.0.0", "<"))
|
|
977
|
+
if (compare(version2, "19.0.0", "<")) {
|
|
978
|
+
return {};
|
|
979
|
+
}
|
|
884
980
|
return {
|
|
885
981
|
JSXElement(node) {
|
|
886
982
|
const elementName = JSX7.getElementName(node.openingElement);
|
|
887
|
-
if (!elementName.endsWith(".Provider"))
|
|
983
|
+
if (!elementName.endsWith(".Provider")) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
888
986
|
context.report({
|
|
889
987
|
messageId: "noContextProvider",
|
|
890
988
|
node,
|
|
@@ -892,7 +990,9 @@ var no_context_provider_default = createRule({
|
|
|
892
990
|
const providerName = elementName.replace(/\.Provider$/, "");
|
|
893
991
|
const openingElement = node.openingElement;
|
|
894
992
|
const closingElement = node.closingElement;
|
|
895
|
-
if (!closingElement)
|
|
993
|
+
if (!closingElement) {
|
|
994
|
+
return fixer.replaceText(openingElement.name, providerName);
|
|
995
|
+
}
|
|
896
996
|
return [
|
|
897
997
|
fixer.replaceText(openingElement.name, providerName),
|
|
898
998
|
fixer.replaceText(closingElement.name, providerName)
|
|
@@ -924,8 +1024,12 @@ var no_create_ref_default = createRule({
|
|
|
924
1024
|
create(context) {
|
|
925
1025
|
return {
|
|
926
1026
|
CallExpression(node) {
|
|
927
|
-
if (!isCreateRefCall(node, context))
|
|
928
|
-
|
|
1027
|
+
if (!isCreateRefCall(node, context)) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
if (O.isSome(AST11.findParentNode(node, isClassComponent))) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
929
1033
|
context.report({ messageId: "noCreateRef", node });
|
|
930
1034
|
}
|
|
931
1035
|
};
|
|
@@ -950,25 +1054,41 @@ var no_default_props_default = createRule({
|
|
|
950
1054
|
},
|
|
951
1055
|
name: RULE_NAME21,
|
|
952
1056
|
create(context) {
|
|
953
|
-
if (!context.sourceCode.text.includes("defaultProps"))
|
|
1057
|
+
if (!context.sourceCode.text.includes("defaultProps")) {
|
|
1058
|
+
return {};
|
|
1059
|
+
}
|
|
954
1060
|
return {
|
|
955
1061
|
AssignmentExpression(node) {
|
|
956
|
-
if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression)
|
|
1062
|
+
if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
957
1065
|
const { object, property } = node.left;
|
|
958
|
-
if (object.type !== AST_NODE_TYPES.Identifier)
|
|
959
|
-
|
|
960
|
-
|
|
1066
|
+
if (object.type !== AST_NODE_TYPES.Identifier) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
if (!isComponentName(object.name)) {
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
961
1075
|
const isComponent = F.pipe(
|
|
962
1076
|
VAR.findVariable(object.name, context.sourceCode.getScope(node)),
|
|
963
1077
|
O.flatMap(VAR.getVariableNode(0)),
|
|
964
1078
|
O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
|
|
965
1079
|
);
|
|
966
|
-
if (!isComponent)
|
|
1080
|
+
if (!isComponent) {
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
967
1083
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
968
1084
|
},
|
|
969
1085
|
PropertyDefinition(node) {
|
|
970
|
-
if (!isClassComponent(node.parent.parent))
|
|
971
|
-
|
|
1086
|
+
if (!isClassComponent(node.parent.parent)) {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
972
1092
|
context.report({ messageId: "noDefaultProps", node });
|
|
973
1093
|
}
|
|
974
1094
|
};
|
|
@@ -1016,7 +1136,9 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1016
1136
|
name: RULE_NAME22,
|
|
1017
1137
|
create(context) {
|
|
1018
1138
|
function getReportDescriptor(node) {
|
|
1019
|
-
if (!isAssignmentToThisState(node))
|
|
1139
|
+
if (!isAssignmentToThisState(node)) {
|
|
1140
|
+
return O.none();
|
|
1141
|
+
}
|
|
1020
1142
|
return F.pipe(
|
|
1021
1143
|
O.Do,
|
|
1022
1144
|
O.bind("parentClass", () => AST11.findParentNodeGuard(
|
|
@@ -1064,9 +1186,13 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1064
1186
|
JSXOpeningElement(node) {
|
|
1065
1187
|
const props = [];
|
|
1066
1188
|
for (const attr of node.attributes) {
|
|
1067
|
-
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute)
|
|
1189
|
+
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1068
1192
|
const name2 = attr.name.name;
|
|
1069
|
-
if (!isString(name2))
|
|
1193
|
+
if (!isString(name2)) {
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1070
1196
|
if (!props.includes(name2)) {
|
|
1071
1197
|
props.push(name2);
|
|
1072
1198
|
continue;
|
|
@@ -1099,12 +1225,16 @@ var no_duplicate_key_default = createRule({
|
|
|
1099
1225
|
},
|
|
1100
1226
|
name: RULE_NAME24,
|
|
1101
1227
|
create(context) {
|
|
1102
|
-
if (!context.sourceCode.getText().includes("key="))
|
|
1228
|
+
if (!context.sourceCode.getText().includes("key=")) {
|
|
1229
|
+
return {};
|
|
1230
|
+
}
|
|
1103
1231
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1104
1232
|
function isKeyValueEqual(a, b) {
|
|
1105
1233
|
const aValue = a.value;
|
|
1106
1234
|
const bValue = b.value;
|
|
1107
|
-
if (aValue === null || bValue === null)
|
|
1235
|
+
if (aValue === null || bValue === null) {
|
|
1236
|
+
return false;
|
|
1237
|
+
}
|
|
1108
1238
|
return AST11.isNodeEqual(aValue, bValue);
|
|
1109
1239
|
}
|
|
1110
1240
|
return {
|
|
@@ -1130,9 +1260,13 @@ var no_duplicate_key_default = createRule({
|
|
|
1130
1260
|
O.bind("iter", ({ call: call2 }) => AST11.findParentNodeStop(jsxElement, call2, AST11.isFunction)),
|
|
1131
1261
|
O.bind("arg0", ({ call: call2 }) => O.fromNullable(call2.arguments[0]))
|
|
1132
1262
|
);
|
|
1133
|
-
if (O.isNone(mbEntry))
|
|
1263
|
+
if (O.isNone(mbEntry)) {
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1134
1266
|
const { arg0, call, iter } = mbEntry.value;
|
|
1135
|
-
if (AST11.unwrapTypeExpression(arg0) !== iter)
|
|
1267
|
+
if (AST11.unwrapTypeExpression(arg0) !== iter) {
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1136
1270
|
keyedEntries.set(call, {
|
|
1137
1271
|
hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
|
|
1138
1272
|
keys: [node],
|
|
@@ -1143,7 +1277,9 @@ var no_duplicate_key_default = createRule({
|
|
|
1143
1277
|
},
|
|
1144
1278
|
"Program:exit"() {
|
|
1145
1279
|
for (const { hasDuplicate, keys } of keyedEntries.values()) {
|
|
1146
|
-
if (!hasDuplicate)
|
|
1280
|
+
if (!hasDuplicate) {
|
|
1281
|
+
continue;
|
|
1282
|
+
}
|
|
1147
1283
|
for (const key of keys) {
|
|
1148
1284
|
context.report({
|
|
1149
1285
|
messageId: "noDuplicateKey",
|
|
@@ -1179,12 +1315,18 @@ var no_forward_ref_default = createRule({
|
|
|
1179
1315
|
},
|
|
1180
1316
|
name: RULE_NAME25,
|
|
1181
1317
|
create(context) {
|
|
1182
|
-
if (!context.sourceCode.text.includes("forwardRef"))
|
|
1318
|
+
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1319
|
+
return {};
|
|
1320
|
+
}
|
|
1183
1321
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1184
|
-
if (compare(version2, "19.0.0", "<"))
|
|
1322
|
+
if (compare(version2, "19.0.0", "<")) {
|
|
1323
|
+
return {};
|
|
1324
|
+
}
|
|
1185
1325
|
return {
|
|
1186
1326
|
CallExpression(node) {
|
|
1187
|
-
if (!isForwardRefCall(node, context))
|
|
1327
|
+
if (!isForwardRefCall(node, context)) {
|
|
1328
|
+
return;
|
|
1329
|
+
}
|
|
1188
1330
|
context.report({
|
|
1189
1331
|
messageId: "noForwardRef",
|
|
1190
1332
|
node,
|
|
@@ -1198,7 +1340,9 @@ var no_forward_ref_default = createRule({
|
|
|
1198
1340
|
function getFix(node, context) {
|
|
1199
1341
|
return (fixer) => {
|
|
1200
1342
|
const [componentNode] = node.arguments;
|
|
1201
|
-
if (!componentNode || !AST11.isFunction(componentNode))
|
|
1343
|
+
if (!componentNode || !AST11.isFunction(componentNode)) {
|
|
1344
|
+
return [];
|
|
1345
|
+
}
|
|
1202
1346
|
return [
|
|
1203
1347
|
// unwrap component from forwardRef call
|
|
1204
1348
|
fixer.removeRange([node.range[0], componentNode.range[0]]),
|
|
@@ -1217,10 +1361,14 @@ function getComponentPropsFixes(node, typeArguments, fixer, context) {
|
|
|
1217
1361
|
const getText = (node2) => context.sourceCode.getText(node2);
|
|
1218
1362
|
const [arg0, arg1] = node.params;
|
|
1219
1363
|
const [typeArg0, typeArg1] = typeArguments;
|
|
1220
|
-
if (!arg0)
|
|
1364
|
+
if (!arg0) {
|
|
1365
|
+
return [];
|
|
1366
|
+
}
|
|
1221
1367
|
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => O.some(`...${n.name}`)).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => O.some(n.properties.map(getText).join(", "))).otherwise(O.none);
|
|
1222
1368
|
const fixedArg1Text = match(arg1).with(P.nullish, () => O.some("ref")).with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => O.some("ref")).with({ type: AST_NODE_TYPES.Identifier, name: P.not("ref") }, (n) => O.some(`ref: ${n.name}`)).otherwise(O.none);
|
|
1223
|
-
if (O.isNone(fixedArg0Text) || O.isNone(fixedArg1Text))
|
|
1369
|
+
if (O.isNone(fixedArg0Text) || O.isNone(fixedArg1Text)) {
|
|
1370
|
+
return [];
|
|
1371
|
+
}
|
|
1224
1372
|
const fixedPropsText = fixedArg0Text.value;
|
|
1225
1373
|
const fixedRefText = fixedArg1Text.value;
|
|
1226
1374
|
if (!typeArg0 || !typeArg1) {
|
|
@@ -1400,7 +1548,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1400
1548
|
},
|
|
1401
1549
|
name: RULE_NAME27,
|
|
1402
1550
|
create(context) {
|
|
1403
|
-
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?"))
|
|
1551
|
+
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) {
|
|
1552
|
+
return {};
|
|
1553
|
+
}
|
|
1404
1554
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1405
1555
|
const allowedVariants = [
|
|
1406
1556
|
"any",
|
|
@@ -1418,7 +1568,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1418
1568
|
function getReportDescriptor(node) {
|
|
1419
1569
|
return match(node).when(AST11.isJSX, O.none).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1420
1570
|
const isLeftUnaryNot = isMatching({ type: AST_NODE_TYPES.UnaryExpression, operator: "!" }, left);
|
|
1421
|
-
if (isLeftUnaryNot)
|
|
1571
|
+
if (isLeftUnaryNot) {
|
|
1572
|
+
return getReportDescriptor(right);
|
|
1573
|
+
}
|
|
1422
1574
|
const initialScope = context.sourceCode.getScope(left);
|
|
1423
1575
|
const isLeftNan = isMatching({ type: AST_NODE_TYPES.Identifier, name: "NaN" }, left) || O.exists(VAR.getStaticValue(left, initialScope), (v) => v === "NaN");
|
|
1424
1576
|
if (isLeftNan) {
|
|
@@ -1431,7 +1583,9 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1431
1583
|
const leftType = getConstrainedTypeAtLocation(services, left);
|
|
1432
1584
|
const leftTypeVariants = inspectVariantTypes(unionTypeParts(leftType));
|
|
1433
1585
|
const isLeftValid = Array.from(leftTypeVariants.values()).every((type) => allowedVariants.some((allowed) => allowed === type));
|
|
1434
|
-
if (isLeftValid)
|
|
1586
|
+
if (isLeftValid) {
|
|
1587
|
+
return getReportDescriptor(right);
|
|
1588
|
+
}
|
|
1435
1589
|
return O.some({
|
|
1436
1590
|
messageId: "noLeakedConditionalRendering",
|
|
1437
1591
|
node: left,
|
|
@@ -1473,7 +1627,9 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1473
1627
|
},
|
|
1474
1628
|
name: RULE_NAME28,
|
|
1475
1629
|
create(context) {
|
|
1476
|
-
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef"))
|
|
1630
|
+
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1631
|
+
return {};
|
|
1632
|
+
}
|
|
1477
1633
|
const { ctx, listeners } = useComponentCollector(context);
|
|
1478
1634
|
return {
|
|
1479
1635
|
...listeners,
|
|
@@ -1481,8 +1637,12 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1481
1637
|
const components = ctx.getAllComponents(node);
|
|
1482
1638
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1483
1639
|
const isMemoOrForwardRef = Boolean(flag & ERFunctionComponentFlag.ForwardRef) || Boolean(flag & ERFunctionComponentFlag.Memo);
|
|
1484
|
-
if (O.isSome(AST11.getFunctionIdentifier(node2)))
|
|
1485
|
-
|
|
1640
|
+
if (O.isSome(AST11.getFunctionIdentifier(node2))) {
|
|
1641
|
+
continue;
|
|
1642
|
+
}
|
|
1643
|
+
if (!isMemoOrForwardRef) {
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1486
1646
|
if (O.isNone(displayName)) {
|
|
1487
1647
|
context.report({
|
|
1488
1648
|
messageId: "noMissingComponentDisplayName",
|
|
@@ -1540,13 +1700,17 @@ var no_missing_key_default = createRule({
|
|
|
1540
1700
|
function checkExpression(node) {
|
|
1541
1701
|
switch (node.type) {
|
|
1542
1702
|
case AST_NODE_TYPES.ConditionalExpression:
|
|
1543
|
-
if (!("consequent" in node))
|
|
1703
|
+
if (!("consequent" in node)) {
|
|
1704
|
+
return O.none();
|
|
1705
|
+
}
|
|
1544
1706
|
return O.orElse(checkIteratorElement(node.consequent), () => checkIteratorElement(node.alternate));
|
|
1545
1707
|
case AST_NODE_TYPES.JSXElement:
|
|
1546
1708
|
case AST_NODE_TYPES.JSXFragment:
|
|
1547
1709
|
return checkIteratorElement(node);
|
|
1548
1710
|
case AST_NODE_TYPES.LogicalExpression:
|
|
1549
|
-
if (!("left" in node))
|
|
1711
|
+
if (!("left" in node)) {
|
|
1712
|
+
return O.none();
|
|
1713
|
+
}
|
|
1550
1714
|
return O.orElse(checkIteratorElement(node.left), () => checkIteratorElement(node.right));
|
|
1551
1715
|
default:
|
|
1552
1716
|
return O.none();
|
|
@@ -1554,16 +1718,22 @@ var no_missing_key_default = createRule({
|
|
|
1554
1718
|
}
|
|
1555
1719
|
function checkBlockStatement(node) {
|
|
1556
1720
|
return AST11.getNestedReturnStatements(node).reduce((acc, statement) => {
|
|
1557
|
-
if (!statement.argument)
|
|
1721
|
+
if (!statement.argument) {
|
|
1722
|
+
return acc;
|
|
1723
|
+
}
|
|
1558
1724
|
const mbDescriptor = checkIteratorElement(statement.argument);
|
|
1559
1725
|
return O.isNone(mbDescriptor) ? acc : [...acc, mbDescriptor.value];
|
|
1560
1726
|
}, []);
|
|
1561
1727
|
}
|
|
1562
1728
|
return {
|
|
1563
1729
|
ArrayExpression(node) {
|
|
1564
|
-
if (state.isWithinChildrenToArray)
|
|
1730
|
+
if (state.isWithinChildrenToArray) {
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1565
1733
|
const elements = node.elements.filter(AST11.is(AST_NODE_TYPES.JSXElement));
|
|
1566
|
-
if (elements.length === 0)
|
|
1734
|
+
if (elements.length === 0) {
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1567
1737
|
const initialScope = context.sourceCode.getScope(node);
|
|
1568
1738
|
for (const element of elements) {
|
|
1569
1739
|
if (!JSX7.hasProp(element.openingElement.attributes, "key", initialScope)) {
|
|
@@ -1576,7 +1746,9 @@ var no_missing_key_default = createRule({
|
|
|
1576
1746
|
},
|
|
1577
1747
|
CallExpression(node) {
|
|
1578
1748
|
state.isWithinChildrenToArray ||= isChildrenToArrayCall(node, context);
|
|
1579
|
-
if (state.isWithinChildrenToArray)
|
|
1749
|
+
if (state.isWithinChildrenToArray) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1580
1752
|
const isMapCall = AST11.isMapCallLoose(node);
|
|
1581
1753
|
const isArrayFromCall = isMatching({
|
|
1582
1754
|
type: AST_NODE_TYPES.CallExpression,
|
|
@@ -1587,9 +1759,13 @@ var no_missing_key_default = createRule({
|
|
|
1587
1759
|
}
|
|
1588
1760
|
}
|
|
1589
1761
|
}, node);
|
|
1590
|
-
if (!isMapCall && !isArrayFromCall)
|
|
1762
|
+
if (!isMapCall && !isArrayFromCall) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1591
1765
|
const fn = node.arguments[isMapCall ? 0 : 1];
|
|
1592
|
-
if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn))
|
|
1766
|
+
if (!AST11.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(fn)) {
|
|
1767
|
+
return;
|
|
1768
|
+
}
|
|
1593
1769
|
if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
|
|
1594
1770
|
for (const descriptor of checkBlockStatement(fn.body)) {
|
|
1595
1771
|
context.report(descriptor);
|
|
@@ -1599,11 +1775,15 @@ var no_missing_key_default = createRule({
|
|
|
1599
1775
|
O.map(checkExpression(fn.body), context.report);
|
|
1600
1776
|
},
|
|
1601
1777
|
"CallExpression:exit"(node) {
|
|
1602
|
-
if (!isChildrenToArrayCall(node, context))
|
|
1778
|
+
if (!isChildrenToArrayCall(node, context)) {
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1603
1781
|
state.isWithinChildrenToArray = false;
|
|
1604
1782
|
},
|
|
1605
1783
|
JSXFragment(node) {
|
|
1606
|
-
if (state.isWithinChildrenToArray)
|
|
1784
|
+
if (state.isWithinChildrenToArray) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1607
1787
|
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) {
|
|
1608
1788
|
context.report({
|
|
1609
1789
|
messageId: "noMissingKeyWithFragment",
|
|
@@ -1634,7 +1814,7 @@ var no_nested_components_default = createRule({
|
|
|
1634
1814
|
},
|
|
1635
1815
|
name: RULE_NAME30,
|
|
1636
1816
|
create(context) {
|
|
1637
|
-
const hint = ERComponentHint.SkipMapCallback | ERComponentHint.SkipNullLiteral | ERComponentHint.
|
|
1817
|
+
const hint = ERComponentHint.SkipMapCallback | ERComponentHint.SkipNullLiteral | ERComponentHint.SkipUndefined | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipNumberLiteral | ERComponentHint.StrictLogical | ERComponentHint.StrictConditional;
|
|
1638
1818
|
const collector = useComponentCollector(context, hint);
|
|
1639
1819
|
const collectorLegacy = useComponentCollectorLegacy();
|
|
1640
1820
|
return {
|
|
@@ -1650,8 +1830,12 @@ var no_nested_components_default = createRule({
|
|
|
1650
1830
|
return AST11.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1651
1831
|
};
|
|
1652
1832
|
for (const { name: componentName, node: component } of functionComponents) {
|
|
1653
|
-
if (isDirectValueOfRenderPropertyLoose(component))
|
|
1654
|
-
|
|
1833
|
+
if (isDirectValueOfRenderPropertyLoose(component)) {
|
|
1834
|
+
continue;
|
|
1835
|
+
}
|
|
1836
|
+
if (O.isNone(componentName)) {
|
|
1837
|
+
continue;
|
|
1838
|
+
}
|
|
1655
1839
|
const name2 = componentName.value;
|
|
1656
1840
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1657
1841
|
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || O.isSome(JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer));
|
|
@@ -1739,25 +1923,41 @@ var no_prop_types_default = createRule({
|
|
|
1739
1923
|
},
|
|
1740
1924
|
name: RULE_NAME31,
|
|
1741
1925
|
create(context) {
|
|
1742
|
-
if (!context.sourceCode.text.includes("propTypes"))
|
|
1926
|
+
if (!context.sourceCode.text.includes("propTypes")) {
|
|
1927
|
+
return {};
|
|
1928
|
+
}
|
|
1743
1929
|
return {
|
|
1744
1930
|
AssignmentExpression(node) {
|
|
1745
|
-
if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression)
|
|
1931
|
+
if (node.operator !== "=" || node.left.type !== AST_NODE_TYPES.MemberExpression) {
|
|
1932
|
+
return;
|
|
1933
|
+
}
|
|
1746
1934
|
const { object, property } = node.left;
|
|
1747
|
-
if (object.type !== AST_NODE_TYPES.Identifier)
|
|
1748
|
-
|
|
1749
|
-
|
|
1935
|
+
if (object.type !== AST_NODE_TYPES.Identifier) {
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
if (!isComponentName(object.name)) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1750
1944
|
const isComponent = F.pipe(
|
|
1751
1945
|
VAR.findVariable(object.name, context.sourceCode.getScope(node)),
|
|
1752
1946
|
O.flatMap(VAR.getVariableNode(0)),
|
|
1753
1947
|
O.exists((n) => AST11.isFunction(n) || isClassComponent(n))
|
|
1754
1948
|
);
|
|
1755
|
-
if (!isComponent)
|
|
1949
|
+
if (!isComponent) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1756
1952
|
context.report({ messageId: "noPropTypes", node: property });
|
|
1757
1953
|
},
|
|
1758
1954
|
PropertyDefinition(node) {
|
|
1759
|
-
if (!isClassComponent(node.parent.parent))
|
|
1760
|
-
|
|
1955
|
+
if (!isClassComponent(node.parent.parent)) {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1761
1961
|
context.report({ messageId: "noPropTypes", node });
|
|
1762
1962
|
}
|
|
1763
1963
|
};
|
|
@@ -1785,14 +1985,18 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1785
1985
|
},
|
|
1786
1986
|
name: RULE_NAME32,
|
|
1787
1987
|
create(context) {
|
|
1788
|
-
if (!context.sourceCode.text.includes("shouldComponentUpdate"))
|
|
1988
|
+
if (!context.sourceCode.text.includes("shouldComponentUpdate")) {
|
|
1989
|
+
return {};
|
|
1990
|
+
}
|
|
1789
1991
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
1790
1992
|
return {
|
|
1791
1993
|
...listeners,
|
|
1792
1994
|
"Program:exit"(node) {
|
|
1793
1995
|
const components = ctx.getAllComponents(node);
|
|
1794
1996
|
for (const { name: name2, node: component, flag } of components.values()) {
|
|
1795
|
-
if (!(flag & ERClassComponentFlag.PureComponent))
|
|
1997
|
+
if (!(flag & ERClassComponentFlag.PureComponent)) {
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
1796
2000
|
const { body } = component.body;
|
|
1797
2001
|
for (const member of body) {
|
|
1798
2002
|
if (isShouldComponentUpdate(member)) {
|
|
@@ -1832,9 +2036,13 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1832
2036
|
},
|
|
1833
2037
|
name: RULE_NAME33,
|
|
1834
2038
|
create(context) {
|
|
1835
|
-
if (!context.sourceCode.text.includes("componentDidMount"))
|
|
2039
|
+
if (!context.sourceCode.text.includes("componentDidMount")) {
|
|
2040
|
+
return {};
|
|
2041
|
+
}
|
|
1836
2042
|
function getReportDescriptor(node) {
|
|
1837
|
-
if (!isThisSetState(node))
|
|
2043
|
+
if (!isThisSetState(node)) {
|
|
2044
|
+
return O.none();
|
|
2045
|
+
}
|
|
1838
2046
|
return F.pipe(
|
|
1839
2047
|
O.Do,
|
|
1840
2048
|
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
@@ -1882,9 +2090,13 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1882
2090
|
},
|
|
1883
2091
|
name: RULE_NAME34,
|
|
1884
2092
|
create(context) {
|
|
1885
|
-
if (!context.sourceCode.text.includes("componentDidUpdate"))
|
|
2093
|
+
if (!context.sourceCode.text.includes("componentDidUpdate")) {
|
|
2094
|
+
return {};
|
|
2095
|
+
}
|
|
1886
2096
|
function getReportDescriptor(node) {
|
|
1887
|
-
if (!isThisSetState(node))
|
|
2097
|
+
if (!isThisSetState(node)) {
|
|
2098
|
+
return O.none();
|
|
2099
|
+
}
|
|
1888
2100
|
return F.pipe(
|
|
1889
2101
|
O.Do,
|
|
1890
2102
|
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
@@ -1932,9 +2144,13 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1932
2144
|
},
|
|
1933
2145
|
name: RULE_NAME35,
|
|
1934
2146
|
create(context) {
|
|
1935
|
-
if (!context.sourceCode.text.includes("componentWillUpdate"))
|
|
2147
|
+
if (!context.sourceCode.text.includes("componentWillUpdate")) {
|
|
2148
|
+
return {};
|
|
2149
|
+
}
|
|
1936
2150
|
function getReportDescriptor(node) {
|
|
1937
|
-
if (!isThisSetState(node))
|
|
2151
|
+
if (!isThisSetState(node)) {
|
|
2152
|
+
return O.none();
|
|
2153
|
+
}
|
|
1938
2154
|
return F.pipe(
|
|
1939
2155
|
O.Do,
|
|
1940
2156
|
O.bind("clazz", () => AST11.findParentNodeGuard(node, isClassComponent)),
|
|
@@ -1969,8 +2185,12 @@ function containsStringLiteral({ value }) {
|
|
|
1969
2185
|
return value?.type === AST_NODE_TYPES.Literal && isString(value.value);
|
|
1970
2186
|
}
|
|
1971
2187
|
function containsStringExpressionContainer({ value }) {
|
|
1972
|
-
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer)
|
|
1973
|
-
|
|
2188
|
+
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
if (value.expression.type === AST_NODE_TYPES.Literal) {
|
|
2192
|
+
return isString(value.expression.value);
|
|
2193
|
+
}
|
|
1974
2194
|
return value.expression.type === AST_NODE_TYPES.TemplateLiteral;
|
|
1975
2195
|
}
|
|
1976
2196
|
var no_string_refs_default = createRule({
|
|
@@ -1989,7 +2209,9 @@ var no_string_refs_default = createRule({
|
|
|
1989
2209
|
create(context) {
|
|
1990
2210
|
return {
|
|
1991
2211
|
JSXAttribute(node) {
|
|
1992
|
-
if (node.name.name !== "ref")
|
|
2212
|
+
if (node.name.name !== "ref") {
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
1993
2215
|
if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
|
|
1994
2216
|
context.report({
|
|
1995
2217
|
messageId: "noStringRefs",
|
|
@@ -2022,7 +2244,9 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2022
2244
|
},
|
|
2023
2245
|
name: RULE_NAME37,
|
|
2024
2246
|
create(context) {
|
|
2025
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount"))
|
|
2247
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) {
|
|
2248
|
+
return {};
|
|
2249
|
+
}
|
|
2026
2250
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2027
2251
|
return {
|
|
2028
2252
|
...listeners,
|
|
@@ -2065,7 +2289,9 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2065
2289
|
},
|
|
2066
2290
|
name: RULE_NAME38,
|
|
2067
2291
|
create(context) {
|
|
2068
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps"))
|
|
2292
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2293
|
+
return {};
|
|
2294
|
+
}
|
|
2069
2295
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2070
2296
|
return {
|
|
2071
2297
|
...listeners,
|
|
@@ -2108,7 +2334,9 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2108
2334
|
},
|
|
2109
2335
|
name: RULE_NAME39,
|
|
2110
2336
|
create(context) {
|
|
2111
|
-
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate"))
|
|
2337
|
+
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) {
|
|
2338
|
+
return {};
|
|
2339
|
+
}
|
|
2112
2340
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2113
2341
|
return {
|
|
2114
2342
|
...listeners,
|
|
@@ -2156,8 +2384,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2156
2384
|
...listeners,
|
|
2157
2385
|
JSXOpeningElement(node) {
|
|
2158
2386
|
const openingElementName = node.name;
|
|
2159
|
-
if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression)
|
|
2160
|
-
|
|
2387
|
+
if (openingElementName.type !== AST_NODE_TYPES.JSXMemberExpression) {
|
|
2388
|
+
return;
|
|
2389
|
+
}
|
|
2390
|
+
if (openingElementName.property.name !== "Provider") {
|
|
2391
|
+
return;
|
|
2392
|
+
}
|
|
2161
2393
|
F.pipe(
|
|
2162
2394
|
O.Do,
|
|
2163
2395
|
O.bind("function", ctx.getCurrentFunction),
|
|
@@ -2173,8 +2405,12 @@ var no_unstable_context_value_default = createRule({
|
|
|
2173
2405
|
return O.some(VAR.getValueConstruction(valueExpression, initialScope));
|
|
2174
2406
|
}),
|
|
2175
2407
|
O.map((vc) => {
|
|
2176
|
-
if (vc.construction.kind === "None")
|
|
2177
|
-
|
|
2408
|
+
if (vc.construction.kind === "None") {
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
if (isReactHookCall(vc.construction.node)) {
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2178
2414
|
const prevs = constructions.get(vc.function.node) ?? [];
|
|
2179
2415
|
constructions.set(vc.function.node, [...prevs, vc.construction]);
|
|
2180
2416
|
})
|
|
@@ -2184,7 +2420,9 @@ var no_unstable_context_value_default = createRule({
|
|
|
2184
2420
|
const components = ctx.getAllComponents(node).values();
|
|
2185
2421
|
for (const { node: component } of components) {
|
|
2186
2422
|
for (const construction of constructions.get(component) ?? []) {
|
|
2187
|
-
if (construction.kind === "None")
|
|
2423
|
+
if (construction.kind === "None") {
|
|
2424
|
+
continue;
|
|
2425
|
+
}
|
|
2188
2426
|
const { kind, node: constructionNode } = construction;
|
|
2189
2427
|
const messageId = kind.startsWith("Function") ? "noUnstableContextValueWithFunction" : "noUnstableContextValueWithIdentifier";
|
|
2190
2428
|
context.report({
|
|
@@ -2228,12 +2466,16 @@ var no_unstable_default_props_default = createRule({
|
|
|
2228
2466
|
for (const { node: component } of components.values()) {
|
|
2229
2467
|
const { params } = component;
|
|
2230
2468
|
const [props] = params;
|
|
2231
|
-
if (!props)
|
|
2469
|
+
if (!props) {
|
|
2470
|
+
continue;
|
|
2471
|
+
}
|
|
2232
2472
|
const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name2 }) => {
|
|
2233
2473
|
return declarators.get(component)?.filter((d) => d.init.name === name2).flatMap((d) => d.id.properties) ?? [];
|
|
2234
2474
|
}).otherwise(() => []);
|
|
2235
2475
|
for (const prop of properties) {
|
|
2236
|
-
if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern)
|
|
2476
|
+
if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) {
|
|
2477
|
+
continue;
|
|
2478
|
+
}
|
|
2237
2479
|
const { value } = prop;
|
|
2238
2480
|
const { right } = value;
|
|
2239
2481
|
const initialScope = context.sourceCode.getScope(value);
|
|
@@ -2242,8 +2484,12 @@ var no_unstable_default_props_default = createRule({
|
|
|
2242
2484
|
initialScope,
|
|
2243
2485
|
VAR.ValueConstructionHint.StrictCallExpression
|
|
2244
2486
|
);
|
|
2245
|
-
if (construction.kind === "None")
|
|
2246
|
-
|
|
2487
|
+
if (construction.kind === "None") {
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
if (isReactHookCall(construction.node)) {
|
|
2491
|
+
continue;
|
|
2492
|
+
}
|
|
2247
2493
|
const forbiddenType = AST11.toReadableNodeType(right);
|
|
2248
2494
|
context.report({
|
|
2249
2495
|
messageId: "noUnstableDefaultProps",
|
|
@@ -2257,7 +2503,9 @@ var no_unstable_default_props_default = createRule({
|
|
|
2257
2503
|
},
|
|
2258
2504
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2259
2505
|
const mbEntry = ctx.getCurrentFunction();
|
|
2260
|
-
if (O.isNone(mbEntry))
|
|
2506
|
+
if (O.isNone(mbEntry)) {
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2261
2509
|
const entry = mbEntry.value;
|
|
2262
2510
|
const prevs = declarators.get(entry.node) ?? [];
|
|
2263
2511
|
declarators.set(entry.node, [...prevs, node]);
|
|
@@ -2322,21 +2570,31 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2322
2570
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
2323
2571
|
function classEnter(node) {
|
|
2324
2572
|
classStack.push(node);
|
|
2325
|
-
if (!isClassComponent(node))
|
|
2573
|
+
if (!isClassComponent(node)) {
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2326
2576
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
2327
2577
|
propertyUsages.set(node, /* @__PURE__ */ new Set());
|
|
2328
2578
|
}
|
|
2329
2579
|
function classExit() {
|
|
2330
2580
|
const currentClass = classStack.pop();
|
|
2331
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2581
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2582
|
+
return;
|
|
2583
|
+
}
|
|
2332
2584
|
const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
|
|
2333
2585
|
const defs = propertyDefs.get(currentClass);
|
|
2334
2586
|
const usages = propertyUsages.get(currentClass);
|
|
2335
|
-
if (!defs)
|
|
2587
|
+
if (!defs) {
|
|
2588
|
+
return;
|
|
2589
|
+
}
|
|
2336
2590
|
for (const def of defs) {
|
|
2337
2591
|
const name2 = getName3(def);
|
|
2338
|
-
if (O.isNone(name2))
|
|
2339
|
-
|
|
2592
|
+
if (O.isNone(name2)) {
|
|
2593
|
+
continue;
|
|
2594
|
+
}
|
|
2595
|
+
if (usages?.has(name2.value) || LIFECYCLE_METHODS.has(name2.value)) {
|
|
2596
|
+
continue;
|
|
2597
|
+
}
|
|
2340
2598
|
context.report({
|
|
2341
2599
|
messageId: "noUnusedClassComponentMembers",
|
|
2342
2600
|
node: def,
|
|
@@ -2350,8 +2608,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2350
2608
|
function methodEnter(node) {
|
|
2351
2609
|
methodStack.push(node);
|
|
2352
2610
|
const currentClass = classStack.at(-1);
|
|
2353
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2354
|
-
|
|
2611
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2612
|
+
return;
|
|
2613
|
+
}
|
|
2614
|
+
if (node.static) {
|
|
2615
|
+
return;
|
|
2616
|
+
}
|
|
2355
2617
|
if (AST11.isKeyLiteralLike(node, node.key)) {
|
|
2356
2618
|
propertyDefs.get(currentClass)?.add(node.key);
|
|
2357
2619
|
}
|
|
@@ -2367,9 +2629,15 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2367
2629
|
MemberExpression(node) {
|
|
2368
2630
|
const currentClass = classStack.at(-1);
|
|
2369
2631
|
const currentMethod = methodStack.at(-1);
|
|
2370
|
-
if (!currentClass || !currentMethod)
|
|
2371
|
-
|
|
2372
|
-
|
|
2632
|
+
if (!currentClass || !currentMethod) {
|
|
2633
|
+
return;
|
|
2634
|
+
}
|
|
2635
|
+
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2636
|
+
return;
|
|
2637
|
+
}
|
|
2638
|
+
if (!AST11.isThisExpression(node.object) || !AST11.isKeyLiteralLike(node, node.property)) {
|
|
2639
|
+
return;
|
|
2640
|
+
}
|
|
2373
2641
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
2374
2642
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
2375
2643
|
return;
|
|
@@ -2383,8 +2651,12 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2383
2651
|
VariableDeclarator(node) {
|
|
2384
2652
|
const currentClass = classStack.at(-1);
|
|
2385
2653
|
const currentMethod = methodStack.at(-1);
|
|
2386
|
-
if (!currentClass || !currentMethod)
|
|
2387
|
-
|
|
2654
|
+
if (!currentClass || !currentMethod) {
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2657
|
+
if (!isClassComponent(currentClass) || currentMethod.static) {
|
|
2658
|
+
return;
|
|
2659
|
+
}
|
|
2388
2660
|
if (node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
2389
2661
|
for (const prop of node.id.properties) {
|
|
2390
2662
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
@@ -2456,10 +2728,14 @@ var no_unused_state_default = createRule({
|
|
|
2456
2728
|
}
|
|
2457
2729
|
function classExit() {
|
|
2458
2730
|
const currentClass = classStack.pop();
|
|
2459
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2731
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2732
|
+
return;
|
|
2733
|
+
}
|
|
2460
2734
|
const className = O.map(AST11.getClassIdentifier(currentClass), (id) => id.name);
|
|
2461
2735
|
const [def, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
|
|
2462
|
-
if (O.isNone(def) || isUsed)
|
|
2736
|
+
if (O.isNone(def) || isUsed) {
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2463
2739
|
context.report({
|
|
2464
2740
|
messageId: "noUnusedState",
|
|
2465
2741
|
node: def.value,
|
|
@@ -2471,7 +2747,9 @@ var no_unused_state_default = createRule({
|
|
|
2471
2747
|
function methodEnter(node) {
|
|
2472
2748
|
methodStack.push(node);
|
|
2473
2749
|
const currentClass = classStack.at(-1);
|
|
2474
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2750
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2751
|
+
return;
|
|
2752
|
+
}
|
|
2475
2753
|
if (node.static) {
|
|
2476
2754
|
if (isGetDerivedStateFromProps(node) && node.value.params.length > 1) {
|
|
2477
2755
|
const [def] = stateDefs.get(currentClass) ?? [O.none()];
|
|
@@ -2494,11 +2772,17 @@ var no_unused_state_default = createRule({
|
|
|
2494
2772
|
}
|
|
2495
2773
|
return {
|
|
2496
2774
|
AssignmentExpression(node) {
|
|
2497
|
-
if (!isAssignmentToThisState2(node))
|
|
2775
|
+
if (!isAssignmentToThisState2(node)) {
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2498
2778
|
const currentClass = classStack.at(-1);
|
|
2499
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2779
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2780
|
+
return;
|
|
2781
|
+
}
|
|
2500
2782
|
const currentConstructor = constructorStack.at(-1);
|
|
2501
|
-
if (!currentConstructor || !currentClass.body.body.includes(currentConstructor))
|
|
2783
|
+
if (!currentConstructor || !currentClass.body.body.includes(currentConstructor)) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2502
2786
|
const [_, isUsed] = stateDefs.get(currentClass) ?? [O.none(), false];
|
|
2503
2787
|
stateDefs.set(currentClass, [O.some(node.left), isUsed]);
|
|
2504
2788
|
},
|
|
@@ -2507,14 +2791,26 @@ var no_unused_state_default = createRule({
|
|
|
2507
2791
|
ClassExpression: classEnter,
|
|
2508
2792
|
"ClassExpression:exit": classExit,
|
|
2509
2793
|
MemberExpression(node) {
|
|
2510
|
-
if (!AST11.isThisExpression(node.object))
|
|
2511
|
-
|
|
2794
|
+
if (!AST11.isThisExpression(node.object)) {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
if (!O.exists(getName4(node.property), (name2) => name2 === "state")) {
|
|
2798
|
+
return;
|
|
2799
|
+
}
|
|
2512
2800
|
const currentClass = classStack.at(-1);
|
|
2513
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2801
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2802
|
+
return;
|
|
2803
|
+
}
|
|
2514
2804
|
const currentMethod = methodStack.at(-1);
|
|
2515
|
-
if (!currentMethod || currentMethod.static)
|
|
2516
|
-
|
|
2517
|
-
|
|
2805
|
+
if (!currentMethod || currentMethod.static) {
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
if (currentMethod === constructorStack.at(-1)) {
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2811
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2518
2814
|
const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
|
|
2519
2815
|
stateDefs.set(currentClass, [def, true]);
|
|
2520
2816
|
},
|
|
@@ -2526,19 +2822,31 @@ var no_unused_state_default = createRule({
|
|
|
2526
2822
|
"PropertyDefinition:exit": methodExit,
|
|
2527
2823
|
VariableDeclarator(node) {
|
|
2528
2824
|
const currentClass = classStack.at(-1);
|
|
2529
|
-
if (!currentClass || !isClassComponent(currentClass))
|
|
2825
|
+
if (!currentClass || !isClassComponent(currentClass)) {
|
|
2826
|
+
return;
|
|
2827
|
+
}
|
|
2530
2828
|
const currentMethod = methodStack.at(-1);
|
|
2531
|
-
if (!currentMethod || currentMethod.static)
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
if (
|
|
2829
|
+
if (!currentMethod || currentMethod.static) {
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
if (currentMethod === constructorStack.at(-1)) {
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
if (!(node.init && AST11.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern)) {
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2535
2841
|
const hasState = node.id.properties.some((prop) => {
|
|
2536
2842
|
if (prop.type === AST_NODE_TYPES.Property && AST11.isKeyLiteralLike(prop, prop.key)) {
|
|
2537
2843
|
return O.exists(getName4(prop.key), (name2) => name2 === "state");
|
|
2538
2844
|
}
|
|
2539
2845
|
return false;
|
|
2540
2846
|
});
|
|
2541
|
-
if (!hasState)
|
|
2847
|
+
if (!hasState) {
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2542
2850
|
const [def] = stateDefs.get(currentClass) ?? [O.none(), false];
|
|
2543
2851
|
stateDefs.set(currentClass, [def, true]);
|
|
2544
2852
|
}
|
|
@@ -2552,8 +2860,12 @@ var defaultOptions = [{
|
|
|
2552
2860
|
}];
|
|
2553
2861
|
function checkAndReport(node, context, allowExpressions) {
|
|
2554
2862
|
const initialScope = context.sourceCode.getScope(node);
|
|
2555
|
-
if (JSX7.isKeyedElement(node, initialScope))
|
|
2556
|
-
|
|
2863
|
+
if (JSX7.isKeyedElement(node, initialScope)) {
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2866
|
+
if (JSX7.isBuiltInElement(node.parent)) {
|
|
2867
|
+
context.report({ messageId: "noUselessFragmentInBuiltIn", node });
|
|
2868
|
+
}
|
|
2557
2869
|
if (node.children.length === 0) {
|
|
2558
2870
|
context.report({ messageId: "noUselessFragment", node });
|
|
2559
2871
|
return;
|
|
@@ -2612,7 +2924,9 @@ var no_useless_fragment_default = createRule({
|
|
|
2612
2924
|
const { allowExpressions = true } = option;
|
|
2613
2925
|
return {
|
|
2614
2926
|
JSXElement(node) {
|
|
2615
|
-
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment")
|
|
2927
|
+
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2616
2930
|
checkAndReport(node, context, allowExpressions);
|
|
2617
2931
|
},
|
|
2618
2932
|
JSXFragment(node) {
|
|
@@ -2656,7 +2970,9 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2656
2970
|
"Program:exit"(node) {
|
|
2657
2971
|
const components = Array.from(ctx.getAllComponents(node).values());
|
|
2658
2972
|
function isFunctionComponent(block) {
|
|
2659
|
-
if (!AST11.isFunction(block))
|
|
2973
|
+
if (!AST11.isFunction(block)) {
|
|
2974
|
+
return false;
|
|
2975
|
+
}
|
|
2660
2976
|
return O.exists(
|
|
2661
2977
|
AST11.getFunctionIdentifier(block),
|
|
2662
2978
|
(id) => isComponentName(id.name) && components.some((component) => component.node === block)
|
|
@@ -2669,9 +2985,13 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2669
2985
|
scope = scope.upper;
|
|
2670
2986
|
isComponent = isFunctionComponent(scope.block);
|
|
2671
2987
|
}
|
|
2672
|
-
if (!isComponent)
|
|
2988
|
+
if (!isComponent) {
|
|
2989
|
+
continue;
|
|
2990
|
+
}
|
|
2673
2991
|
const component = scope.block;
|
|
2674
|
-
if (!("params" in component))
|
|
2992
|
+
if (!("params" in component)) {
|
|
2993
|
+
continue;
|
|
2994
|
+
}
|
|
2675
2995
|
const [props, ctx2] = component.params;
|
|
2676
2996
|
const isMatch = isMatching({ name: memberExpression.object.name });
|
|
2677
2997
|
if (isMatch(props)) {
|
|
@@ -2787,9 +3107,13 @@ var prefer_read_only_props_default = createRule({
|
|
|
2787
3107
|
const components = ctx.getAllComponents(node);
|
|
2788
3108
|
for (const [_, component] of components) {
|
|
2789
3109
|
const [props] = component.node.params;
|
|
2790
|
-
if (!props)
|
|
3110
|
+
if (!props) {
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
2791
3113
|
const propsType = getConstrainedTypeAtLocation(services, props);
|
|
2792
|
-
if (isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services))
|
|
3114
|
+
if (isTypeReadonly(services.program, propsType) || isReadonlyType(propsType, services)) {
|
|
3115
|
+
continue;
|
|
3116
|
+
}
|
|
2793
3117
|
context.report({ messageId: "preferReadOnlyProps", node: props });
|
|
2794
3118
|
}
|
|
2795
3119
|
}
|
|
@@ -2821,7 +3145,9 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
2821
3145
|
const { value } = node;
|
|
2822
3146
|
const propName = JSX7.getPropName(node);
|
|
2823
3147
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
2824
|
-
if (!hasValueTrue)
|
|
3148
|
+
if (!hasValueTrue) {
|
|
3149
|
+
return O.none();
|
|
3150
|
+
}
|
|
2825
3151
|
return O.some({
|
|
2826
3152
|
messageId: "preferShorthandBoolean",
|
|
2827
3153
|
node,
|
|
@@ -2858,15 +3184,21 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
2858
3184
|
name: RULE_NAME49,
|
|
2859
3185
|
create(context) {
|
|
2860
3186
|
function getReportDescriptor(node) {
|
|
2861
|
-
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment")
|
|
3187
|
+
if (JSX7.getElementName(node.openingElement).split(".").at(-1) !== "Fragment") {
|
|
3188
|
+
return O.none();
|
|
3189
|
+
}
|
|
2862
3190
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
2863
|
-
if (hasAttributes)
|
|
3191
|
+
if (hasAttributes) {
|
|
3192
|
+
return O.none();
|
|
3193
|
+
}
|
|
2864
3194
|
return O.some({
|
|
2865
3195
|
messageId: "preferShorthandFragment",
|
|
2866
3196
|
node,
|
|
2867
3197
|
fix: (fixer) => {
|
|
2868
3198
|
const { closingElement, openingElement } = node;
|
|
2869
|
-
if (!closingElement)
|
|
3199
|
+
if (!closingElement) {
|
|
3200
|
+
return [];
|
|
3201
|
+
}
|
|
2870
3202
|
return [
|
|
2871
3203
|
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
2872
3204
|
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
@@ -2909,7 +3241,9 @@ var use_jsx_vars_default = createRule({
|
|
|
2909
3241
|
}
|
|
2910
3242
|
return {
|
|
2911
3243
|
JSXOpeningElement(node) {
|
|
2912
|
-
if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name))
|
|
3244
|
+
if (node.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.name.name)) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
2913
3247
|
for (const name2 of O.toArray(getName5(node.name))) {
|
|
2914
3248
|
context.sourceCode.markVariableAsUsed(name2, node);
|
|
2915
3249
|
}
|