eslint-plugin-react-x 2.0.0-beta.18 → 2.0.0-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/README.md +1 -1
- package/dist/index.d.ts +44 -8
- package/dist/index.js +1078 -838
- package/package.json +16 -16
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getDocsUrl, getSettingsFromContext, coerceSettings, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
2
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
3
3
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
4
|
+
import * as AST13 from '@eslint-react/ast';
|
|
5
|
+
import * as VAR5 from '@eslint-react/var';
|
|
6
6
|
import { match, isMatching, P } from 'ts-pattern';
|
|
7
|
-
import * as
|
|
8
|
-
import { JsxConfig, Reporter, Selector } from '@eslint-react/kit';
|
|
9
|
-
import {
|
|
7
|
+
import * as ER26 from '@eslint-react/core';
|
|
8
|
+
import { JsxConfig, Reporter, Selector, LanguagePreference } from '@eslint-react/kit';
|
|
9
|
+
import { flow, identity, getOrElseUpdate, constTrue, constFalse, unit } from '@eslint-react/eff';
|
|
10
10
|
import { compare } from 'compare-versions';
|
|
11
11
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
12
12
|
import { unionTypeParts, isTypeFlagSet, isTrueLiteralType, isFalseLiteralType } from 'ts-api-utils';
|
|
@@ -28,8 +28,8 @@ __export(recommended_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
var name = "react-x/recommended";
|
|
30
30
|
var rules = {
|
|
31
|
-
"react-x/jsx-no-comment-textnodes": "warn",
|
|
32
31
|
"react-x/jsx-key-before-spread": "warn",
|
|
32
|
+
"react-x/jsx-no-comment-textnodes": "warn",
|
|
33
33
|
"react-x/jsx-no-duplicate-props": "warn",
|
|
34
34
|
// "react-x/jsx-no-undef": "error",
|
|
35
35
|
"react-x/jsx-uses-react": "warn",
|
|
@@ -54,7 +54,6 @@ var rules = {
|
|
|
54
54
|
// "react-x/prefer-destructuring-assignment": "warn",
|
|
55
55
|
// "react-x/prefer-namespace-import": "warn",
|
|
56
56
|
// "react-x/prefer-read-only-props": "error",
|
|
57
|
-
"react-x/no-direct-set-state-in-use-effect": "warn",
|
|
58
57
|
"react-x/no-duplicate-key": "warn",
|
|
59
58
|
"react-x/no-forward-ref": "warn",
|
|
60
59
|
"react-x/no-implicit-key": "warn",
|
|
@@ -126,7 +125,7 @@ var settings3 = {
|
|
|
126
125
|
|
|
127
126
|
// package.json
|
|
128
127
|
var name4 = "eslint-plugin-react-x";
|
|
129
|
-
var version = "2.0.0-beta.
|
|
128
|
+
var version = "2.0.0-beta.2";
|
|
130
129
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
131
130
|
|
|
132
131
|
// src/rules/jsx-key-before-spread.ts
|
|
@@ -192,14 +191,14 @@ var jsx_no_comment_textnodes_default = createRule({
|
|
|
192
191
|
});
|
|
193
192
|
function create2(context) {
|
|
194
193
|
function hasCommentLike(node) {
|
|
195
|
-
if (
|
|
194
|
+
if (AST13.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
196
195
|
return false;
|
|
197
196
|
}
|
|
198
197
|
const rawValue = context.sourceCode.getText(node);
|
|
199
198
|
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
200
199
|
}
|
|
201
200
|
const visitorFunction = (node) => {
|
|
202
|
-
if (!
|
|
201
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
203
202
|
return;
|
|
204
203
|
}
|
|
205
204
|
if (!hasCommentLike(node)) {
|
|
@@ -260,17 +259,19 @@ function create3(context) {
|
|
|
260
259
|
}
|
|
261
260
|
};
|
|
262
261
|
}
|
|
263
|
-
var RULE_NAME4 = "jsx-no-
|
|
264
|
-
var RULE_FEATURES4 = [
|
|
265
|
-
|
|
262
|
+
var RULE_NAME4 = "jsx-no-iife";
|
|
263
|
+
var RULE_FEATURES4 = [
|
|
264
|
+
"EXP"
|
|
265
|
+
];
|
|
266
|
+
var jsx_no_iife_default = createRule({
|
|
266
267
|
meta: {
|
|
267
268
|
type: "problem",
|
|
268
269
|
docs: {
|
|
269
|
-
description: "
|
|
270
|
+
description: "Disallows 'IIFE' in JSX elements.",
|
|
270
271
|
[Symbol.for("rule_features")]: RULE_FEATURES4
|
|
271
272
|
},
|
|
272
273
|
messages: {
|
|
273
|
-
|
|
274
|
+
jsxNoIife: "Avoid using IIFE in JSX elements."
|
|
274
275
|
},
|
|
275
276
|
schema: []
|
|
276
277
|
},
|
|
@@ -279,13 +280,51 @@ var jsx_no_undef_default = createRule({
|
|
|
279
280
|
defaultOptions: []
|
|
280
281
|
});
|
|
281
282
|
function create4(context) {
|
|
283
|
+
return {
|
|
284
|
+
"JSXElement :function"(node) {
|
|
285
|
+
if (node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node) {
|
|
286
|
+
context.report({
|
|
287
|
+
messageId: "jsxNoIife",
|
|
288
|
+
node: node.parent
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
"JSXFragment :function"(node) {
|
|
293
|
+
if (node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node) {
|
|
294
|
+
context.report({
|
|
295
|
+
messageId: "jsxNoIife",
|
|
296
|
+
node: node.parent
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
var RULE_NAME5 = "jsx-no-undef";
|
|
303
|
+
var RULE_FEATURES5 = [];
|
|
304
|
+
var jsx_no_undef_default = createRule({
|
|
305
|
+
meta: {
|
|
306
|
+
type: "problem",
|
|
307
|
+
docs: {
|
|
308
|
+
description: "Disallow undefined variables in JSX.",
|
|
309
|
+
[Symbol.for("rule_features")]: RULE_FEATURES5
|
|
310
|
+
},
|
|
311
|
+
messages: {
|
|
312
|
+
jsxNoUndef: "JSX variable '{{name}}' is not defined."
|
|
313
|
+
},
|
|
314
|
+
schema: []
|
|
315
|
+
},
|
|
316
|
+
name: RULE_NAME5,
|
|
317
|
+
create: create5,
|
|
318
|
+
defaultOptions: []
|
|
319
|
+
});
|
|
320
|
+
function create5(context) {
|
|
282
321
|
return {
|
|
283
322
|
JSXOpeningElement(node) {
|
|
284
323
|
const name5 = match(node.name).with({ type: AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({ type: AST_NODE_TYPES.JSXMemberExpression, object: { type: AST_NODE_TYPES.JSXIdentifier } }, (n) => n.object.name).otherwise(() => null);
|
|
285
324
|
if (name5 == null) return;
|
|
286
325
|
if (name5 === "this") return;
|
|
287
326
|
if (/^[a-z]/u.test(name5)) return;
|
|
288
|
-
if (
|
|
327
|
+
if (VAR5.findVariable(name5, context.sourceCode.getScope(node)) == null) {
|
|
289
328
|
context.report({
|
|
290
329
|
messageId: "jsxNoUndef",
|
|
291
330
|
node,
|
|
@@ -297,8 +336,8 @@ function create4(context) {
|
|
|
297
336
|
}
|
|
298
337
|
};
|
|
299
338
|
}
|
|
300
|
-
var
|
|
301
|
-
var
|
|
339
|
+
var RULE_NAME6 = "jsx-shorthand-boolean";
|
|
340
|
+
var RULE_FEATURES6 = [
|
|
302
341
|
"CFG",
|
|
303
342
|
"FIX"
|
|
304
343
|
];
|
|
@@ -314,7 +353,7 @@ var jsx_shorthand_boolean_default = createRule({
|
|
|
314
353
|
type: "problem",
|
|
315
354
|
docs: {
|
|
316
355
|
description: "Enforces shorthand syntax for boolean attributes.",
|
|
317
|
-
[Symbol.for("rule_features")]:
|
|
356
|
+
[Symbol.for("rule_features")]: RULE_FEATURES6
|
|
318
357
|
},
|
|
319
358
|
fixable: "code",
|
|
320
359
|
messages: {
|
|
@@ -322,16 +361,16 @@ var jsx_shorthand_boolean_default = createRule({
|
|
|
322
361
|
},
|
|
323
362
|
schema
|
|
324
363
|
},
|
|
325
|
-
name:
|
|
326
|
-
create:
|
|
364
|
+
name: RULE_NAME6,
|
|
365
|
+
create: create6,
|
|
327
366
|
defaultOptions
|
|
328
367
|
});
|
|
329
|
-
function
|
|
368
|
+
function create6(context) {
|
|
330
369
|
const policy = context.options[0] ?? defaultOptions[0];
|
|
331
370
|
return {
|
|
332
371
|
JSXAttribute(node) {
|
|
333
372
|
const { value } = node;
|
|
334
|
-
const propName =
|
|
373
|
+
const propName = ER26.getAttributeName(context, node);
|
|
335
374
|
switch (true) {
|
|
336
375
|
case (policy === 1 && value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true): {
|
|
337
376
|
context.report({
|
|
@@ -359,8 +398,8 @@ function create5(context) {
|
|
|
359
398
|
}
|
|
360
399
|
};
|
|
361
400
|
}
|
|
362
|
-
var
|
|
363
|
-
var
|
|
401
|
+
var RULE_NAME7 = "jsx-shorthand-fragment";
|
|
402
|
+
var RULE_FEATURES7 = [
|
|
364
403
|
"CFG",
|
|
365
404
|
"FIX"
|
|
366
405
|
];
|
|
@@ -376,7 +415,7 @@ var jsx_shorthand_fragment_default = createRule({
|
|
|
376
415
|
type: "problem",
|
|
377
416
|
docs: {
|
|
378
417
|
description: "Enforces shorthand syntax for fragments.",
|
|
379
|
-
[Symbol.for("rule_features")]:
|
|
418
|
+
[Symbol.for("rule_features")]: RULE_FEATURES7
|
|
380
419
|
},
|
|
381
420
|
fixable: "code",
|
|
382
421
|
messages: {
|
|
@@ -384,11 +423,11 @@ var jsx_shorthand_fragment_default = createRule({
|
|
|
384
423
|
},
|
|
385
424
|
schema: schema2
|
|
386
425
|
},
|
|
387
|
-
name:
|
|
388
|
-
create:
|
|
426
|
+
name: RULE_NAME7,
|
|
427
|
+
create: create7,
|
|
389
428
|
defaultOptions: defaultOptions2
|
|
390
429
|
});
|
|
391
|
-
function
|
|
430
|
+
function create7(context) {
|
|
392
431
|
const policy = context.options[0] ?? defaultOptions2[0];
|
|
393
432
|
const jsxConfig = {
|
|
394
433
|
...JsxConfig.getFromContext(context),
|
|
@@ -397,7 +436,7 @@ function create6(context) {
|
|
|
397
436
|
const { jsxFragmentFactory } = jsxConfig;
|
|
398
437
|
return match(policy).with(1, () => ({
|
|
399
438
|
JSXElement(node) {
|
|
400
|
-
if (!
|
|
439
|
+
if (!ER26.isFragmentElement(context, node)) return;
|
|
401
440
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
402
441
|
if (hasAttributes) return;
|
|
403
442
|
context.report({
|
|
@@ -440,25 +479,25 @@ function create6(context) {
|
|
|
440
479
|
})).otherwise(() => ({}));
|
|
441
480
|
}
|
|
442
481
|
var { JsxEmit } = JsxConfig;
|
|
443
|
-
var
|
|
444
|
-
var
|
|
482
|
+
var RULE_NAME8 = "jsx-uses-react";
|
|
483
|
+
var RULE_FEATURES8 = [];
|
|
445
484
|
var jsx_uses_react_default = createRule({
|
|
446
485
|
meta: {
|
|
447
486
|
type: "problem",
|
|
448
487
|
docs: {
|
|
449
488
|
description: "Marks React variables as used when JSX is used.",
|
|
450
|
-
[Symbol.for("rule_features")]:
|
|
489
|
+
[Symbol.for("rule_features")]: RULE_FEATURES8
|
|
451
490
|
},
|
|
452
491
|
messages: {
|
|
453
492
|
jsxUsesReact: "Marked {{name}} as used."
|
|
454
493
|
},
|
|
455
494
|
schema: []
|
|
456
495
|
},
|
|
457
|
-
name:
|
|
458
|
-
create:
|
|
496
|
+
name: RULE_NAME8,
|
|
497
|
+
create: create8,
|
|
459
498
|
defaultOptions: []
|
|
460
499
|
});
|
|
461
|
-
function
|
|
500
|
+
function create8(context) {
|
|
462
501
|
const jsxConfig = {
|
|
463
502
|
...JsxConfig.getFromContext(context),
|
|
464
503
|
...JsxConfig.getFromAnnotation(context)
|
|
@@ -487,25 +526,25 @@ function debugReport(context, node, name5) {
|
|
|
487
526
|
data: { name: name5 }
|
|
488
527
|
});
|
|
489
528
|
}
|
|
490
|
-
var
|
|
491
|
-
var
|
|
529
|
+
var RULE_NAME9 = "jsx-uses-vars";
|
|
530
|
+
var RULE_FEATURES9 = [];
|
|
492
531
|
var jsx_uses_vars_default = createRule({
|
|
493
532
|
meta: {
|
|
494
533
|
type: "problem",
|
|
495
534
|
docs: {
|
|
496
535
|
description: "Marks variables used in JSX elements as used.",
|
|
497
|
-
[Symbol.for("rule_features")]:
|
|
536
|
+
[Symbol.for("rule_features")]: RULE_FEATURES9
|
|
498
537
|
},
|
|
499
538
|
messages: {
|
|
500
|
-
jsxUsesVars: ""
|
|
539
|
+
jsxUsesVars: "An identifier in JSX is marked as used."
|
|
501
540
|
},
|
|
502
541
|
schema: []
|
|
503
542
|
},
|
|
504
|
-
name:
|
|
505
|
-
create:
|
|
543
|
+
name: RULE_NAME9,
|
|
544
|
+
create: create9,
|
|
506
545
|
defaultOptions: []
|
|
507
546
|
});
|
|
508
|
-
function
|
|
547
|
+
function create9(context) {
|
|
509
548
|
return {
|
|
510
549
|
JSXOpeningElement(node) {
|
|
511
550
|
switch (node.name.type) {
|
|
@@ -527,8 +566,8 @@ function create8(context) {
|
|
|
527
566
|
}
|
|
528
567
|
};
|
|
529
568
|
}
|
|
530
|
-
var
|
|
531
|
-
var
|
|
569
|
+
var RULE_NAME10 = "no-access-state-in-setstate";
|
|
570
|
+
var RULE_FEATURES10 = [];
|
|
532
571
|
function isKeyLiteral(node, key) {
|
|
533
572
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
534
573
|
}
|
|
@@ -537,18 +576,18 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
537
576
|
type: "problem",
|
|
538
577
|
docs: {
|
|
539
578
|
description: "Disallow accessing `this.state` inside `setState` calls.",
|
|
540
|
-
[Symbol.for("rule_features")]:
|
|
579
|
+
[Symbol.for("rule_features")]: RULE_FEATURES10
|
|
541
580
|
},
|
|
542
581
|
messages: {
|
|
543
582
|
noAccessStateInSetstate: "Do not access 'this.state' within 'setState'. Use the update function instead."
|
|
544
583
|
},
|
|
545
584
|
schema: []
|
|
546
585
|
},
|
|
547
|
-
name:
|
|
548
|
-
create:
|
|
586
|
+
name: RULE_NAME10,
|
|
587
|
+
create: create10,
|
|
549
588
|
defaultOptions: []
|
|
550
589
|
});
|
|
551
|
-
function
|
|
590
|
+
function create10(context) {
|
|
552
591
|
if (!context.sourceCode.text.includes("setState")) {
|
|
553
592
|
return {};
|
|
554
593
|
}
|
|
@@ -557,31 +596,31 @@ function create9(context) {
|
|
|
557
596
|
const setStateEntries = [];
|
|
558
597
|
return {
|
|
559
598
|
CallExpression(node) {
|
|
560
|
-
if (!
|
|
599
|
+
if (!ER26.isThisSetState(node)) {
|
|
561
600
|
return;
|
|
562
601
|
}
|
|
563
602
|
setStateEntries.push([node, false]);
|
|
564
603
|
},
|
|
565
604
|
"CallExpression:exit"(node) {
|
|
566
|
-
if (!
|
|
605
|
+
if (!ER26.isThisSetState(node)) {
|
|
567
606
|
return;
|
|
568
607
|
}
|
|
569
608
|
setStateEntries.pop();
|
|
570
609
|
},
|
|
571
610
|
ClassDeclaration(node) {
|
|
572
|
-
classEntries.push([node,
|
|
611
|
+
classEntries.push([node, ER26.isClassComponent(node)]);
|
|
573
612
|
},
|
|
574
613
|
"ClassDeclaration:exit"() {
|
|
575
614
|
classEntries.pop();
|
|
576
615
|
},
|
|
577
616
|
ClassExpression(node) {
|
|
578
|
-
classEntries.push([node,
|
|
617
|
+
classEntries.push([node, ER26.isClassComponent(node)]);
|
|
579
618
|
},
|
|
580
619
|
"ClassExpression:exit"() {
|
|
581
620
|
classEntries.pop();
|
|
582
621
|
},
|
|
583
622
|
MemberExpression(node) {
|
|
584
|
-
if (!
|
|
623
|
+
if (!AST13.isThisExpression(node.object)) {
|
|
585
624
|
return;
|
|
586
625
|
}
|
|
587
626
|
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
@@ -596,7 +635,7 @@ function create9(context) {
|
|
|
596
635
|
if (setState == null || hasThisState) {
|
|
597
636
|
return;
|
|
598
637
|
}
|
|
599
|
-
if (
|
|
638
|
+
if (AST13.getPropertyName(node.property) !== "state") {
|
|
600
639
|
return;
|
|
601
640
|
}
|
|
602
641
|
context.report({ messageId: "noAccessStateInSetstate", node });
|
|
@@ -626,11 +665,11 @@ function create9(context) {
|
|
|
626
665
|
if (setState == null || hasThisState) {
|
|
627
666
|
return;
|
|
628
667
|
}
|
|
629
|
-
if (node.init == null || !
|
|
668
|
+
if (node.init == null || !AST13.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
630
669
|
return;
|
|
631
670
|
}
|
|
632
671
|
const hasState = node.id.properties.some(
|
|
633
|
-
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) &&
|
|
672
|
+
(prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key) && AST13.getPropertyName(prop.key) === "state"
|
|
634
673
|
);
|
|
635
674
|
if (!hasState) {
|
|
636
675
|
return;
|
|
@@ -639,8 +678,8 @@ function create9(context) {
|
|
|
639
678
|
}
|
|
640
679
|
};
|
|
641
680
|
}
|
|
642
|
-
var
|
|
643
|
-
var
|
|
681
|
+
var RULE_NAME11 = "no-array-index-key";
|
|
682
|
+
var RULE_FEATURES11 = [];
|
|
644
683
|
var reactChildrenMethod = ["forEach", "map"];
|
|
645
684
|
function isReactChildrenMethod(name5) {
|
|
646
685
|
return reactChildrenMethod.some((method) => method === name5);
|
|
@@ -659,36 +698,36 @@ function isUsingReactChildren(context, node) {
|
|
|
659
698
|
return true;
|
|
660
699
|
}
|
|
661
700
|
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
662
|
-
return
|
|
701
|
+
return ER26.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
663
702
|
}
|
|
664
703
|
return false;
|
|
665
704
|
}
|
|
666
705
|
function getMapIndexParamName(context, node) {
|
|
667
706
|
const { callee } = node;
|
|
668
707
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
669
|
-
return
|
|
708
|
+
return unit;
|
|
670
709
|
}
|
|
671
710
|
if (callee.property.type !== AST_NODE_TYPES.Identifier) {
|
|
672
|
-
return
|
|
711
|
+
return unit;
|
|
673
712
|
}
|
|
674
713
|
const { name: name5 } = callee.property;
|
|
675
|
-
const indexPosition =
|
|
714
|
+
const indexPosition = AST13.getArrayMethodCallbackIndexParamPosition(name5);
|
|
676
715
|
if (indexPosition === -1) {
|
|
677
|
-
return
|
|
716
|
+
return unit;
|
|
678
717
|
}
|
|
679
718
|
const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
|
|
680
719
|
if (callbackArg == null) {
|
|
681
|
-
return
|
|
720
|
+
return unit;
|
|
682
721
|
}
|
|
683
|
-
if (!
|
|
684
|
-
return
|
|
722
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(callbackArg)) {
|
|
723
|
+
return unit;
|
|
685
724
|
}
|
|
686
725
|
const { params } = callbackArg;
|
|
687
726
|
if (params.length < indexPosition + 1) {
|
|
688
|
-
return
|
|
727
|
+
return unit;
|
|
689
728
|
}
|
|
690
729
|
const param = params.at(indexPosition);
|
|
691
|
-
return param != null && "name" in param ? param.name :
|
|
730
|
+
return param != null && "name" in param ? param.name : unit;
|
|
692
731
|
}
|
|
693
732
|
function getIdentifiersFromBinaryExpression(side) {
|
|
694
733
|
if (side.type === AST_NODE_TYPES.Identifier) {
|
|
@@ -707,25 +746,25 @@ var no_array_index_key_default = createRule({
|
|
|
707
746
|
type: "problem",
|
|
708
747
|
docs: {
|
|
709
748
|
description: "Disallow an item's index in the array as its key.",
|
|
710
|
-
[Symbol.for("rule_features")]:
|
|
749
|
+
[Symbol.for("rule_features")]: RULE_FEATURES11
|
|
711
750
|
},
|
|
712
751
|
messages: {
|
|
713
752
|
noArrayIndexKey: "Do not use item index in the array as its key."
|
|
714
753
|
},
|
|
715
754
|
schema: []
|
|
716
755
|
},
|
|
717
|
-
name:
|
|
718
|
-
create:
|
|
756
|
+
name: RULE_NAME11,
|
|
757
|
+
create: create11,
|
|
719
758
|
defaultOptions: []
|
|
720
759
|
});
|
|
721
|
-
function
|
|
760
|
+
function create11(context) {
|
|
722
761
|
const report = Reporter.make(context);
|
|
723
762
|
const indexParamNames = [];
|
|
724
763
|
function isArrayIndex(node) {
|
|
725
764
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
726
765
|
}
|
|
727
766
|
function isCreateOrCloneElementCall(node) {
|
|
728
|
-
return
|
|
767
|
+
return ER26.isCreateElementCall(context, node) || ER26.isCloneElementCall(context, node);
|
|
729
768
|
}
|
|
730
769
|
function getReportDescriptors(node) {
|
|
731
770
|
switch (node.type) {
|
|
@@ -820,28 +859,28 @@ function create10(context) {
|
|
|
820
859
|
}
|
|
821
860
|
};
|
|
822
861
|
}
|
|
823
|
-
var
|
|
824
|
-
var
|
|
862
|
+
var RULE_NAME12 = "no-children-count";
|
|
863
|
+
var RULE_FEATURES12 = [];
|
|
825
864
|
var no_children_count_default = createRule({
|
|
826
865
|
meta: {
|
|
827
866
|
type: "problem",
|
|
828
867
|
docs: {
|
|
829
868
|
description: "Disallow `Children.count`.",
|
|
830
|
-
[Symbol.for("rule_features")]:
|
|
869
|
+
[Symbol.for("rule_features")]: RULE_FEATURES12
|
|
831
870
|
},
|
|
832
871
|
messages: {
|
|
833
872
|
noChildrenCount: "Using 'Children.count' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
834
873
|
},
|
|
835
874
|
schema: []
|
|
836
875
|
},
|
|
837
|
-
name:
|
|
838
|
-
create:
|
|
876
|
+
name: RULE_NAME12,
|
|
877
|
+
create: create12,
|
|
839
878
|
defaultOptions: []
|
|
840
879
|
});
|
|
841
|
-
function
|
|
880
|
+
function create12(context) {
|
|
842
881
|
return {
|
|
843
882
|
MemberExpression(node) {
|
|
844
|
-
if (
|
|
883
|
+
if (ER26.isChildrenCount(context, node)) {
|
|
845
884
|
context.report({
|
|
846
885
|
messageId: "noChildrenCount",
|
|
847
886
|
node: node.property
|
|
@@ -850,28 +889,28 @@ function create11(context) {
|
|
|
850
889
|
}
|
|
851
890
|
};
|
|
852
891
|
}
|
|
853
|
-
var
|
|
854
|
-
var
|
|
892
|
+
var RULE_NAME13 = "no-children-for-each";
|
|
893
|
+
var RULE_FEATURES13 = [];
|
|
855
894
|
var no_children_for_each_default = createRule({
|
|
856
895
|
meta: {
|
|
857
896
|
type: "problem",
|
|
858
897
|
docs: {
|
|
859
898
|
description: "Disallow 'Children.forEach'.",
|
|
860
|
-
[Symbol.for("rule_features")]:
|
|
899
|
+
[Symbol.for("rule_features")]: RULE_FEATURES13
|
|
861
900
|
},
|
|
862
901
|
messages: {
|
|
863
902
|
noChildrenForEach: "Using 'Children.forEach' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
864
903
|
},
|
|
865
904
|
schema: []
|
|
866
905
|
},
|
|
867
|
-
name:
|
|
868
|
-
create:
|
|
906
|
+
name: RULE_NAME13,
|
|
907
|
+
create: create13,
|
|
869
908
|
defaultOptions: []
|
|
870
909
|
});
|
|
871
|
-
function
|
|
910
|
+
function create13(context) {
|
|
872
911
|
return {
|
|
873
912
|
MemberExpression(node) {
|
|
874
|
-
if (
|
|
913
|
+
if (ER26.isChildrenForEach(context, node)) {
|
|
875
914
|
context.report({
|
|
876
915
|
messageId: "noChildrenForEach",
|
|
877
916
|
node: node.property
|
|
@@ -880,28 +919,28 @@ function create12(context) {
|
|
|
880
919
|
}
|
|
881
920
|
};
|
|
882
921
|
}
|
|
883
|
-
var
|
|
884
|
-
var
|
|
922
|
+
var RULE_NAME14 = "no-children-map";
|
|
923
|
+
var RULE_FEATURES14 = [];
|
|
885
924
|
var no_children_map_default = createRule({
|
|
886
925
|
meta: {
|
|
887
926
|
type: "problem",
|
|
888
927
|
docs: {
|
|
889
928
|
description: "Disallow `Children.map`.",
|
|
890
|
-
[Symbol.for("rule_features")]:
|
|
929
|
+
[Symbol.for("rule_features")]: RULE_FEATURES14
|
|
891
930
|
},
|
|
892
931
|
messages: {
|
|
893
932
|
noChildrenMap: "Using 'Children.map' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
894
933
|
},
|
|
895
934
|
schema: []
|
|
896
935
|
},
|
|
897
|
-
name:
|
|
898
|
-
create:
|
|
936
|
+
name: RULE_NAME14,
|
|
937
|
+
create: create14,
|
|
899
938
|
defaultOptions: []
|
|
900
939
|
});
|
|
901
|
-
function
|
|
940
|
+
function create14(context) {
|
|
902
941
|
return {
|
|
903
942
|
MemberExpression(node) {
|
|
904
|
-
if (
|
|
943
|
+
if (ER26.isChildrenMap(context, node)) {
|
|
905
944
|
context.report({
|
|
906
945
|
messageId: "noChildrenMap",
|
|
907
946
|
node: node.property
|
|
@@ -910,28 +949,28 @@ function create13(context) {
|
|
|
910
949
|
}
|
|
911
950
|
};
|
|
912
951
|
}
|
|
913
|
-
var
|
|
914
|
-
var
|
|
952
|
+
var RULE_NAME15 = "no-children-only";
|
|
953
|
+
var RULE_FEATURES15 = [];
|
|
915
954
|
var no_children_only_default = createRule({
|
|
916
955
|
meta: {
|
|
917
956
|
type: "problem",
|
|
918
957
|
docs: {
|
|
919
958
|
description: "Disallow `Children.only`.",
|
|
920
|
-
[Symbol.for("rule_features")]:
|
|
959
|
+
[Symbol.for("rule_features")]: RULE_FEATURES15
|
|
921
960
|
},
|
|
922
961
|
messages: {
|
|
923
962
|
noChildrenOnly: "Using 'Children.only' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
924
963
|
},
|
|
925
964
|
schema: []
|
|
926
965
|
},
|
|
927
|
-
name:
|
|
928
|
-
create:
|
|
966
|
+
name: RULE_NAME15,
|
|
967
|
+
create: create15,
|
|
929
968
|
defaultOptions: []
|
|
930
969
|
});
|
|
931
|
-
function
|
|
970
|
+
function create15(context) {
|
|
932
971
|
return {
|
|
933
972
|
MemberExpression(node) {
|
|
934
|
-
if (
|
|
973
|
+
if (ER26.isChildrenOnly(context, node)) {
|
|
935
974
|
context.report({
|
|
936
975
|
messageId: "noChildrenOnly",
|
|
937
976
|
node: node.property
|
|
@@ -940,29 +979,29 @@ function create14(context) {
|
|
|
940
979
|
}
|
|
941
980
|
};
|
|
942
981
|
}
|
|
943
|
-
var
|
|
944
|
-
var
|
|
982
|
+
var RULE_NAME16 = "no-children-prop";
|
|
983
|
+
var RULE_FEATURES16 = [];
|
|
945
984
|
var no_children_prop_default = createRule({
|
|
946
985
|
meta: {
|
|
947
986
|
type: "problem",
|
|
948
987
|
docs: {
|
|
949
988
|
description: "Disallow passing `children` as a prop.",
|
|
950
|
-
[Symbol.for("rule_features")]:
|
|
989
|
+
[Symbol.for("rule_features")]: RULE_FEATURES16
|
|
951
990
|
},
|
|
952
991
|
messages: {
|
|
953
992
|
noChildrenProp: "Do not pass 'children' as props."
|
|
954
993
|
},
|
|
955
994
|
schema: []
|
|
956
995
|
},
|
|
957
|
-
name:
|
|
958
|
-
create:
|
|
996
|
+
name: RULE_NAME16,
|
|
997
|
+
create: create16,
|
|
959
998
|
defaultOptions: []
|
|
960
999
|
});
|
|
961
|
-
function
|
|
1000
|
+
function create16(context) {
|
|
962
1001
|
return {
|
|
963
1002
|
JSXElement(node) {
|
|
964
1003
|
const attributes = node.openingElement.attributes;
|
|
965
|
-
const childrenProp =
|
|
1004
|
+
const childrenProp = ER26.getAttribute(context, "children", attributes, context.sourceCode.getScope(node));
|
|
966
1005
|
if (childrenProp != null) {
|
|
967
1006
|
context.report({
|
|
968
1007
|
messageId: "noChildrenProp",
|
|
@@ -972,28 +1011,28 @@ function create15(context) {
|
|
|
972
1011
|
}
|
|
973
1012
|
};
|
|
974
1013
|
}
|
|
975
|
-
var
|
|
976
|
-
var
|
|
1014
|
+
var RULE_NAME17 = "no-children-to-array";
|
|
1015
|
+
var RULE_FEATURES17 = [];
|
|
977
1016
|
var no_children_to_array_default = createRule({
|
|
978
1017
|
meta: {
|
|
979
1018
|
type: "problem",
|
|
980
1019
|
docs: {
|
|
981
1020
|
description: "Disallow `Children.toArray`.",
|
|
982
|
-
[Symbol.for("rule_features")]:
|
|
1021
|
+
[Symbol.for("rule_features")]: RULE_FEATURES17
|
|
983
1022
|
},
|
|
984
1023
|
messages: {
|
|
985
1024
|
noChildrenToArray: "Using 'Children.toArray' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
986
1025
|
},
|
|
987
1026
|
schema: []
|
|
988
1027
|
},
|
|
989
|
-
name:
|
|
990
|
-
create:
|
|
1028
|
+
name: RULE_NAME17,
|
|
1029
|
+
create: create17,
|
|
991
1030
|
defaultOptions: []
|
|
992
1031
|
});
|
|
993
|
-
function
|
|
1032
|
+
function create17(context) {
|
|
994
1033
|
return {
|
|
995
1034
|
MemberExpression(node) {
|
|
996
|
-
if (
|
|
1035
|
+
if (ER26.isChildrenToArray(context, node)) {
|
|
997
1036
|
context.report({
|
|
998
1037
|
messageId: "noChildrenToArray",
|
|
999
1038
|
node: node.property
|
|
@@ -1002,33 +1041,33 @@ function create16(context) {
|
|
|
1002
1041
|
}
|
|
1003
1042
|
};
|
|
1004
1043
|
}
|
|
1005
|
-
var
|
|
1006
|
-
var
|
|
1044
|
+
var RULE_NAME18 = "no-class-component";
|
|
1045
|
+
var RULE_FEATURES18 = [];
|
|
1007
1046
|
var no_class_component_default = createRule({
|
|
1008
1047
|
meta: {
|
|
1009
1048
|
type: "problem",
|
|
1010
1049
|
docs: {
|
|
1011
1050
|
description: "Disallow class components except for error boundaries.",
|
|
1012
|
-
[Symbol.for("rule_features")]:
|
|
1051
|
+
[Symbol.for("rule_features")]: RULE_FEATURES18
|
|
1013
1052
|
},
|
|
1014
1053
|
messages: {
|
|
1015
1054
|
noClassComponent: "Avoid using class components. Use function components instead."
|
|
1016
1055
|
},
|
|
1017
1056
|
schema: []
|
|
1018
1057
|
},
|
|
1019
|
-
name:
|
|
1020
|
-
create:
|
|
1058
|
+
name: RULE_NAME18,
|
|
1059
|
+
create: create18,
|
|
1021
1060
|
defaultOptions: []
|
|
1022
1061
|
});
|
|
1023
|
-
function
|
|
1062
|
+
function create18(context) {
|
|
1024
1063
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
1025
|
-
const { ctx, listeners } =
|
|
1064
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
1026
1065
|
return {
|
|
1027
1066
|
...listeners,
|
|
1028
1067
|
"Program:exit"(program) {
|
|
1029
1068
|
const components = ctx.getAllComponents(program);
|
|
1030
1069
|
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
1031
|
-
if (component.body.body.some((m) =>
|
|
1070
|
+
if (component.body.body.some((m) => ER26.isComponentDidCatch(m) || ER26.isGetDerivedStateFromError(m))) {
|
|
1032
1071
|
continue;
|
|
1033
1072
|
}
|
|
1034
1073
|
context.report({
|
|
@@ -1042,28 +1081,28 @@ function create17(context) {
|
|
|
1042
1081
|
}
|
|
1043
1082
|
};
|
|
1044
1083
|
}
|
|
1045
|
-
var
|
|
1046
|
-
var
|
|
1084
|
+
var RULE_NAME19 = "no-clone-element";
|
|
1085
|
+
var RULE_FEATURES19 = [];
|
|
1047
1086
|
var no_clone_element_default = createRule({
|
|
1048
1087
|
meta: {
|
|
1049
1088
|
type: "problem",
|
|
1050
1089
|
docs: {
|
|
1051
1090
|
description: "Disallow `cloneElement`.",
|
|
1052
|
-
[Symbol.for("rule_features")]:
|
|
1091
|
+
[Symbol.for("rule_features")]: RULE_FEATURES19
|
|
1053
1092
|
},
|
|
1054
1093
|
messages: {
|
|
1055
1094
|
noCloneElement: "Using 'cloneElement' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
1056
1095
|
},
|
|
1057
1096
|
schema: []
|
|
1058
1097
|
},
|
|
1059
|
-
name:
|
|
1060
|
-
create:
|
|
1098
|
+
name: RULE_NAME19,
|
|
1099
|
+
create: create19,
|
|
1061
1100
|
defaultOptions: []
|
|
1062
1101
|
});
|
|
1063
|
-
function
|
|
1102
|
+
function create19(context) {
|
|
1064
1103
|
return {
|
|
1065
1104
|
CallExpression(node) {
|
|
1066
|
-
if (
|
|
1105
|
+
if (ER26.isCloneElementCall(context, node)) {
|
|
1067
1106
|
context.report({
|
|
1068
1107
|
messageId: "noCloneElement",
|
|
1069
1108
|
node
|
|
@@ -1072,8 +1111,8 @@ function create18(context) {
|
|
|
1072
1111
|
}
|
|
1073
1112
|
};
|
|
1074
1113
|
}
|
|
1075
|
-
var
|
|
1076
|
-
var
|
|
1114
|
+
var RULE_NAME20 = "no-component-will-mount";
|
|
1115
|
+
var RULE_FEATURES20 = [
|
|
1077
1116
|
"MOD"
|
|
1078
1117
|
];
|
|
1079
1118
|
var no_component_will_mount_default = createRule({
|
|
@@ -1081,7 +1120,7 @@ var no_component_will_mount_default = createRule({
|
|
|
1081
1120
|
type: "problem",
|
|
1082
1121
|
docs: {
|
|
1083
1122
|
description: "Replace usages of `componentWillMount` with `UNSAFE_componentWillMount`.",
|
|
1084
|
-
[Symbol.for("rule_features")]:
|
|
1123
|
+
[Symbol.for("rule_features")]: RULE_FEATURES20
|
|
1085
1124
|
},
|
|
1086
1125
|
fixable: "code",
|
|
1087
1126
|
messages: {
|
|
@@ -1089,13 +1128,13 @@ var no_component_will_mount_default = createRule({
|
|
|
1089
1128
|
},
|
|
1090
1129
|
schema: []
|
|
1091
1130
|
},
|
|
1092
|
-
name:
|
|
1093
|
-
create:
|
|
1131
|
+
name: RULE_NAME20,
|
|
1132
|
+
create: create20,
|
|
1094
1133
|
defaultOptions: []
|
|
1095
1134
|
});
|
|
1096
|
-
function
|
|
1135
|
+
function create20(context) {
|
|
1097
1136
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
1098
|
-
const { ctx, listeners } =
|
|
1137
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
1099
1138
|
return {
|
|
1100
1139
|
...listeners,
|
|
1101
1140
|
"Program:exit"(program) {
|
|
@@ -1103,7 +1142,7 @@ function create19(context) {
|
|
|
1103
1142
|
for (const { node: component } of components.values()) {
|
|
1104
1143
|
const { body } = component.body;
|
|
1105
1144
|
for (const member of body) {
|
|
1106
|
-
if (
|
|
1145
|
+
if (ER26.isComponentWillMount(member)) {
|
|
1107
1146
|
context.report({
|
|
1108
1147
|
messageId: "noComponentWillMount",
|
|
1109
1148
|
node: member,
|
|
@@ -1120,8 +1159,8 @@ function create19(context) {
|
|
|
1120
1159
|
}
|
|
1121
1160
|
};
|
|
1122
1161
|
}
|
|
1123
|
-
var
|
|
1124
|
-
var
|
|
1162
|
+
var RULE_NAME21 = "no-component-will-receive-props";
|
|
1163
|
+
var RULE_FEATURES21 = [
|
|
1125
1164
|
"MOD"
|
|
1126
1165
|
];
|
|
1127
1166
|
var no_component_will_receive_props_default = createRule({
|
|
@@ -1129,7 +1168,7 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1129
1168
|
type: "problem",
|
|
1130
1169
|
docs: {
|
|
1131
1170
|
description: "Replace usages of `componentWillReceiveProps` with `UNSAFE_componentWillReceiveProps`.",
|
|
1132
|
-
[Symbol.for("rule_features")]:
|
|
1171
|
+
[Symbol.for("rule_features")]: RULE_FEATURES21
|
|
1133
1172
|
},
|
|
1134
1173
|
fixable: "code",
|
|
1135
1174
|
messages: {
|
|
@@ -1137,13 +1176,13 @@ var no_component_will_receive_props_default = createRule({
|
|
|
1137
1176
|
},
|
|
1138
1177
|
schema: []
|
|
1139
1178
|
},
|
|
1140
|
-
name:
|
|
1141
|
-
create:
|
|
1179
|
+
name: RULE_NAME21,
|
|
1180
|
+
create: create21,
|
|
1142
1181
|
defaultOptions: []
|
|
1143
1182
|
});
|
|
1144
|
-
function
|
|
1183
|
+
function create21(context) {
|
|
1145
1184
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
1146
|
-
const { ctx, listeners } =
|
|
1185
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
1147
1186
|
return {
|
|
1148
1187
|
...listeners,
|
|
1149
1188
|
"Program:exit"(program) {
|
|
@@ -1151,7 +1190,7 @@ function create20(context) {
|
|
|
1151
1190
|
for (const { node: component } of components.values()) {
|
|
1152
1191
|
const { body } = component.body;
|
|
1153
1192
|
for (const member of body) {
|
|
1154
|
-
if (
|
|
1193
|
+
if (ER26.isComponentWillReceiveProps(member)) {
|
|
1155
1194
|
context.report({
|
|
1156
1195
|
messageId: "noComponentWillReceiveProps",
|
|
1157
1196
|
node: member,
|
|
@@ -1168,8 +1207,8 @@ function create20(context) {
|
|
|
1168
1207
|
}
|
|
1169
1208
|
};
|
|
1170
1209
|
}
|
|
1171
|
-
var
|
|
1172
|
-
var
|
|
1210
|
+
var RULE_NAME22 = "no-component-will-update";
|
|
1211
|
+
var RULE_FEATURES22 = [
|
|
1173
1212
|
"MOD"
|
|
1174
1213
|
];
|
|
1175
1214
|
var no_component_will_update_default = createRule({
|
|
@@ -1177,7 +1216,7 @@ var no_component_will_update_default = createRule({
|
|
|
1177
1216
|
type: "problem",
|
|
1178
1217
|
docs: {
|
|
1179
1218
|
description: "Replace usages of `componentWillUpdate` with `UNSAFE_componentWillUpdate`.",
|
|
1180
|
-
[Symbol.for("rule_features")]:
|
|
1219
|
+
[Symbol.for("rule_features")]: RULE_FEATURES22
|
|
1181
1220
|
},
|
|
1182
1221
|
fixable: "code",
|
|
1183
1222
|
messages: {
|
|
@@ -1185,13 +1224,13 @@ var no_component_will_update_default = createRule({
|
|
|
1185
1224
|
},
|
|
1186
1225
|
schema: []
|
|
1187
1226
|
},
|
|
1188
|
-
name:
|
|
1189
|
-
create:
|
|
1227
|
+
name: RULE_NAME22,
|
|
1228
|
+
create: create22,
|
|
1190
1229
|
defaultOptions: []
|
|
1191
1230
|
});
|
|
1192
|
-
function
|
|
1231
|
+
function create22(context) {
|
|
1193
1232
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1194
|
-
const { ctx, listeners } =
|
|
1233
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
1195
1234
|
return {
|
|
1196
1235
|
...listeners,
|
|
1197
1236
|
"Program:exit"(program) {
|
|
@@ -1199,7 +1238,7 @@ function create21(context) {
|
|
|
1199
1238
|
for (const { node: component } of components.values()) {
|
|
1200
1239
|
const { body } = component.body;
|
|
1201
1240
|
for (const member of body) {
|
|
1202
|
-
if (
|
|
1241
|
+
if (ER26.isComponentWillUpdate(member)) {
|
|
1203
1242
|
context.report({
|
|
1204
1243
|
messageId: "noComponentWillUpdate",
|
|
1205
1244
|
node: member,
|
|
@@ -1216,8 +1255,8 @@ function create21(context) {
|
|
|
1216
1255
|
}
|
|
1217
1256
|
};
|
|
1218
1257
|
}
|
|
1219
|
-
var
|
|
1220
|
-
var
|
|
1258
|
+
var RULE_NAME23 = "no-context-provider";
|
|
1259
|
+
var RULE_FEATURES23 = [
|
|
1221
1260
|
"MOD"
|
|
1222
1261
|
];
|
|
1223
1262
|
var no_context_provider_default = createRule({
|
|
@@ -1225,7 +1264,7 @@ var no_context_provider_default = createRule({
|
|
|
1225
1264
|
type: "problem",
|
|
1226
1265
|
docs: {
|
|
1227
1266
|
description: "Replace usages of `<Context.Provider>` with `<Context>`.",
|
|
1228
|
-
[Symbol.for("rule_features")]:
|
|
1267
|
+
[Symbol.for("rule_features")]: RULE_FEATURES23
|
|
1229
1268
|
},
|
|
1230
1269
|
fixable: "code",
|
|
1231
1270
|
messages: {
|
|
@@ -1233,17 +1272,17 @@ var no_context_provider_default = createRule({
|
|
|
1233
1272
|
},
|
|
1234
1273
|
schema: []
|
|
1235
1274
|
},
|
|
1236
|
-
name:
|
|
1237
|
-
create:
|
|
1275
|
+
name: RULE_NAME23,
|
|
1276
|
+
create: create23,
|
|
1238
1277
|
defaultOptions: []
|
|
1239
1278
|
});
|
|
1240
|
-
function
|
|
1279
|
+
function create23(context) {
|
|
1241
1280
|
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
1242
1281
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1243
1282
|
if (compare(version2, "19.0.0", "<")) return {};
|
|
1244
1283
|
return {
|
|
1245
1284
|
JSXElement(node) {
|
|
1246
|
-
const fullName =
|
|
1285
|
+
const fullName = ER26.getElementType(context, node);
|
|
1247
1286
|
const parts = fullName.split(".");
|
|
1248
1287
|
const selfName = parts.pop();
|
|
1249
1288
|
const contextFullName = parts.join(".");
|
|
@@ -1254,7 +1293,7 @@ function create22(context) {
|
|
|
1254
1293
|
messageId: "noContextProvider",
|
|
1255
1294
|
node,
|
|
1256
1295
|
fix(fixer) {
|
|
1257
|
-
if (!
|
|
1296
|
+
if (!ER26.isComponentNameLoose(contextSelfName)) return null;
|
|
1258
1297
|
const openingElement = node.openingElement;
|
|
1259
1298
|
const closingElement = node.closingElement;
|
|
1260
1299
|
if (closingElement == null) {
|
|
@@ -1269,52 +1308,52 @@ function create22(context) {
|
|
|
1269
1308
|
}
|
|
1270
1309
|
};
|
|
1271
1310
|
}
|
|
1272
|
-
var
|
|
1273
|
-
var
|
|
1311
|
+
var RULE_NAME24 = "no-create-ref";
|
|
1312
|
+
var RULE_FEATURES24 = [];
|
|
1274
1313
|
var no_create_ref_default = createRule({
|
|
1275
1314
|
meta: {
|
|
1276
1315
|
type: "problem",
|
|
1277
1316
|
docs: {
|
|
1278
1317
|
description: "Disallow `createRef` in function components.",
|
|
1279
|
-
[Symbol.for("rule_features")]:
|
|
1318
|
+
[Symbol.for("rule_features")]: RULE_FEATURES24
|
|
1280
1319
|
},
|
|
1281
1320
|
messages: {
|
|
1282
1321
|
noCreateRef: "[Deprecated] Use 'useRef' instead."
|
|
1283
1322
|
},
|
|
1284
1323
|
schema: []
|
|
1285
1324
|
},
|
|
1286
|
-
name:
|
|
1287
|
-
create:
|
|
1325
|
+
name: RULE_NAME24,
|
|
1326
|
+
create: create24,
|
|
1288
1327
|
defaultOptions: []
|
|
1289
1328
|
});
|
|
1290
|
-
function
|
|
1329
|
+
function create24(context) {
|
|
1291
1330
|
return {
|
|
1292
1331
|
CallExpression(node) {
|
|
1293
|
-
if (
|
|
1332
|
+
if (ER26.isCreateRefCall(context, node) && AST13.findParentNode(node, ER26.isClassComponent) == null) {
|
|
1294
1333
|
context.report({ messageId: "noCreateRef", node });
|
|
1295
1334
|
}
|
|
1296
1335
|
}
|
|
1297
1336
|
};
|
|
1298
1337
|
}
|
|
1299
|
-
var
|
|
1300
|
-
var
|
|
1338
|
+
var RULE_NAME25 = "no-default-props";
|
|
1339
|
+
var RULE_FEATURES25 = [];
|
|
1301
1340
|
var no_default_props_default = createRule({
|
|
1302
1341
|
meta: {
|
|
1303
1342
|
type: "problem",
|
|
1304
1343
|
docs: {
|
|
1305
1344
|
description: "Disallow `defaultProps` property in favor of ES6 default parameters.",
|
|
1306
|
-
[Symbol.for("rule_features")]:
|
|
1345
|
+
[Symbol.for("rule_features")]: RULE_FEATURES25
|
|
1307
1346
|
},
|
|
1308
1347
|
messages: {
|
|
1309
1348
|
noDefaultProps: "[Deprecated] Use ES6 default parameters instead."
|
|
1310
1349
|
},
|
|
1311
1350
|
schema: []
|
|
1312
1351
|
},
|
|
1313
|
-
name:
|
|
1314
|
-
create:
|
|
1352
|
+
name: RULE_NAME25,
|
|
1353
|
+
create: create25,
|
|
1315
1354
|
defaultOptions: []
|
|
1316
1355
|
});
|
|
1317
|
-
function
|
|
1356
|
+
function create25(context) {
|
|
1318
1357
|
if (!context.sourceCode.text.includes("defaultProps")) return {};
|
|
1319
1358
|
return {
|
|
1320
1359
|
AssignmentExpression(node) {
|
|
@@ -1328,60 +1367,51 @@ function create24(context) {
|
|
|
1328
1367
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "defaultProps") {
|
|
1329
1368
|
return;
|
|
1330
1369
|
}
|
|
1331
|
-
if (!
|
|
1370
|
+
if (!ER26.isComponentNameLoose(object.name)) {
|
|
1332
1371
|
return;
|
|
1333
1372
|
}
|
|
1334
|
-
const variable =
|
|
1335
|
-
const variableNode =
|
|
1373
|
+
const variable = VAR5.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1374
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
1336
1375
|
if (variableNode == null) return;
|
|
1337
|
-
if (!
|
|
1376
|
+
if (!AST13.isFunction(variableNode)) return;
|
|
1338
1377
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1339
|
-
},
|
|
1340
|
-
PropertyDefinition(node) {
|
|
1341
|
-
if (!ER27.isClassComponent(node.parent.parent)) {
|
|
1342
|
-
return;
|
|
1343
|
-
}
|
|
1344
|
-
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "defaultProps") {
|
|
1345
|
-
return;
|
|
1346
|
-
}
|
|
1347
|
-
context.report({ messageId: "noDefaultProps", node });
|
|
1348
1378
|
}
|
|
1349
1379
|
};
|
|
1350
1380
|
}
|
|
1351
|
-
var
|
|
1352
|
-
var
|
|
1381
|
+
var RULE_NAME26 = "no-direct-mutation-state";
|
|
1382
|
+
var RULE_FEATURES26 = [];
|
|
1353
1383
|
function isConstructorFunction(node) {
|
|
1354
|
-
return
|
|
1384
|
+
return AST13.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST13.isMethodOrProperty(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1355
1385
|
}
|
|
1356
1386
|
var no_direct_mutation_state_default = createRule({
|
|
1357
1387
|
meta: {
|
|
1358
1388
|
type: "problem",
|
|
1359
1389
|
docs: {
|
|
1360
1390
|
description: "Disallow direct mutation of `this.state`.",
|
|
1361
|
-
[Symbol.for("rule_features")]:
|
|
1391
|
+
[Symbol.for("rule_features")]: RULE_FEATURES26
|
|
1362
1392
|
},
|
|
1363
1393
|
messages: {
|
|
1364
1394
|
noDirectMutationState: "Do not mutate state directly. Use 'setState()' instead."
|
|
1365
1395
|
},
|
|
1366
1396
|
schema: []
|
|
1367
1397
|
},
|
|
1368
|
-
name:
|
|
1369
|
-
create:
|
|
1398
|
+
name: RULE_NAME26,
|
|
1399
|
+
create: create26,
|
|
1370
1400
|
defaultOptions: []
|
|
1371
1401
|
});
|
|
1372
|
-
function
|
|
1402
|
+
function create26(context) {
|
|
1373
1403
|
return {
|
|
1374
1404
|
AssignmentExpression(node) {
|
|
1375
|
-
if (!
|
|
1376
|
-
const parentClass =
|
|
1405
|
+
if (!ER26.isAssignmentToThisState(node)) return;
|
|
1406
|
+
const parentClass = AST13.findParentNode(
|
|
1377
1407
|
node,
|
|
1378
|
-
|
|
1408
|
+
AST13.isOneOf([
|
|
1379
1409
|
AST_NODE_TYPES.ClassDeclaration,
|
|
1380
1410
|
AST_NODE_TYPES.ClassExpression
|
|
1381
1411
|
])
|
|
1382
1412
|
);
|
|
1383
1413
|
if (parentClass == null) return;
|
|
1384
|
-
if (
|
|
1414
|
+
if (ER26.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST13.findParentNode(node, isConstructorFunction)) {
|
|
1385
1415
|
context.report({
|
|
1386
1416
|
messageId: "noDirectMutationState",
|
|
1387
1417
|
node
|
|
@@ -1390,327 +1420,25 @@ function create25(context) {
|
|
|
1390
1420
|
}
|
|
1391
1421
|
};
|
|
1392
1422
|
}
|
|
1393
|
-
var
|
|
1394
|
-
var
|
|
1395
|
-
|
|
1396
|
-
];
|
|
1397
|
-
var no_direct_set_state_in_use_effect_default = createRule({
|
|
1423
|
+
var RULE_NAME27 = "no-duplicate-key";
|
|
1424
|
+
var RULE_FEATURES27 = [];
|
|
1425
|
+
var no_duplicate_key_default = createRule({
|
|
1398
1426
|
meta: {
|
|
1399
1427
|
type: "problem",
|
|
1400
1428
|
docs: {
|
|
1401
|
-
description: "Disallow
|
|
1402
|
-
[Symbol.for("rule_features")]:
|
|
1429
|
+
description: "Disallow duplicate `key` on elements in the same array or a list of `children`.",
|
|
1430
|
+
[Symbol.for("rule_features")]: RULE_FEATURES27
|
|
1403
1431
|
},
|
|
1404
1432
|
messages: {
|
|
1405
|
-
|
|
1433
|
+
noDuplicateKey: "A key must be unique. '{{value}}' is duplicated."
|
|
1406
1434
|
},
|
|
1407
1435
|
schema: []
|
|
1408
1436
|
},
|
|
1409
|
-
name:
|
|
1410
|
-
create:
|
|
1411
|
-
defaultOptions: []
|
|
1412
|
-
});
|
|
1413
|
-
function create26(context) {
|
|
1414
|
-
if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
|
|
1415
|
-
return useNoDirectSetStateInUseEffect(context, {
|
|
1416
|
-
onViolation(ctx, node, data) {
|
|
1417
|
-
ctx.report({ messageId: "noDirectSetStateInUseEffect", node, data });
|
|
1418
|
-
},
|
|
1419
|
-
useEffectKind: "useEffect"
|
|
1420
|
-
});
|
|
1421
|
-
}
|
|
1422
|
-
function useNoDirectSetStateInUseEffect(context, options) {
|
|
1423
|
-
const { onViolation, useEffectKind } = options;
|
|
1424
|
-
const settings4 = getSettingsFromContext(context);
|
|
1425
|
-
const hooks = settings4.additionalHooks;
|
|
1426
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
1427
|
-
const isUseEffectLikeCall = ER27.isReactHookCallWithNameAlias(context, useEffectKind, hooks[useEffectKind]);
|
|
1428
|
-
const isUseStateCall = ER27.isReactHookCallWithNameAlias(context, "useState", hooks.useState);
|
|
1429
|
-
const isUseMemoCall = ER27.isReactHookCallWithNameAlias(context, "useMemo", hooks.useMemo);
|
|
1430
|
-
const isUseCallbackCall = ER27.isReactHookCallWithNameAlias(context, "useCallback", hooks.useCallback);
|
|
1431
|
-
const functionEntries = [];
|
|
1432
|
-
const setupFunctionRef = { current: null };
|
|
1433
|
-
const setupFunctionIdentifiers = [];
|
|
1434
|
-
const indFunctionCalls = [];
|
|
1435
|
-
const indSetStateCalls = /* @__PURE__ */ new WeakMap();
|
|
1436
|
-
const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new WeakMap();
|
|
1437
|
-
const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
|
|
1438
|
-
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
|
|
1439
|
-
const onSetupFunctionEnter = (node) => {
|
|
1440
|
-
setupFunctionRef.current = node;
|
|
1441
|
-
};
|
|
1442
|
-
const onSetupFunctionExit = (node) => {
|
|
1443
|
-
if (setupFunctionRef.current === node) {
|
|
1444
|
-
setupFunctionRef.current = null;
|
|
1445
|
-
}
|
|
1446
|
-
};
|
|
1447
|
-
function isFunctionOfUseEffectSetup(node) {
|
|
1448
|
-
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
|
|
1449
|
-
}
|
|
1450
|
-
function getCallName(node) {
|
|
1451
|
-
if (node.type === AST_NODE_TYPES.CallExpression) {
|
|
1452
|
-
return AST7.toStringFormat(node.callee, getText);
|
|
1453
|
-
}
|
|
1454
|
-
return AST7.toStringFormat(node, getText);
|
|
1455
|
-
}
|
|
1456
|
-
function getCallKind(node) {
|
|
1457
|
-
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(AST7.isThenCall, () => "then").otherwise(() => "other");
|
|
1458
|
-
}
|
|
1459
|
-
function getFunctionKind(node) {
|
|
1460
|
-
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST7.isImmediatelyInvokedFunction, () => "immediate").otherwise(() => "other");
|
|
1461
|
-
}
|
|
1462
|
-
function isIdFromUseStateCall(topLevelId, at) {
|
|
1463
|
-
const variable = VAR3.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
|
|
1464
|
-
const variableNode = VAR3.getVariableInitNode(variable, 0);
|
|
1465
|
-
if (variableNode == null) return false;
|
|
1466
|
-
if (variableNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
1467
|
-
if (!ER27.isReactHookCallWithNameAlias(context, "useState", hooks.useState)(variableNode)) return false;
|
|
1468
|
-
const variableNodeParent = variableNode.parent;
|
|
1469
|
-
if (!("id" in variableNodeParent) || variableNodeParent.id?.type !== AST_NODE_TYPES.ArrayPattern) {
|
|
1470
|
-
return true;
|
|
1471
|
-
}
|
|
1472
|
-
return variableNodeParent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === topLevelId.name) === at;
|
|
1473
|
-
}
|
|
1474
|
-
function isSetStateCall(node) {
|
|
1475
|
-
switch (node.callee.type) {
|
|
1476
|
-
// const data = useState();
|
|
1477
|
-
// data.at(1)();
|
|
1478
|
-
case AST_NODE_TYPES.CallExpression: {
|
|
1479
|
-
const { callee } = node.callee;
|
|
1480
|
-
if (callee.type !== AST_NODE_TYPES.MemberExpression) {
|
|
1481
|
-
return false;
|
|
1482
|
-
}
|
|
1483
|
-
if (!("name" in callee.object)) {
|
|
1484
|
-
return false;
|
|
1485
|
-
}
|
|
1486
|
-
const isAt = callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "at";
|
|
1487
|
-
const [index] = node.callee.arguments;
|
|
1488
|
-
if (!isAt || index == null) {
|
|
1489
|
-
return false;
|
|
1490
|
-
}
|
|
1491
|
-
const indexScope = context.sourceCode.getScope(node);
|
|
1492
|
-
const indexValue = VAR3.toStaticValue({
|
|
1493
|
-
kind: "lazy",
|
|
1494
|
-
node: index,
|
|
1495
|
-
initialScope: indexScope
|
|
1496
|
-
}).value;
|
|
1497
|
-
return indexValue === 1 && isIdFromUseStateCall(callee.object);
|
|
1498
|
-
}
|
|
1499
|
-
// const [data, setData] = useState();
|
|
1500
|
-
// setData();
|
|
1501
|
-
case AST_NODE_TYPES.Identifier: {
|
|
1502
|
-
return isIdFromUseStateCall(node.callee, 1);
|
|
1503
|
-
}
|
|
1504
|
-
// const data = useState();
|
|
1505
|
-
// data[1]();
|
|
1506
|
-
case AST_NODE_TYPES.MemberExpression: {
|
|
1507
|
-
if (!("name" in node.callee.object)) {
|
|
1508
|
-
return false;
|
|
1509
|
-
}
|
|
1510
|
-
const property = node.callee.property;
|
|
1511
|
-
const propertyScope = context.sourceCode.getScope(node);
|
|
1512
|
-
const propertyValue = VAR3.toStaticValue({
|
|
1513
|
-
kind: "lazy",
|
|
1514
|
-
node: property,
|
|
1515
|
-
initialScope: propertyScope
|
|
1516
|
-
}).value;
|
|
1517
|
-
return propertyValue === 1 && isIdFromUseStateCall(node.callee.object, 1);
|
|
1518
|
-
}
|
|
1519
|
-
default: {
|
|
1520
|
-
return false;
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
return {
|
|
1525
|
-
":function"(node) {
|
|
1526
|
-
const kind = getFunctionKind(node);
|
|
1527
|
-
functionEntries.push({ kind, node });
|
|
1528
|
-
if (kind === "setup") {
|
|
1529
|
-
onSetupFunctionEnter(node);
|
|
1530
|
-
}
|
|
1531
|
-
},
|
|
1532
|
-
":function:exit"(node) {
|
|
1533
|
-
const { kind } = functionEntries.at(-1) ?? {};
|
|
1534
|
-
if (kind === "setup") {
|
|
1535
|
-
onSetupFunctionExit(node);
|
|
1536
|
-
}
|
|
1537
|
-
functionEntries.pop();
|
|
1538
|
-
},
|
|
1539
|
-
CallExpression(node) {
|
|
1540
|
-
const setupFunction = setupFunctionRef.current;
|
|
1541
|
-
const pEntry = functionEntries.at(-1);
|
|
1542
|
-
if (pEntry == null || pEntry.node.async) {
|
|
1543
|
-
return;
|
|
1544
|
-
}
|
|
1545
|
-
match(getCallKind(node)).with("setState", () => {
|
|
1546
|
-
switch (true) {
|
|
1547
|
-
case pEntry.node === setupFunction:
|
|
1548
|
-
case (pEntry.kind === "immediate" && AST7.findParentNode(pEntry.node, AST7.isFunction) === setupFunction): {
|
|
1549
|
-
onViolation(context, node, {
|
|
1550
|
-
name: context.sourceCode.getText(node.callee)
|
|
1551
|
-
});
|
|
1552
|
-
return;
|
|
1553
|
-
}
|
|
1554
|
-
default: {
|
|
1555
|
-
const vd = AST7.findParentNode(node, isVariableDeclaratorFromHookCall);
|
|
1556
|
-
if (vd == null) getOrElseUpdate(indSetStateCalls, pEntry.node, () => []).push(node);
|
|
1557
|
-
else getOrElseUpdate(indSetStateCallsInUseMemoOrCallback, vd.init, () => []).push(node);
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
}).with(useEffectKind, () => {
|
|
1561
|
-
if (AST7.isFunction(node.arguments.at(0))) return;
|
|
1562
|
-
setupFunctionIdentifiers.push(...AST7.getNestedIdentifiers(node));
|
|
1563
|
-
}).with("other", () => {
|
|
1564
|
-
if (pEntry.node !== setupFunction) return;
|
|
1565
|
-
indFunctionCalls.push(node);
|
|
1566
|
-
}).otherwise(constVoid);
|
|
1567
|
-
},
|
|
1568
|
-
Identifier(node) {
|
|
1569
|
-
if (node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node) {
|
|
1570
|
-
return;
|
|
1571
|
-
}
|
|
1572
|
-
if (!isIdFromUseStateCall(node, 1)) {
|
|
1573
|
-
return;
|
|
1574
|
-
}
|
|
1575
|
-
switch (node.parent.type) {
|
|
1576
|
-
case AST_NODE_TYPES.ArrowFunctionExpression: {
|
|
1577
|
-
const parent = node.parent.parent;
|
|
1578
|
-
if (parent.type !== AST_NODE_TYPES.CallExpression) {
|
|
1579
|
-
break;
|
|
1580
|
-
}
|
|
1581
|
-
if (!isUseMemoCall(parent)) {
|
|
1582
|
-
break;
|
|
1583
|
-
}
|
|
1584
|
-
const vd = AST7.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
1585
|
-
if (vd != null) {
|
|
1586
|
-
getOrElseUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
1587
|
-
}
|
|
1588
|
-
break;
|
|
1589
|
-
}
|
|
1590
|
-
case AST_NODE_TYPES.CallExpression: {
|
|
1591
|
-
if (node !== node.parent.arguments.at(0)) {
|
|
1592
|
-
break;
|
|
1593
|
-
}
|
|
1594
|
-
if (isUseCallbackCall(node.parent)) {
|
|
1595
|
-
const vd = AST7.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
1596
|
-
if (vd != null) {
|
|
1597
|
-
getOrElseUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
1598
|
-
}
|
|
1599
|
-
break;
|
|
1600
|
-
}
|
|
1601
|
-
if (isUseEffectLikeCall(node.parent)) {
|
|
1602
|
-
getOrElseUpdate(indSetStateCallsInUseEffectSetup, node.parent, () => []).push(node);
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
},
|
|
1607
|
-
"Program:exit"() {
|
|
1608
|
-
const getSetStateCalls = (id, initialScope) => {
|
|
1609
|
-
const node = VAR3.getVariableInitNode(VAR3.findVariable(id, initialScope), 0);
|
|
1610
|
-
switch (node?.type) {
|
|
1611
|
-
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
1612
|
-
case AST_NODE_TYPES.FunctionDeclaration:
|
|
1613
|
-
case AST_NODE_TYPES.FunctionExpression:
|
|
1614
|
-
return indSetStateCalls.get(node) ?? [];
|
|
1615
|
-
case AST_NODE_TYPES.CallExpression:
|
|
1616
|
-
return indSetStateCallsInUseMemoOrCallback.get(node) ?? indSetStateCallsInUseEffectArg0.get(node) ?? [];
|
|
1617
|
-
}
|
|
1618
|
-
return [];
|
|
1619
|
-
};
|
|
1620
|
-
for (const [, calls] of indSetStateCallsInUseEffectSetup) {
|
|
1621
|
-
for (const call of calls) {
|
|
1622
|
-
onViolation(context, call, { name: call.name });
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
for (const { callee } of indFunctionCalls) {
|
|
1626
|
-
if (!("name" in callee)) {
|
|
1627
|
-
continue;
|
|
1628
|
-
}
|
|
1629
|
-
const { name: name5 } = callee;
|
|
1630
|
-
const setStateCalls = getSetStateCalls(name5, context.sourceCode.getScope(callee));
|
|
1631
|
-
for (const setStateCall of setStateCalls) {
|
|
1632
|
-
onViolation(context, setStateCall, {
|
|
1633
|
-
name: getCallName(setStateCall)
|
|
1634
|
-
});
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
for (const id of setupFunctionIdentifiers) {
|
|
1638
|
-
const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
|
|
1639
|
-
for (const setStateCall of setStateCalls) {
|
|
1640
|
-
onViolation(context, setStateCall, {
|
|
1641
|
-
name: getCallName(setStateCall)
|
|
1642
|
-
});
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
};
|
|
1647
|
-
}
|
|
1648
|
-
function isInitFromHookCall(init) {
|
|
1649
|
-
if (init?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
1650
|
-
switch (init.callee.type) {
|
|
1651
|
-
case AST_NODE_TYPES.Identifier:
|
|
1652
|
-
return ER27.isReactHookName(init.callee.name);
|
|
1653
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
1654
|
-
return init.callee.property.type === AST_NODE_TYPES.Identifier && ER27.isReactHookName(init.callee.property.name);
|
|
1655
|
-
default:
|
|
1656
|
-
return false;
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
function isVariableDeclaratorFromHookCall(node) {
|
|
1660
|
-
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
1661
|
-
if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
|
|
1662
|
-
return isInitFromHookCall(node.init);
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
// src/rules/no-direct-set-state-in-use-layout-effect.ts
|
|
1666
|
-
var RULE_NAME27 = "no-direct-set-state-in-use-layout-effect";
|
|
1667
|
-
var RULE_FEATURES27 = [
|
|
1668
|
-
"EXP"
|
|
1669
|
-
];
|
|
1670
|
-
var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
1671
|
-
meta: {
|
|
1672
|
-
type: "problem",
|
|
1673
|
-
docs: {
|
|
1674
|
-
description: "Disallow direct calls to the `set` function of `useState` in `useLayoutEffect`.",
|
|
1675
|
-
[Symbol.for("rule_features")]: RULE_FEATURES27
|
|
1676
|
-
},
|
|
1677
|
-
messages: {
|
|
1678
|
-
noDirectSetStateInUseLayoutEffect: "Do not call the 'set' function '{{name}}' of 'useState' directly in 'useLayoutEffect'."
|
|
1679
|
-
},
|
|
1680
|
-
schema: []
|
|
1681
|
-
},
|
|
1682
|
-
name: RULE_NAME27,
|
|
1683
|
-
create: create27,
|
|
1437
|
+
name: RULE_NAME27,
|
|
1438
|
+
create: create27,
|
|
1684
1439
|
defaultOptions: []
|
|
1685
1440
|
});
|
|
1686
1441
|
function create27(context) {
|
|
1687
|
-
if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
|
|
1688
|
-
return useNoDirectSetStateInUseEffect(context, {
|
|
1689
|
-
onViolation(ctx, node, data) {
|
|
1690
|
-
ctx.report({ messageId: "noDirectSetStateInUseLayoutEffect", node, data });
|
|
1691
|
-
},
|
|
1692
|
-
useEffectKind: "useLayoutEffect"
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
var RULE_NAME28 = "no-duplicate-key";
|
|
1696
|
-
var RULE_FEATURES28 = [];
|
|
1697
|
-
var no_duplicate_key_default = createRule({
|
|
1698
|
-
meta: {
|
|
1699
|
-
type: "problem",
|
|
1700
|
-
docs: {
|
|
1701
|
-
description: "Disallow duplicate `key` on elements in the same array or a list of `children`.",
|
|
1702
|
-
[Symbol.for("rule_features")]: RULE_FEATURES28
|
|
1703
|
-
},
|
|
1704
|
-
messages: {
|
|
1705
|
-
noDuplicateKey: "A key must be unique. '{{value}}' is duplicated."
|
|
1706
|
-
},
|
|
1707
|
-
schema: []
|
|
1708
|
-
},
|
|
1709
|
-
name: RULE_NAME28,
|
|
1710
|
-
create: create28,
|
|
1711
|
-
defaultOptions: []
|
|
1712
|
-
});
|
|
1713
|
-
function create28(context) {
|
|
1714
1442
|
if (!context.sourceCode.getText().includes("key=")) {
|
|
1715
1443
|
return {};
|
|
1716
1444
|
}
|
|
@@ -1721,7 +1449,7 @@ function create28(context) {
|
|
|
1721
1449
|
if (aValue == null || bValue == null) {
|
|
1722
1450
|
return false;
|
|
1723
1451
|
}
|
|
1724
|
-
return
|
|
1452
|
+
return AST13.isNodeEqual(aValue, bValue);
|
|
1725
1453
|
}
|
|
1726
1454
|
return {
|
|
1727
1455
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1740,12 +1468,12 @@ function create28(context) {
|
|
|
1740
1468
|
break;
|
|
1741
1469
|
}
|
|
1742
1470
|
default: {
|
|
1743
|
-
const call =
|
|
1744
|
-
const iter =
|
|
1745
|
-
if (!
|
|
1471
|
+
const call = AST13.findParentNode(jsxElement, AST13.isArrayMapCall);
|
|
1472
|
+
const iter = AST13.findParentNode(jsxElement, (n) => n === call || AST13.isFunction(n));
|
|
1473
|
+
if (!AST13.isFunction(iter)) return;
|
|
1746
1474
|
const arg0 = call?.arguments[0];
|
|
1747
1475
|
if (call == null || arg0 == null) return;
|
|
1748
|
-
if (
|
|
1476
|
+
if (AST13.getJSExpression(arg0) !== iter) {
|
|
1749
1477
|
return;
|
|
1750
1478
|
}
|
|
1751
1479
|
keyedEntries.set(call, {
|
|
@@ -1774,8 +1502,8 @@ function create28(context) {
|
|
|
1774
1502
|
}
|
|
1775
1503
|
};
|
|
1776
1504
|
}
|
|
1777
|
-
var
|
|
1778
|
-
var
|
|
1505
|
+
var RULE_NAME28 = "no-forward-ref";
|
|
1506
|
+
var RULE_FEATURES28 = [
|
|
1779
1507
|
"MOD"
|
|
1780
1508
|
];
|
|
1781
1509
|
var no_forward_ref_default = createRule({
|
|
@@ -1783,7 +1511,7 @@ var no_forward_ref_default = createRule({
|
|
|
1783
1511
|
type: "problem",
|
|
1784
1512
|
docs: {
|
|
1785
1513
|
description: "Replaces usages of `forwardRef` with passing `ref` as a prop.",
|
|
1786
|
-
[Symbol.for("rule_features")]:
|
|
1514
|
+
[Symbol.for("rule_features")]: RULE_FEATURES28
|
|
1787
1515
|
},
|
|
1788
1516
|
fixable: "code",
|
|
1789
1517
|
messages: {
|
|
@@ -1791,11 +1519,11 @@ var no_forward_ref_default = createRule({
|
|
|
1791
1519
|
},
|
|
1792
1520
|
schema: []
|
|
1793
1521
|
},
|
|
1794
|
-
name:
|
|
1795
|
-
create:
|
|
1522
|
+
name: RULE_NAME28,
|
|
1523
|
+
create: create28,
|
|
1796
1524
|
defaultOptions: []
|
|
1797
1525
|
});
|
|
1798
|
-
function
|
|
1526
|
+
function create28(context) {
|
|
1799
1527
|
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1800
1528
|
return {};
|
|
1801
1529
|
}
|
|
@@ -1805,10 +1533,10 @@ function create29(context) {
|
|
|
1805
1533
|
}
|
|
1806
1534
|
return {
|
|
1807
1535
|
CallExpression(node) {
|
|
1808
|
-
if (!
|
|
1536
|
+
if (!ER26.isForwardRefCall(context, node)) {
|
|
1809
1537
|
return;
|
|
1810
1538
|
}
|
|
1811
|
-
const id =
|
|
1539
|
+
const id = AST13.getFunctionId(node);
|
|
1812
1540
|
context.report({
|
|
1813
1541
|
messageId: "noForwardRef",
|
|
1814
1542
|
node: id ?? node,
|
|
@@ -1820,7 +1548,7 @@ function create29(context) {
|
|
|
1820
1548
|
function getFix(context, node) {
|
|
1821
1549
|
return (fixer) => {
|
|
1822
1550
|
const [componentNode] = node.arguments;
|
|
1823
|
-
if (componentNode == null || !
|
|
1551
|
+
if (componentNode == null || !AST13.isFunction(componentNode)) {
|
|
1824
1552
|
return [];
|
|
1825
1553
|
}
|
|
1826
1554
|
return [
|
|
@@ -1884,8 +1612,8 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
1884
1612
|
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1885
1613
|
];
|
|
1886
1614
|
}
|
|
1887
|
-
var
|
|
1888
|
-
var
|
|
1615
|
+
var RULE_NAME29 = "no-implicit-key";
|
|
1616
|
+
var RULE_FEATURES29 = [
|
|
1889
1617
|
"EXP"
|
|
1890
1618
|
];
|
|
1891
1619
|
var no_implicit_key_default = createRule({
|
|
@@ -1893,22 +1621,22 @@ var no_implicit_key_default = createRule({
|
|
|
1893
1621
|
type: "problem",
|
|
1894
1622
|
docs: {
|
|
1895
1623
|
description: "Prevents `key` from not being explicitly specified (e.g. spreading `key` from objects).",
|
|
1896
|
-
[Symbol.for("rule_features")]:
|
|
1624
|
+
[Symbol.for("rule_features")]: RULE_FEATURES29
|
|
1897
1625
|
},
|
|
1898
1626
|
messages: {
|
|
1899
1627
|
noImplicitKey: "Do not use implicit 'key' props."
|
|
1900
1628
|
},
|
|
1901
1629
|
schema: []
|
|
1902
1630
|
},
|
|
1903
|
-
name:
|
|
1904
|
-
create:
|
|
1631
|
+
name: RULE_NAME29,
|
|
1632
|
+
create: create29,
|
|
1905
1633
|
defaultOptions: []
|
|
1906
1634
|
});
|
|
1907
|
-
function
|
|
1635
|
+
function create29(context) {
|
|
1908
1636
|
return {
|
|
1909
1637
|
JSXOpeningElement(node) {
|
|
1910
1638
|
const initialScope = context.sourceCode.getScope(node);
|
|
1911
|
-
const keyProp =
|
|
1639
|
+
const keyProp = ER26.getAttribute(context, "key", node.attributes, initialScope);
|
|
1912
1640
|
const isKeyPropOnElement = node.attributes.some(
|
|
1913
1641
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1914
1642
|
);
|
|
@@ -1918,8 +1646,8 @@ function create30(context) {
|
|
|
1918
1646
|
}
|
|
1919
1647
|
};
|
|
1920
1648
|
}
|
|
1921
|
-
var
|
|
1922
|
-
var
|
|
1649
|
+
var RULE_NAME30 = "no-leaked-conditional-rendering";
|
|
1650
|
+
var RULE_FEATURES30 = [
|
|
1923
1651
|
"TSC"
|
|
1924
1652
|
];
|
|
1925
1653
|
var tsHelpers = {
|
|
@@ -2005,18 +1733,18 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
2005
1733
|
type: "problem",
|
|
2006
1734
|
docs: {
|
|
2007
1735
|
description: "Prevents problematic leaked values from being rendered.",
|
|
2008
|
-
[Symbol.for("rule_features")]:
|
|
1736
|
+
[Symbol.for("rule_features")]: RULE_FEATURES30
|
|
2009
1737
|
},
|
|
2010
1738
|
messages: {
|
|
2011
1739
|
noLeakedConditionalRendering: "Potential leaked value {{value}} that might cause unintentionally rendered values or rendering crashes."
|
|
2012
1740
|
},
|
|
2013
1741
|
schema: []
|
|
2014
1742
|
},
|
|
2015
|
-
name:
|
|
2016
|
-
create:
|
|
1743
|
+
name: RULE_NAME30,
|
|
1744
|
+
create: create30,
|
|
2017
1745
|
defaultOptions: []
|
|
2018
1746
|
});
|
|
2019
|
-
function
|
|
1747
|
+
function create30(context) {
|
|
2020
1748
|
if (!context.sourceCode.text.includes("&&")) return {};
|
|
2021
1749
|
const { version: version2 } = getSettingsFromContext(context);
|
|
2022
1750
|
const allowedVariants = [
|
|
@@ -2033,17 +1761,17 @@ function create31(context) {
|
|
|
2033
1761
|
];
|
|
2034
1762
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2035
1763
|
function getReportDescriptor(node) {
|
|
2036
|
-
if (node == null) return
|
|
2037
|
-
if (
|
|
2038
|
-
if (
|
|
2039
|
-
if (
|
|
1764
|
+
if (node == null) return unit;
|
|
1765
|
+
if (AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(node)) return getReportDescriptor(node.expression);
|
|
1766
|
+
if (AST13.isJSX(node)) return unit;
|
|
1767
|
+
if (AST13.isTypeExpression(node)) return getReportDescriptor(node.expression);
|
|
2040
1768
|
return match(node).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
2041
1769
|
const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
2042
1770
|
if (isLeftUnaryNot) {
|
|
2043
1771
|
return getReportDescriptor(right);
|
|
2044
1772
|
}
|
|
2045
1773
|
const initialScope = context.sourceCode.getScope(left);
|
|
2046
|
-
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" ||
|
|
1774
|
+
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR5.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
2047
1775
|
if (isLeftNan) {
|
|
2048
1776
|
return {
|
|
2049
1777
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -2065,44 +1793,44 @@ function create31(context) {
|
|
|
2065
1793
|
}).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
|
|
2066
1794
|
return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
|
|
2067
1795
|
}).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2068
|
-
const variable =
|
|
1796
|
+
const variable = VAR5.findVariable(n.name, context.sourceCode.getScope(n));
|
|
2069
1797
|
const variableDefNode = variable?.defs.at(0)?.node;
|
|
2070
|
-
return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() =>
|
|
2071
|
-
}).otherwise(() =>
|
|
1798
|
+
return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => unit);
|
|
1799
|
+
}).otherwise(() => unit);
|
|
2072
1800
|
}
|
|
2073
1801
|
return {
|
|
2074
1802
|
JSXExpressionContainer: flow(getReportDescriptor, Reporter.make(context).send)
|
|
2075
1803
|
};
|
|
2076
1804
|
}
|
|
2077
|
-
var
|
|
2078
|
-
var
|
|
1805
|
+
var RULE_NAME31 = "no-missing-component-display-name";
|
|
1806
|
+
var RULE_FEATURES31 = [];
|
|
2079
1807
|
var no_missing_component_display_name_default = createRule({
|
|
2080
1808
|
meta: {
|
|
2081
1809
|
type: "problem",
|
|
2082
1810
|
docs: {
|
|
2083
1811
|
description: "Enforces that all components have a `displayName` which can be used in devtools.",
|
|
2084
|
-
[Symbol.for("rule_features")]:
|
|
1812
|
+
[Symbol.for("rule_features")]: RULE_FEATURES31
|
|
2085
1813
|
},
|
|
2086
1814
|
messages: {
|
|
2087
1815
|
noMissingComponentDisplayName: "Add missing 'displayName' for component."
|
|
2088
1816
|
},
|
|
2089
1817
|
schema: []
|
|
2090
1818
|
},
|
|
2091
|
-
name:
|
|
2092
|
-
create:
|
|
1819
|
+
name: RULE_NAME31,
|
|
1820
|
+
create: create31,
|
|
2093
1821
|
defaultOptions: []
|
|
2094
1822
|
});
|
|
2095
|
-
function
|
|
1823
|
+
function create31(context) {
|
|
2096
1824
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
2097
1825
|
const {
|
|
2098
1826
|
ctx,
|
|
2099
1827
|
listeners
|
|
2100
|
-
} =
|
|
1828
|
+
} = ER26.useComponentCollector(
|
|
2101
1829
|
context,
|
|
2102
1830
|
{
|
|
2103
1831
|
collectDisplayName: true,
|
|
2104
1832
|
collectHookCalls: false,
|
|
2105
|
-
hint:
|
|
1833
|
+
hint: ER26.DEFAULT_COMPONENT_DETECTION_HINT
|
|
2106
1834
|
}
|
|
2107
1835
|
);
|
|
2108
1836
|
return {
|
|
@@ -2110,15 +1838,15 @@ function create32(context) {
|
|
|
2110
1838
|
"Program:exit"(program) {
|
|
2111
1839
|
const components = ctx.getAllComponents(program);
|
|
2112
1840
|
for (const { node, displayName, flag } of components.values()) {
|
|
2113
|
-
const isMemoOrForwardRef = (flag & (
|
|
2114
|
-
if (
|
|
1841
|
+
const isMemoOrForwardRef = (flag & (ER26.ComponentFlag.ForwardRef | ER26.ComponentFlag.Memo)) > 0n;
|
|
1842
|
+
if (AST13.getFunctionId(node) != null) {
|
|
2115
1843
|
continue;
|
|
2116
1844
|
}
|
|
2117
1845
|
if (!isMemoOrForwardRef) {
|
|
2118
1846
|
continue;
|
|
2119
1847
|
}
|
|
2120
1848
|
if (displayName == null) {
|
|
2121
|
-
const id =
|
|
1849
|
+
const id = AST13.getFunctionId(node);
|
|
2122
1850
|
context.report({
|
|
2123
1851
|
messageId: "noMissingComponentDisplayName",
|
|
2124
1852
|
node: id ?? node
|
|
@@ -2128,36 +1856,39 @@ function create32(context) {
|
|
|
2128
1856
|
}
|
|
2129
1857
|
};
|
|
2130
1858
|
}
|
|
2131
|
-
var
|
|
2132
|
-
var
|
|
1859
|
+
var RULE_NAME32 = "no-missing-context-display-name";
|
|
1860
|
+
var RULE_FEATURES32 = [
|
|
1861
|
+
"FIX"
|
|
1862
|
+
];
|
|
2133
1863
|
var no_missing_context_display_name_default = createRule({
|
|
2134
1864
|
meta: {
|
|
2135
1865
|
type: "problem",
|
|
2136
1866
|
docs: {
|
|
2137
1867
|
description: "Enforces that all contexts have a `displayName` which can be used in devtools.",
|
|
2138
|
-
[Symbol.for("rule_features")]:
|
|
1868
|
+
[Symbol.for("rule_features")]: RULE_FEATURES32
|
|
2139
1869
|
},
|
|
1870
|
+
fixable: "code",
|
|
2140
1871
|
messages: {
|
|
2141
1872
|
noMissingContextDisplayName: "Add missing 'displayName' for context."
|
|
2142
1873
|
},
|
|
2143
1874
|
schema: []
|
|
2144
1875
|
},
|
|
2145
|
-
name:
|
|
2146
|
-
create:
|
|
1876
|
+
name: RULE_NAME32,
|
|
1877
|
+
create: create32,
|
|
2147
1878
|
defaultOptions: []
|
|
2148
1879
|
});
|
|
2149
|
-
function
|
|
1880
|
+
function create32(context) {
|
|
2150
1881
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
2151
1882
|
const createCalls = [];
|
|
2152
1883
|
const displayNameAssignments = [];
|
|
2153
1884
|
return {
|
|
2154
1885
|
CallExpression(node) {
|
|
2155
|
-
if (!
|
|
1886
|
+
if (!ER26.isCreateContextCall(context, node)) return;
|
|
2156
1887
|
createCalls.push(node);
|
|
2157
1888
|
},
|
|
2158
1889
|
"Program:exit"() {
|
|
2159
1890
|
for (const call of createCalls) {
|
|
2160
|
-
const id =
|
|
1891
|
+
const id = ER26.getInstanceId(call);
|
|
2161
1892
|
if (id == null) {
|
|
2162
1893
|
context.report({
|
|
2163
1894
|
messageId: "noMissingContextDisplayName",
|
|
@@ -2169,12 +1900,30 @@ function create33(context) {
|
|
|
2169
1900
|
const left = node.left;
|
|
2170
1901
|
if (left.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
2171
1902
|
const object = left.object;
|
|
2172
|
-
return
|
|
1903
|
+
return ER26.isInstanceIdEqual(context, id, object);
|
|
2173
1904
|
});
|
|
2174
1905
|
if (!hasDisplayNameAssignment) {
|
|
1906
|
+
const semi = LanguagePreference.defaultLanguagePreference.semicolons === "always" ? ";" : "";
|
|
2175
1907
|
context.report({
|
|
2176
1908
|
messageId: "noMissingContextDisplayName",
|
|
2177
|
-
node: id
|
|
1909
|
+
node: id,
|
|
1910
|
+
fix(fixer) {
|
|
1911
|
+
if (id.type !== AST_NODE_TYPES.Identifier || id.parent !== call.parent) return [];
|
|
1912
|
+
return fixer.insertTextAfter(
|
|
1913
|
+
context.sourceCode.getTokenAfter(call) ?? call,
|
|
1914
|
+
[
|
|
1915
|
+
"\n",
|
|
1916
|
+
id.name,
|
|
1917
|
+
".",
|
|
1918
|
+
"displayName",
|
|
1919
|
+
" ",
|
|
1920
|
+
"=",
|
|
1921
|
+
" ",
|
|
1922
|
+
JSON.stringify(id.name),
|
|
1923
|
+
semi
|
|
1924
|
+
].join("")
|
|
1925
|
+
);
|
|
1926
|
+
}
|
|
2178
1927
|
});
|
|
2179
1928
|
}
|
|
2180
1929
|
}
|
|
@@ -2184,14 +1933,14 @@ function create33(context) {
|
|
|
2184
1933
|
}
|
|
2185
1934
|
};
|
|
2186
1935
|
}
|
|
2187
|
-
var
|
|
2188
|
-
var
|
|
1936
|
+
var RULE_NAME33 = "no-missing-key";
|
|
1937
|
+
var RULE_FEATURES33 = [];
|
|
2189
1938
|
var no_missing_key_default = createRule({
|
|
2190
1939
|
meta: {
|
|
2191
1940
|
type: "problem",
|
|
2192
1941
|
docs: {
|
|
2193
1942
|
description: "Disallow missing `key` on items in list rendering.",
|
|
2194
|
-
[Symbol.for("rule_features")]:
|
|
1943
|
+
[Symbol.for("rule_features")]: RULE_FEATURES33
|
|
2195
1944
|
},
|
|
2196
1945
|
messages: {
|
|
2197
1946
|
missingKey: "Missing 'key' for element when rendering list.",
|
|
@@ -2199,18 +1948,18 @@ var no_missing_key_default = createRule({
|
|
|
2199
1948
|
},
|
|
2200
1949
|
schema: []
|
|
2201
1950
|
},
|
|
2202
|
-
name:
|
|
2203
|
-
create:
|
|
1951
|
+
name: RULE_NAME33,
|
|
1952
|
+
create: create33,
|
|
2204
1953
|
defaultOptions: []
|
|
2205
1954
|
});
|
|
2206
|
-
function
|
|
1955
|
+
function create33(context) {
|
|
2207
1956
|
const report = Reporter.make(context);
|
|
2208
1957
|
const state = { isWithinChildrenToArray: false };
|
|
2209
1958
|
function checkIteratorElement(node) {
|
|
2210
1959
|
switch (node.type) {
|
|
2211
1960
|
case AST_NODE_TYPES.JSXElement: {
|
|
2212
1961
|
const initialScope = context.sourceCode.getScope(node);
|
|
2213
|
-
if (!
|
|
1962
|
+
if (!ER26.hasAttribute(context, "key", node.openingElement.attributes, initialScope)) {
|
|
2214
1963
|
return {
|
|
2215
1964
|
messageId: "missingKey",
|
|
2216
1965
|
node
|
|
@@ -2249,7 +1998,7 @@ function create34(context) {
|
|
|
2249
1998
|
}
|
|
2250
1999
|
function checkBlockStatement(node) {
|
|
2251
2000
|
const descriptors = [];
|
|
2252
|
-
for (const statement of
|
|
2001
|
+
for (const statement of AST13.getNestedReturnStatements(node)) {
|
|
2253
2002
|
if (statement.argument == null) continue;
|
|
2254
2003
|
const descriptor = checkIteratorElement(statement.argument);
|
|
2255
2004
|
if (descriptor != null) descriptors.push(descriptor);
|
|
@@ -2261,13 +2010,13 @@ function create34(context) {
|
|
|
2261
2010
|
if (state.isWithinChildrenToArray) {
|
|
2262
2011
|
return;
|
|
2263
2012
|
}
|
|
2264
|
-
const elements = node.elements.filter(
|
|
2013
|
+
const elements = node.elements.filter(AST13.is(AST_NODE_TYPES.JSXElement));
|
|
2265
2014
|
if (elements.length === 0) {
|
|
2266
2015
|
return;
|
|
2267
2016
|
}
|
|
2268
2017
|
const initialScope = context.sourceCode.getScope(node);
|
|
2269
2018
|
for (const element of elements) {
|
|
2270
|
-
if (!
|
|
2019
|
+
if (!ER26.hasAttribute(context, "key", element.openingElement.attributes, initialScope)) {
|
|
2271
2020
|
report.send({
|
|
2272
2021
|
messageId: "missingKey",
|
|
2273
2022
|
node: element
|
|
@@ -2276,10 +2025,10 @@ function create34(context) {
|
|
|
2276
2025
|
}
|
|
2277
2026
|
},
|
|
2278
2027
|
CallExpression(node) {
|
|
2279
|
-
state.isWithinChildrenToArray ||=
|
|
2028
|
+
state.isWithinChildrenToArray ||= ER26.isChildrenToArrayCall(context, node);
|
|
2280
2029
|
if (state.isWithinChildrenToArray) return;
|
|
2281
|
-
const callback = match(node).when(
|
|
2282
|
-
if (!
|
|
2030
|
+
const callback = match(node).when(AST13.isArrayMapCall, (n) => n.arguments[0]).when(AST13.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
|
|
2031
|
+
if (!AST13.isFunction(callback)) return;
|
|
2283
2032
|
const body = callback.body;
|
|
2284
2033
|
if (body.type === AST_NODE_TYPES.BlockStatement) {
|
|
2285
2034
|
checkBlockStatement(body).forEach(report.send);
|
|
@@ -2288,7 +2037,7 @@ function create34(context) {
|
|
|
2288
2037
|
report.send(checkExpression(body));
|
|
2289
2038
|
},
|
|
2290
2039
|
"CallExpression:exit"(node) {
|
|
2291
|
-
if (!
|
|
2040
|
+
if (!ER26.isChildrenToArrayCall(context, node)) {
|
|
2292
2041
|
return;
|
|
2293
2042
|
}
|
|
2294
2043
|
state.isWithinChildrenToArray = false;
|
|
@@ -2306,8 +2055,8 @@ function create34(context) {
|
|
|
2306
2055
|
}
|
|
2307
2056
|
};
|
|
2308
2057
|
}
|
|
2309
|
-
var
|
|
2310
|
-
var
|
|
2058
|
+
var RULE_NAME34 = "no-misused-capture-owner-stack";
|
|
2059
|
+
var RULE_FEATURES34 = [
|
|
2311
2060
|
"EXP"
|
|
2312
2061
|
];
|
|
2313
2062
|
var no_misused_capture_owner_stack_default = createRule({
|
|
@@ -2315,7 +2064,7 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
2315
2064
|
type: "problem",
|
|
2316
2065
|
docs: {
|
|
2317
2066
|
description: "Prevents incorrect usage of `captureOwnerStack`.",
|
|
2318
|
-
[Symbol.for("rule_features")]:
|
|
2067
|
+
[Symbol.for("rule_features")]: RULE_FEATURES34
|
|
2319
2068
|
},
|
|
2320
2069
|
fixable: "code",
|
|
2321
2070
|
messages: {
|
|
@@ -2325,17 +2074,17 @@ var no_misused_capture_owner_stack_default = createRule({
|
|
|
2325
2074
|
},
|
|
2326
2075
|
schema: []
|
|
2327
2076
|
},
|
|
2328
|
-
name:
|
|
2329
|
-
create:
|
|
2077
|
+
name: RULE_NAME34,
|
|
2078
|
+
create: create34,
|
|
2330
2079
|
defaultOptions: []
|
|
2331
2080
|
});
|
|
2332
|
-
function
|
|
2081
|
+
function create34(context) {
|
|
2333
2082
|
if (!context.sourceCode.text.includes("captureOwnerStack")) return {};
|
|
2334
2083
|
const { importSource } = getSettingsFromContext(context);
|
|
2335
2084
|
return {
|
|
2336
2085
|
CallExpression(node) {
|
|
2337
|
-
if (!
|
|
2338
|
-
if (
|
|
2086
|
+
if (!ER26.isCaptureOwnerStackCall(context, node)) return;
|
|
2087
|
+
if (AST13.findParentNode(node, isDevelopmentOnlyCheck) == null) {
|
|
2339
2088
|
context.report({
|
|
2340
2089
|
messageId: "missingDevelopmentOnlyCheck",
|
|
2341
2090
|
node
|
|
@@ -2359,31 +2108,31 @@ function create35(context) {
|
|
|
2359
2108
|
}
|
|
2360
2109
|
function isDevelopmentOnlyCheck(node) {
|
|
2361
2110
|
if (node.type !== AST_NODE_TYPES.IfStatement) return false;
|
|
2362
|
-
if (
|
|
2111
|
+
if (AST13.isProcessEnvNodeEnvCompare(node.test, "!==", "production")) return true;
|
|
2363
2112
|
return false;
|
|
2364
2113
|
}
|
|
2365
|
-
var
|
|
2366
|
-
var
|
|
2114
|
+
var RULE_NAME35 = "no-nested-component-definitions";
|
|
2115
|
+
var RULE_FEATURES35 = [];
|
|
2367
2116
|
var no_nested_component_definitions_default = createRule({
|
|
2368
2117
|
meta: {
|
|
2369
2118
|
type: "problem",
|
|
2370
2119
|
docs: {
|
|
2371
2120
|
description: "Disallow nesting component definitions inside other components.",
|
|
2372
|
-
[Symbol.for("rule_features")]:
|
|
2121
|
+
[Symbol.for("rule_features")]: RULE_FEATURES35
|
|
2373
2122
|
},
|
|
2374
2123
|
messages: {
|
|
2375
2124
|
noNestedComponentDefinitions: "Do not nest component definitions inside other components or props. {{suggestion}}"
|
|
2376
2125
|
},
|
|
2377
2126
|
schema: []
|
|
2378
2127
|
},
|
|
2379
|
-
name:
|
|
2380
|
-
create:
|
|
2128
|
+
name: RULE_NAME35,
|
|
2129
|
+
create: create35,
|
|
2381
2130
|
defaultOptions: []
|
|
2382
2131
|
});
|
|
2383
|
-
function
|
|
2384
|
-
const hint =
|
|
2385
|
-
const collector =
|
|
2386
|
-
const collectorLegacy =
|
|
2132
|
+
function create35(context) {
|
|
2133
|
+
const hint = ER26.ComponentDetectionHint.SkipArrayMapArgument | ER26.ComponentDetectionHint.SkipNullLiteral | ER26.ComponentDetectionHint.SkipUndefined | ER26.ComponentDetectionHint.SkipBooleanLiteral | ER26.ComponentDetectionHint.SkipStringLiteral | ER26.ComponentDetectionHint.SkipNumberLiteral | ER26.ComponentDetectionHint.StrictLogical | ER26.ComponentDetectionHint.StrictConditional;
|
|
2134
|
+
const collector = ER26.useComponentCollector(context, { hint });
|
|
2135
|
+
const collectorLegacy = ER26.useComponentCollectorLegacy();
|
|
2387
2136
|
return {
|
|
2388
2137
|
...collector.listeners,
|
|
2389
2138
|
...collectorLegacy.listeners,
|
|
@@ -2395,16 +2144,16 @@ function create36(context) {
|
|
|
2395
2144
|
...collectorLegacy.ctx.getAllComponents(program).values()
|
|
2396
2145
|
];
|
|
2397
2146
|
const isFunctionComponent = (node) => {
|
|
2398
|
-
return
|
|
2147
|
+
return AST13.isFunction(node) && functionComponents.some((component) => component.node === node);
|
|
2399
2148
|
};
|
|
2400
|
-
const
|
|
2401
|
-
return
|
|
2149
|
+
const isClassComponent12 = (node) => {
|
|
2150
|
+
return AST13.isClass(node) && classComponents.some((component) => component.node === node);
|
|
2402
2151
|
};
|
|
2403
2152
|
for (const { name: name5, node: component } of functionComponents) {
|
|
2404
2153
|
if (name5 == null) continue;
|
|
2405
|
-
if (
|
|
2154
|
+
if (ER26.isDirectValueOfRenderPropertyLoose(component)) continue;
|
|
2406
2155
|
if (isInsideJSXAttributeValue(component)) {
|
|
2407
|
-
if (!
|
|
2156
|
+
if (!ER26.isDeclaredInRenderPropLoose(component)) {
|
|
2408
2157
|
context.report({
|
|
2409
2158
|
messageId: "noNestedComponentDefinitions",
|
|
2410
2159
|
node: component,
|
|
@@ -2427,8 +2176,8 @@ function create36(context) {
|
|
|
2427
2176
|
});
|
|
2428
2177
|
continue;
|
|
2429
2178
|
}
|
|
2430
|
-
const parentComponent =
|
|
2431
|
-
if (parentComponent != null && !
|
|
2179
|
+
const parentComponent = AST13.findParentNode(component, isFunctionComponent);
|
|
2180
|
+
if (parentComponent != null && !ER26.isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
2432
2181
|
context.report({
|
|
2433
2182
|
messageId: "noNestedComponentDefinitions",
|
|
2434
2183
|
node: component,
|
|
@@ -2451,7 +2200,7 @@ function create36(context) {
|
|
|
2451
2200
|
}
|
|
2452
2201
|
}
|
|
2453
2202
|
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
2454
|
-
if (
|
|
2203
|
+
if (AST13.findParentNode(component, (n) => isClassComponent12(n) || isFunctionComponent(n)) == null) {
|
|
2455
2204
|
continue;
|
|
2456
2205
|
}
|
|
2457
2206
|
context.report({
|
|
@@ -2467,46 +2216,46 @@ function create36(context) {
|
|
|
2467
2216
|
};
|
|
2468
2217
|
}
|
|
2469
2218
|
function isInsideJSXAttributeValue(node) {
|
|
2470
|
-
return node.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
2219
|
+
return node.parent.type === AST_NODE_TYPES.JSXAttribute || ER26.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2471
2220
|
}
|
|
2472
2221
|
function isInsideRenderMethod(node) {
|
|
2473
|
-
return
|
|
2222
|
+
return AST13.findParentNode(node, (n) => ER26.isRenderLike(n) && ER26.isClassComponent(n.parent.parent)) != null;
|
|
2474
2223
|
}
|
|
2475
2224
|
function isInsideCreateElementProps(context, node) {
|
|
2476
|
-
const call =
|
|
2225
|
+
const call = AST13.findParentNode(node, ER26.isCreateElementCall(context));
|
|
2477
2226
|
if (call == null) return false;
|
|
2478
|
-
const prop =
|
|
2227
|
+
const prop = AST13.findParentNode(node, AST13.is(AST_NODE_TYPES.ObjectExpression));
|
|
2479
2228
|
if (prop == null) return false;
|
|
2480
2229
|
return prop === call.arguments[1];
|
|
2481
2230
|
}
|
|
2482
|
-
var
|
|
2483
|
-
var
|
|
2231
|
+
var RULE_NAME36 = "no-nested-component-definitions";
|
|
2232
|
+
var RULE_FEATURES36 = [];
|
|
2484
2233
|
var no_nested_lazy_component_declarations_default = createRule({
|
|
2485
2234
|
meta: {
|
|
2486
2235
|
type: "problem",
|
|
2487
2236
|
docs: {
|
|
2488
2237
|
description: "Disallow nesting lazy component declarations inside other components.",
|
|
2489
|
-
[Symbol.for("rule_features")]:
|
|
2238
|
+
[Symbol.for("rule_features")]: RULE_FEATURES36
|
|
2490
2239
|
},
|
|
2491
2240
|
messages: {
|
|
2492
2241
|
noNestedComponentDefinitions: "Do not declare lazy components inside other components. Instead, always declare them at the top level of your module."
|
|
2493
2242
|
},
|
|
2494
2243
|
schema: []
|
|
2495
2244
|
},
|
|
2496
|
-
name:
|
|
2497
|
-
create:
|
|
2245
|
+
name: RULE_NAME36,
|
|
2246
|
+
create: create36,
|
|
2498
2247
|
defaultOptions: []
|
|
2499
2248
|
});
|
|
2500
|
-
function
|
|
2501
|
-
const hint =
|
|
2502
|
-
const collector =
|
|
2503
|
-
const collectorLegacy =
|
|
2249
|
+
function create36(context) {
|
|
2250
|
+
const hint = ER26.ComponentDetectionHint.None;
|
|
2251
|
+
const collector = ER26.useComponentCollector(context, { hint });
|
|
2252
|
+
const collectorLegacy = ER26.useComponentCollectorLegacy();
|
|
2504
2253
|
const lazyComponentDeclarations = /* @__PURE__ */ new Set();
|
|
2505
2254
|
return {
|
|
2506
2255
|
...collector.listeners,
|
|
2507
2256
|
...collectorLegacy.listeners,
|
|
2508
2257
|
ImportExpression(node) {
|
|
2509
|
-
const lazyCall =
|
|
2258
|
+
const lazyCall = AST13.findParentNode(node, (n) => ER26.isLazyCall(context, n));
|
|
2510
2259
|
if (lazyCall != null) {
|
|
2511
2260
|
lazyComponentDeclarations.add(lazyCall);
|
|
2512
2261
|
}
|
|
@@ -2519,15 +2268,15 @@ function create37(context) {
|
|
|
2519
2268
|
...collectorLegacy.ctx.getAllComponents(program).values()
|
|
2520
2269
|
];
|
|
2521
2270
|
for (const lazy of lazyComponentDeclarations) {
|
|
2522
|
-
const significantParent =
|
|
2523
|
-
if (
|
|
2271
|
+
const significantParent = AST13.findParentNode(lazy, (n) => {
|
|
2272
|
+
if (AST13.isJSX(n)) return true;
|
|
2524
2273
|
if (n.type === AST_NODE_TYPES.CallExpression) {
|
|
2525
|
-
return
|
|
2274
|
+
return ER26.isReactHookCall(n) || ER26.isCreateElementCall(context, n) || ER26.isCreateContextCall(context, n);
|
|
2526
2275
|
}
|
|
2527
|
-
if (
|
|
2276
|
+
if (AST13.isFunction(n)) {
|
|
2528
2277
|
return functionComponents.some((c) => c.node === n);
|
|
2529
2278
|
}
|
|
2530
|
-
if (
|
|
2279
|
+
if (AST13.isClass(n)) {
|
|
2531
2280
|
return classComponents.some((c) => c.node === n);
|
|
2532
2281
|
}
|
|
2533
2282
|
return false;
|
|
@@ -2542,25 +2291,25 @@ function create37(context) {
|
|
|
2542
2291
|
}
|
|
2543
2292
|
};
|
|
2544
2293
|
}
|
|
2545
|
-
var
|
|
2546
|
-
var
|
|
2294
|
+
var RULE_NAME37 = "no-prop-types";
|
|
2295
|
+
var RULE_FEATURES37 = [];
|
|
2547
2296
|
var no_prop_types_default = createRule({
|
|
2548
2297
|
meta: {
|
|
2549
2298
|
type: "problem",
|
|
2550
2299
|
docs: {
|
|
2551
2300
|
description: "Disallow `propTypes` in favor of TypeScript or another type-checking solution.",
|
|
2552
|
-
[Symbol.for("rule_features")]:
|
|
2301
|
+
[Symbol.for("rule_features")]: RULE_FEATURES37
|
|
2553
2302
|
},
|
|
2554
2303
|
messages: {
|
|
2555
2304
|
noPropTypes: "[Deprecated] Use TypeScript or another type-checking solution instead."
|
|
2556
2305
|
},
|
|
2557
2306
|
schema: []
|
|
2558
2307
|
},
|
|
2559
|
-
name:
|
|
2560
|
-
create:
|
|
2308
|
+
name: RULE_NAME37,
|
|
2309
|
+
create: create37,
|
|
2561
2310
|
defaultOptions: []
|
|
2562
2311
|
});
|
|
2563
|
-
function
|
|
2312
|
+
function create37(context) {
|
|
2564
2313
|
if (!context.sourceCode.text.includes("propTypes")) {
|
|
2565
2314
|
return {};
|
|
2566
2315
|
}
|
|
@@ -2576,17 +2325,17 @@ function create38(context) {
|
|
|
2576
2325
|
if (property.type !== AST_NODE_TYPES.Identifier || property.name !== "propTypes") {
|
|
2577
2326
|
return;
|
|
2578
2327
|
}
|
|
2579
|
-
if (!
|
|
2328
|
+
if (!ER26.isComponentNameLoose(object.name)) {
|
|
2580
2329
|
return;
|
|
2581
2330
|
}
|
|
2582
|
-
const variable =
|
|
2583
|
-
const variableNode =
|
|
2584
|
-
if (variableNode != null && (
|
|
2331
|
+
const variable = VAR5.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2332
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2333
|
+
if (variableNode != null && (AST13.isFunction(variableNode) || ER26.isClassComponent(variableNode))) {
|
|
2585
2334
|
context.report({ messageId: "noPropTypes", node: property });
|
|
2586
2335
|
}
|
|
2587
2336
|
},
|
|
2588
2337
|
PropertyDefinition(node) {
|
|
2589
|
-
if (!
|
|
2338
|
+
if (!ER26.isClassComponent(node.parent.parent)) {
|
|
2590
2339
|
return;
|
|
2591
2340
|
}
|
|
2592
2341
|
if (!node.static || node.key.type !== AST_NODE_TYPES.Identifier || node.key.name !== "propTypes") {
|
|
@@ -2596,36 +2345,36 @@ function create38(context) {
|
|
|
2596
2345
|
}
|
|
2597
2346
|
};
|
|
2598
2347
|
}
|
|
2599
|
-
var
|
|
2600
|
-
var
|
|
2348
|
+
var RULE_NAME38 = "no-redundant-should-component-update";
|
|
2349
|
+
var RULE_FEATURES38 = [];
|
|
2601
2350
|
function isShouldComponentUpdate(node) {
|
|
2602
|
-
return
|
|
2351
|
+
return AST13.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
2603
2352
|
}
|
|
2604
2353
|
var no_redundant_should_component_update_default = createRule({
|
|
2605
2354
|
meta: {
|
|
2606
2355
|
type: "problem",
|
|
2607
2356
|
docs: {
|
|
2608
2357
|
description: "Disallow `shouldComponentUpdate` when extending `React.PureComponent`.",
|
|
2609
|
-
[Symbol.for("rule_features")]:
|
|
2358
|
+
[Symbol.for("rule_features")]: RULE_FEATURES38
|
|
2610
2359
|
},
|
|
2611
2360
|
messages: {
|
|
2612
2361
|
noRedundantShouldComponentUpdate: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'."
|
|
2613
2362
|
},
|
|
2614
2363
|
schema: []
|
|
2615
2364
|
},
|
|
2616
|
-
name:
|
|
2617
|
-
create:
|
|
2365
|
+
name: RULE_NAME38,
|
|
2366
|
+
create: create38,
|
|
2618
2367
|
defaultOptions: []
|
|
2619
2368
|
});
|
|
2620
|
-
function
|
|
2369
|
+
function create38(context) {
|
|
2621
2370
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2622
|
-
const { ctx, listeners } =
|
|
2371
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
2623
2372
|
return {
|
|
2624
2373
|
...listeners,
|
|
2625
2374
|
"Program:exit"(program) {
|
|
2626
2375
|
const components = ctx.getAllComponents(program);
|
|
2627
2376
|
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2628
|
-
if ((flag &
|
|
2377
|
+
if ((flag & ER26.ComponentFlag.PureComponent) === 0n) {
|
|
2629
2378
|
continue;
|
|
2630
2379
|
}
|
|
2631
2380
|
const { body } = component.body;
|
|
@@ -2644,33 +2393,33 @@ function create39(context) {
|
|
|
2644
2393
|
}
|
|
2645
2394
|
};
|
|
2646
2395
|
}
|
|
2647
|
-
var
|
|
2648
|
-
var
|
|
2396
|
+
var RULE_NAME39 = "no-set-state-in-component-did-mount";
|
|
2397
|
+
var RULE_FEATURES39 = [];
|
|
2649
2398
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2650
2399
|
meta: {
|
|
2651
2400
|
type: "problem",
|
|
2652
2401
|
docs: {
|
|
2653
2402
|
description: "Disallow calling `this.setState` in `componentDidMount` outside of functions, such as callbacks.",
|
|
2654
|
-
[Symbol.for("rule_features")]:
|
|
2403
|
+
[Symbol.for("rule_features")]: RULE_FEATURES39
|
|
2655
2404
|
},
|
|
2656
2405
|
messages: {
|
|
2657
2406
|
noSetStateInComponentDidMount: "Do not call `this.setState` in `componentDidMount` outside of functions, such as callbacks."
|
|
2658
2407
|
},
|
|
2659
2408
|
schema: []
|
|
2660
2409
|
},
|
|
2661
|
-
name:
|
|
2662
|
-
create:
|
|
2410
|
+
name: RULE_NAME39,
|
|
2411
|
+
create: create39,
|
|
2663
2412
|
defaultOptions: []
|
|
2664
2413
|
});
|
|
2665
|
-
function
|
|
2414
|
+
function create39(context) {
|
|
2666
2415
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2667
2416
|
return {
|
|
2668
2417
|
CallExpression(node) {
|
|
2669
|
-
if (!
|
|
2418
|
+
if (!ER26.isThisSetState(node)) {
|
|
2670
2419
|
return;
|
|
2671
2420
|
}
|
|
2672
|
-
const clazz =
|
|
2673
|
-
const method =
|
|
2421
|
+
const clazz = AST13.findParentNode(node, ER26.isClassComponent);
|
|
2422
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER26.isComponentDidMount(n));
|
|
2674
2423
|
if (clazz == null || method == null || method === clazz) return;
|
|
2675
2424
|
const methodScope = context.sourceCode.getScope(method);
|
|
2676
2425
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2683,33 +2432,33 @@ function create40(context) {
|
|
|
2683
2432
|
}
|
|
2684
2433
|
};
|
|
2685
2434
|
}
|
|
2686
|
-
var
|
|
2687
|
-
var
|
|
2435
|
+
var RULE_NAME40 = "no-set-state-in-component-did-update";
|
|
2436
|
+
var RULE_FEATURES40 = [];
|
|
2688
2437
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2689
2438
|
meta: {
|
|
2690
2439
|
type: "problem",
|
|
2691
2440
|
docs: {
|
|
2692
2441
|
description: "Disallow calling `this.setState` in `componentDidUpdate` outside of functions, such as callbacks.",
|
|
2693
|
-
[Symbol.for("rule_features")]:
|
|
2442
|
+
[Symbol.for("rule_features")]: RULE_FEATURES40
|
|
2694
2443
|
},
|
|
2695
2444
|
messages: {
|
|
2696
2445
|
noSetStateInComponentDidUpdate: "Do not call `this.setState` in `componentDidUpdate` outside of functions, such as callbacks."
|
|
2697
2446
|
},
|
|
2698
2447
|
schema: []
|
|
2699
2448
|
},
|
|
2700
|
-
name:
|
|
2701
|
-
create:
|
|
2449
|
+
name: RULE_NAME40,
|
|
2450
|
+
create: create40,
|
|
2702
2451
|
defaultOptions: []
|
|
2703
2452
|
});
|
|
2704
|
-
function
|
|
2453
|
+
function create40(context) {
|
|
2705
2454
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2706
2455
|
return {
|
|
2707
2456
|
CallExpression(node) {
|
|
2708
|
-
if (!
|
|
2457
|
+
if (!ER26.isThisSetState(node)) {
|
|
2709
2458
|
return;
|
|
2710
2459
|
}
|
|
2711
|
-
const clazz =
|
|
2712
|
-
const method =
|
|
2460
|
+
const clazz = AST13.findParentNode(node, ER26.isClassComponent);
|
|
2461
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER26.isComponentDidUpdate(n));
|
|
2713
2462
|
if (clazz == null || method == null || method === clazz) return;
|
|
2714
2463
|
const methodScope = context.sourceCode.getScope(method);
|
|
2715
2464
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2722,33 +2471,33 @@ function create41(context) {
|
|
|
2722
2471
|
}
|
|
2723
2472
|
};
|
|
2724
2473
|
}
|
|
2725
|
-
var
|
|
2726
|
-
var
|
|
2474
|
+
var RULE_NAME41 = "no-set-state-in-component-will-update";
|
|
2475
|
+
var RULE_FEATURES41 = [];
|
|
2727
2476
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2728
2477
|
meta: {
|
|
2729
2478
|
type: "problem",
|
|
2730
2479
|
docs: {
|
|
2731
2480
|
description: "Disallows calling `this.setState` in `componentWillUpdate` outside of functions, such as callbacks.",
|
|
2732
|
-
[Symbol.for("rule_features")]:
|
|
2481
|
+
[Symbol.for("rule_features")]: RULE_FEATURES41
|
|
2733
2482
|
},
|
|
2734
2483
|
messages: {
|
|
2735
2484
|
noSetStateInComponentWillUpdate: "Do not call `this.setState` in `componentWillUpdate` outside of functions, such as callbacks."
|
|
2736
2485
|
},
|
|
2737
2486
|
schema: []
|
|
2738
2487
|
},
|
|
2739
|
-
name:
|
|
2740
|
-
create:
|
|
2488
|
+
name: RULE_NAME41,
|
|
2489
|
+
create: create41,
|
|
2741
2490
|
defaultOptions: []
|
|
2742
2491
|
});
|
|
2743
|
-
function
|
|
2492
|
+
function create41(context) {
|
|
2744
2493
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2745
2494
|
return {
|
|
2746
2495
|
CallExpression(node) {
|
|
2747
|
-
if (!
|
|
2496
|
+
if (!ER26.isThisSetState(node)) {
|
|
2748
2497
|
return;
|
|
2749
2498
|
}
|
|
2750
|
-
const clazz =
|
|
2751
|
-
const method =
|
|
2499
|
+
const clazz = AST13.findParentNode(node, ER26.isClassComponent);
|
|
2500
|
+
const method = AST13.findParentNode(node, (n) => n === clazz || ER26.isComponentWillUpdate(n));
|
|
2752
2501
|
if (clazz == null || method == null || method === clazz) return;
|
|
2753
2502
|
const methodScope = context.sourceCode.getScope(method);
|
|
2754
2503
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
@@ -2761,8 +2510,8 @@ function create42(context) {
|
|
|
2761
2510
|
}
|
|
2762
2511
|
};
|
|
2763
2512
|
}
|
|
2764
|
-
var
|
|
2765
|
-
var
|
|
2513
|
+
var RULE_NAME42 = "no-string-refs";
|
|
2514
|
+
var RULE_FEATURES42 = [
|
|
2766
2515
|
"MOD"
|
|
2767
2516
|
];
|
|
2768
2517
|
var no_string_refs_default = createRule({
|
|
@@ -2770,7 +2519,7 @@ var no_string_refs_default = createRule({
|
|
|
2770
2519
|
type: "problem",
|
|
2771
2520
|
docs: {
|
|
2772
2521
|
description: "Replaces string refs with callback refs.",
|
|
2773
|
-
[Symbol.for("rule_features")]:
|
|
2522
|
+
[Symbol.for("rule_features")]: RULE_FEATURES42
|
|
2774
2523
|
},
|
|
2775
2524
|
fixable: "code",
|
|
2776
2525
|
messages: {
|
|
@@ -2778,16 +2527,16 @@ var no_string_refs_default = createRule({
|
|
|
2778
2527
|
},
|
|
2779
2528
|
schema: []
|
|
2780
2529
|
},
|
|
2781
|
-
name:
|
|
2782
|
-
create:
|
|
2530
|
+
name: RULE_NAME42,
|
|
2531
|
+
create: create42,
|
|
2783
2532
|
defaultOptions: []
|
|
2784
2533
|
});
|
|
2785
|
-
function
|
|
2534
|
+
function create42(context) {
|
|
2786
2535
|
const state = {
|
|
2787
2536
|
isWithinClassComponent: false
|
|
2788
2537
|
};
|
|
2789
2538
|
function onClassBodyEnter(node) {
|
|
2790
|
-
if (
|
|
2539
|
+
if (ER26.isClassComponent(node.parent)) {
|
|
2791
2540
|
state.isWithinClassComponent = true;
|
|
2792
2541
|
}
|
|
2793
2542
|
}
|
|
@@ -2826,8 +2575,8 @@ function getAttributeValueText(context, node) {
|
|
|
2826
2575
|
return null;
|
|
2827
2576
|
}
|
|
2828
2577
|
}
|
|
2829
|
-
var
|
|
2830
|
-
var
|
|
2578
|
+
var RULE_NAME43 = "no-unnecessary-use-callback";
|
|
2579
|
+
var RULE_FEATURES43 = [
|
|
2831
2580
|
"EXP"
|
|
2832
2581
|
];
|
|
2833
2582
|
var no_unnecessary_use_callback_default = createRule({
|
|
@@ -2835,24 +2584,24 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
2835
2584
|
type: "problem",
|
|
2836
2585
|
docs: {
|
|
2837
2586
|
description: "Disallow unnecessary usage of `useCallback`.",
|
|
2838
|
-
[Symbol.for("rule_features")]:
|
|
2587
|
+
[Symbol.for("rule_features")]: RULE_FEATURES43
|
|
2839
2588
|
},
|
|
2840
2589
|
messages: {
|
|
2841
2590
|
noUnnecessaryUseCallback: "An 'useCallback' with empty deps and no references to the component scope may be unnecessary."
|
|
2842
2591
|
},
|
|
2843
2592
|
schema: []
|
|
2844
2593
|
},
|
|
2845
|
-
name:
|
|
2846
|
-
create:
|
|
2594
|
+
name: RULE_NAME43,
|
|
2595
|
+
create: create43,
|
|
2847
2596
|
defaultOptions: []
|
|
2848
2597
|
});
|
|
2849
|
-
function
|
|
2598
|
+
function create43(context) {
|
|
2850
2599
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
2851
2600
|
const alias = getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
2852
|
-
const isUseCallbackCall =
|
|
2601
|
+
const isUseCallbackCall = ER26.isReactHookCallWithNameAlias(context, "useCallback", alias);
|
|
2853
2602
|
return {
|
|
2854
2603
|
CallExpression(node) {
|
|
2855
|
-
if (!
|
|
2604
|
+
if (!ER26.isReactHookCall(node)) {
|
|
2856
2605
|
return;
|
|
2857
2606
|
}
|
|
2858
2607
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -2861,7 +2610,7 @@ function create44(context) {
|
|
|
2861
2610
|
}
|
|
2862
2611
|
const scope = context.sourceCode.getScope(node);
|
|
2863
2612
|
const component = scope.block;
|
|
2864
|
-
if (!
|
|
2613
|
+
if (!AST13.isFunction(component)) {
|
|
2865
2614
|
return;
|
|
2866
2615
|
}
|
|
2867
2616
|
const [arg0, arg1] = node.arguments;
|
|
@@ -2869,8 +2618,8 @@ function create44(context) {
|
|
|
2869
2618
|
return;
|
|
2870
2619
|
}
|
|
2871
2620
|
const hasEmptyDeps = match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2872
|
-
const variable =
|
|
2873
|
-
const variableNode =
|
|
2621
|
+
const variable = VAR5.findVariable(n.name, initialScope);
|
|
2622
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2874
2623
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) {
|
|
2875
2624
|
return false;
|
|
2876
2625
|
}
|
|
@@ -2885,8 +2634,8 @@ function create44(context) {
|
|
|
2885
2634
|
}
|
|
2886
2635
|
return n;
|
|
2887
2636
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2888
|
-
const variable =
|
|
2889
|
-
const variableNode =
|
|
2637
|
+
const variable = VAR5.findVariable(n.name, initialScope);
|
|
2638
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2890
2639
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) {
|
|
2891
2640
|
return null;
|
|
2892
2641
|
}
|
|
@@ -2894,7 +2643,7 @@ function create44(context) {
|
|
|
2894
2643
|
}).otherwise(() => null);
|
|
2895
2644
|
if (arg0Node == null) return;
|
|
2896
2645
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
2897
|
-
const arg0NodeReferences =
|
|
2646
|
+
const arg0NodeReferences = VAR5.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
2898
2647
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
2899
2648
|
if (!isReferencedToComponentScope) {
|
|
2900
2649
|
context.report({
|
|
@@ -2905,8 +2654,8 @@ function create44(context) {
|
|
|
2905
2654
|
}
|
|
2906
2655
|
};
|
|
2907
2656
|
}
|
|
2908
|
-
var
|
|
2909
|
-
var
|
|
2657
|
+
var RULE_NAME44 = "no-unnecessary-use-memo";
|
|
2658
|
+
var RULE_FEATURES44 = [
|
|
2910
2659
|
"EXP"
|
|
2911
2660
|
];
|
|
2912
2661
|
var no_unnecessary_use_memo_default = createRule({
|
|
@@ -2914,24 +2663,24 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
2914
2663
|
type: "problem",
|
|
2915
2664
|
docs: {
|
|
2916
2665
|
description: "Disallow unnecessary usage of `useMemo`.",
|
|
2917
|
-
[Symbol.for("rule_features")]:
|
|
2666
|
+
[Symbol.for("rule_features")]: RULE_FEATURES44
|
|
2918
2667
|
},
|
|
2919
2668
|
messages: {
|
|
2920
2669
|
noUnnecessaryUseMemo: "An 'useMemo' with empty deps and no references to the component scope may be unnecessary."
|
|
2921
2670
|
},
|
|
2922
2671
|
schema: []
|
|
2923
2672
|
},
|
|
2924
|
-
name:
|
|
2925
|
-
create:
|
|
2673
|
+
name: RULE_NAME44,
|
|
2674
|
+
create: create44,
|
|
2926
2675
|
defaultOptions: []
|
|
2927
2676
|
});
|
|
2928
|
-
function
|
|
2677
|
+
function create44(context) {
|
|
2929
2678
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
2930
2679
|
const alias = getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
2931
|
-
const isUseMemoCall =
|
|
2680
|
+
const isUseMemoCall = ER26.isReactHookCallWithNameAlias(context, "useMemo", alias);
|
|
2932
2681
|
return {
|
|
2933
2682
|
CallExpression(node) {
|
|
2934
|
-
if (!
|
|
2683
|
+
if (!ER26.isReactHookCall(node)) {
|
|
2935
2684
|
return;
|
|
2936
2685
|
}
|
|
2937
2686
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -2940,20 +2689,20 @@ function create45(context) {
|
|
|
2940
2689
|
}
|
|
2941
2690
|
const scope = context.sourceCode.getScope(node);
|
|
2942
2691
|
const component = scope.block;
|
|
2943
|
-
if (!
|
|
2692
|
+
if (!AST13.isFunction(component)) {
|
|
2944
2693
|
return;
|
|
2945
2694
|
}
|
|
2946
2695
|
const [arg0, arg1] = node.arguments;
|
|
2947
2696
|
if (arg0 == null || arg1 == null) {
|
|
2948
2697
|
return;
|
|
2949
2698
|
}
|
|
2950
|
-
const hasCallInArg0 =
|
|
2699
|
+
const hasCallInArg0 = AST13.isFunction(arg0) && [...AST13.getNestedCallExpressions(arg0.body), ...AST13.getNestedNewExpressions(arg0.body)].length > 0;
|
|
2951
2700
|
if (hasCallInArg0) {
|
|
2952
2701
|
return;
|
|
2953
2702
|
}
|
|
2954
2703
|
const hasEmptyDeps = match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2955
|
-
const variable =
|
|
2956
|
-
const variableNode =
|
|
2704
|
+
const variable = VAR5.findVariable(n.name, initialScope);
|
|
2705
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2957
2706
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) {
|
|
2958
2707
|
return false;
|
|
2959
2708
|
}
|
|
@@ -2968,8 +2717,8 @@ function create45(context) {
|
|
|
2968
2717
|
}
|
|
2969
2718
|
return n;
|
|
2970
2719
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
2971
|
-
const variable =
|
|
2972
|
-
const variableNode =
|
|
2720
|
+
const variable = VAR5.findVariable(n.name, initialScope);
|
|
2721
|
+
const variableNode = VAR5.getVariableInitNode(variable, 0);
|
|
2973
2722
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) {
|
|
2974
2723
|
return null;
|
|
2975
2724
|
}
|
|
@@ -2977,7 +2726,7 @@ function create45(context) {
|
|
|
2977
2726
|
}).otherwise(() => null);
|
|
2978
2727
|
if (arg0Node == null) return;
|
|
2979
2728
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
2980
|
-
const arg0NodeReferences =
|
|
2729
|
+
const arg0NodeReferences = VAR5.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
2981
2730
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
2982
2731
|
if (!isReferencedToComponentScope) {
|
|
2983
2732
|
context.report({
|
|
@@ -2988,8 +2737,8 @@ function create45(context) {
|
|
|
2988
2737
|
}
|
|
2989
2738
|
};
|
|
2990
2739
|
}
|
|
2991
|
-
var
|
|
2992
|
-
var
|
|
2740
|
+
var RULE_NAME45 = "no-unnecessary-use-prefix";
|
|
2741
|
+
var RULE_FEATURES45 = [];
|
|
2993
2742
|
var WELL_KNOWN_HOOKS = [
|
|
2994
2743
|
"useMDXComponents"
|
|
2995
2744
|
];
|
|
@@ -3001,19 +2750,19 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
3001
2750
|
type: "problem",
|
|
3002
2751
|
docs: {
|
|
3003
2752
|
description: "Enforces that a function with the `use` prefix should use at least one Hook inside of it.",
|
|
3004
|
-
[Symbol.for("rule_features")]:
|
|
2753
|
+
[Symbol.for("rule_features")]: RULE_FEATURES45
|
|
3005
2754
|
},
|
|
3006
2755
|
messages: {
|
|
3007
2756
|
noUnnecessaryUsePrefix: "If your function doesn't call any Hooks, avoid the 'use' prefix. Instead, write it as a regular function without the 'use' prefix."
|
|
3008
2757
|
},
|
|
3009
2758
|
schema: []
|
|
3010
2759
|
},
|
|
3011
|
-
name:
|
|
3012
|
-
create:
|
|
2760
|
+
name: RULE_NAME45,
|
|
2761
|
+
create: create45,
|
|
3013
2762
|
defaultOptions: []
|
|
3014
2763
|
});
|
|
3015
|
-
function
|
|
3016
|
-
const { ctx, listeners } =
|
|
2764
|
+
function create45(context) {
|
|
2765
|
+
const { ctx, listeners } = ER26.useHookCollector();
|
|
3017
2766
|
return {
|
|
3018
2767
|
...listeners,
|
|
3019
2768
|
"Program:exit"(program) {
|
|
@@ -3022,7 +2771,7 @@ function create46(context) {
|
|
|
3022
2771
|
if (WELL_KNOWN_HOOKS.includes(name5)) {
|
|
3023
2772
|
continue;
|
|
3024
2773
|
}
|
|
3025
|
-
if (
|
|
2774
|
+
if (AST13.isEmptyFunction(node)) {
|
|
3026
2775
|
continue;
|
|
3027
2776
|
}
|
|
3028
2777
|
if (hookCalls.length > 0) {
|
|
@@ -3053,7 +2802,7 @@ function create46(context) {
|
|
|
3053
2802
|
};
|
|
3054
2803
|
}
|
|
3055
2804
|
function getPreferredLoc(context, id) {
|
|
3056
|
-
if (
|
|
2805
|
+
if (AST13.isMultiLine(id)) return id.loc;
|
|
3057
2806
|
if (!context.sourceCode.getText(id).startsWith("use")) return id.loc;
|
|
3058
2807
|
return {
|
|
3059
2808
|
end: {
|
|
@@ -3066,27 +2815,27 @@ function getPreferredLoc(context, id) {
|
|
|
3066
2815
|
}
|
|
3067
2816
|
};
|
|
3068
2817
|
}
|
|
3069
|
-
var
|
|
3070
|
-
var
|
|
2818
|
+
var RULE_NAME46 = "no-unsafe-component-will-mount";
|
|
2819
|
+
var RULE_FEATURES46 = [];
|
|
3071
2820
|
var no_unsafe_component_will_mount_default = createRule({
|
|
3072
2821
|
meta: {
|
|
3073
2822
|
type: "problem",
|
|
3074
2823
|
docs: {
|
|
3075
2824
|
description: "Warns the usage of `UNSAFE_componentWillMount` in class components.",
|
|
3076
|
-
[Symbol.for("rule_features")]:
|
|
2825
|
+
[Symbol.for("rule_features")]: RULE_FEATURES46
|
|
3077
2826
|
},
|
|
3078
2827
|
messages: {
|
|
3079
2828
|
noUnsafeComponentWillMount: "Do not use 'UNSAFE_componentWillMount'."
|
|
3080
2829
|
},
|
|
3081
2830
|
schema: []
|
|
3082
2831
|
},
|
|
3083
|
-
name:
|
|
3084
|
-
create:
|
|
2832
|
+
name: RULE_NAME46,
|
|
2833
|
+
create: create46,
|
|
3085
2834
|
defaultOptions: []
|
|
3086
2835
|
});
|
|
3087
|
-
function
|
|
2836
|
+
function create46(context) {
|
|
3088
2837
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
3089
|
-
const { ctx, listeners } =
|
|
2838
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
3090
2839
|
return {
|
|
3091
2840
|
...listeners,
|
|
3092
2841
|
"Program:exit"(program) {
|
|
@@ -3094,7 +2843,7 @@ function create47(context) {
|
|
|
3094
2843
|
for (const { node: component } of components.values()) {
|
|
3095
2844
|
const { body } = component.body;
|
|
3096
2845
|
for (const member of body) {
|
|
3097
|
-
if (
|
|
2846
|
+
if (ER26.isUnsafeComponentWillMount(member)) {
|
|
3098
2847
|
context.report({
|
|
3099
2848
|
messageId: "noUnsafeComponentWillMount",
|
|
3100
2849
|
node: member
|
|
@@ -3105,29 +2854,29 @@ function create47(context) {
|
|
|
3105
2854
|
}
|
|
3106
2855
|
};
|
|
3107
2856
|
}
|
|
3108
|
-
var
|
|
3109
|
-
var
|
|
2857
|
+
var RULE_NAME47 = "no-unsafe-component-will-receive-props";
|
|
2858
|
+
var RULE_FEATURES47 = [];
|
|
3110
2859
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
3111
2860
|
meta: {
|
|
3112
2861
|
type: "problem",
|
|
3113
2862
|
docs: {
|
|
3114
2863
|
description: "Warns the usage of `UNSAFE_componentWillReceiveProps` in class components.",
|
|
3115
|
-
[Symbol.for("rule_features")]:
|
|
2864
|
+
[Symbol.for("rule_features")]: RULE_FEATURES47
|
|
3116
2865
|
},
|
|
3117
2866
|
messages: {
|
|
3118
2867
|
noUnsafeComponentWillReceiveProps: "Do not use 'UNSAFE_componentWillReceiveProps'."
|
|
3119
2868
|
},
|
|
3120
2869
|
schema: []
|
|
3121
2870
|
},
|
|
3122
|
-
name:
|
|
3123
|
-
create:
|
|
2871
|
+
name: RULE_NAME47,
|
|
2872
|
+
create: create47,
|
|
3124
2873
|
defaultOptions: []
|
|
3125
2874
|
});
|
|
3126
|
-
function
|
|
2875
|
+
function create47(context) {
|
|
3127
2876
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
3128
2877
|
return {};
|
|
3129
2878
|
}
|
|
3130
|
-
const { ctx, listeners } =
|
|
2879
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
3131
2880
|
return {
|
|
3132
2881
|
...listeners,
|
|
3133
2882
|
"Program:exit"(program) {
|
|
@@ -3135,7 +2884,7 @@ function create48(context) {
|
|
|
3135
2884
|
for (const { node: component } of components.values()) {
|
|
3136
2885
|
const { body } = component.body;
|
|
3137
2886
|
for (const member of body) {
|
|
3138
|
-
if (
|
|
2887
|
+
if (ER26.isUnsafeComponentWillReceiveProps(member)) {
|
|
3139
2888
|
context.report({
|
|
3140
2889
|
messageId: "noUnsafeComponentWillReceiveProps",
|
|
3141
2890
|
node: member
|
|
@@ -3146,27 +2895,27 @@ function create48(context) {
|
|
|
3146
2895
|
}
|
|
3147
2896
|
};
|
|
3148
2897
|
}
|
|
3149
|
-
var
|
|
3150
|
-
var
|
|
2898
|
+
var RULE_NAME48 = "no-unsafe-component-will-update";
|
|
2899
|
+
var RULE_FEATURES48 = [];
|
|
3151
2900
|
var no_unsafe_component_will_update_default = createRule({
|
|
3152
2901
|
meta: {
|
|
3153
2902
|
type: "problem",
|
|
3154
2903
|
docs: {
|
|
3155
2904
|
description: "Warns the usage of `UNSAFE_componentWillUpdate` in class components.",
|
|
3156
|
-
[Symbol.for("rule_features")]:
|
|
2905
|
+
[Symbol.for("rule_features")]: RULE_FEATURES48
|
|
3157
2906
|
},
|
|
3158
2907
|
messages: {
|
|
3159
2908
|
noUnsafeComponentWillUpdate: "Do not use 'UNSAFE_componentWillUpdate'."
|
|
3160
2909
|
},
|
|
3161
2910
|
schema: []
|
|
3162
2911
|
},
|
|
3163
|
-
name:
|
|
3164
|
-
create:
|
|
2912
|
+
name: RULE_NAME48,
|
|
2913
|
+
create: create48,
|
|
3165
2914
|
defaultOptions: []
|
|
3166
2915
|
});
|
|
3167
|
-
function
|
|
2916
|
+
function create48(context) {
|
|
3168
2917
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
3169
|
-
const { ctx, listeners } =
|
|
2918
|
+
const { ctx, listeners } = ER26.useComponentCollectorLegacy();
|
|
3170
2919
|
return {
|
|
3171
2920
|
...listeners,
|
|
3172
2921
|
"Program:exit"(program) {
|
|
@@ -3174,7 +2923,7 @@ function create49(context) {
|
|
|
3174
2923
|
for (const { node: component } of components.values()) {
|
|
3175
2924
|
const { body } = component.body;
|
|
3176
2925
|
for (const member of body) {
|
|
3177
|
-
if (
|
|
2926
|
+
if (ER26.isUnsafeComponentWillUpdate(member)) {
|
|
3178
2927
|
context.report({
|
|
3179
2928
|
messageId: "noUnsafeComponentWillUpdate",
|
|
3180
2929
|
node: member
|
|
@@ -3185,33 +2934,33 @@ function create49(context) {
|
|
|
3185
2934
|
}
|
|
3186
2935
|
};
|
|
3187
2936
|
}
|
|
3188
|
-
var
|
|
3189
|
-
var
|
|
2937
|
+
var RULE_NAME49 = "no-unstable-context-value";
|
|
2938
|
+
var RULE_FEATURES49 = [];
|
|
3190
2939
|
var no_unstable_context_value_default = createRule({
|
|
3191
2940
|
meta: {
|
|
3192
2941
|
type: "problem",
|
|
3193
2942
|
docs: {
|
|
3194
2943
|
description: "Prevents non-stable values (i.e. object literals) from being used as a value for `Context.Provider`.",
|
|
3195
|
-
[Symbol.for("rule_features")]:
|
|
2944
|
+
[Symbol.for("rule_features")]: RULE_FEATURES49
|
|
3196
2945
|
},
|
|
3197
2946
|
messages: {
|
|
3198
2947
|
unstableContextValue: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}"
|
|
3199
2948
|
},
|
|
3200
2949
|
schema: []
|
|
3201
2950
|
},
|
|
3202
|
-
name:
|
|
3203
|
-
create:
|
|
2951
|
+
name: RULE_NAME49,
|
|
2952
|
+
create: create49,
|
|
3204
2953
|
defaultOptions: []
|
|
3205
2954
|
});
|
|
3206
|
-
function
|
|
2955
|
+
function create49(context) {
|
|
3207
2956
|
const { version: version2 } = getSettingsFromContext(context);
|
|
3208
2957
|
const isReact18OrBelow = compare(version2, "19.0.0", "<");
|
|
3209
|
-
const { ctx, listeners } =
|
|
2958
|
+
const { ctx, listeners } = ER26.useComponentCollector(context);
|
|
3210
2959
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
3211
2960
|
return {
|
|
3212
2961
|
...listeners,
|
|
3213
2962
|
JSXOpeningElement(node) {
|
|
3214
|
-
const fullName =
|
|
2963
|
+
const fullName = ER26.getElementType(context, node.parent);
|
|
3215
2964
|
const selfName = fullName.split(".").at(-1);
|
|
3216
2965
|
if (selfName == null) return;
|
|
3217
2966
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
@@ -3225,9 +2974,9 @@ function create50(context) {
|
|
|
3225
2974
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
3226
2975
|
const valueExpression = value.expression;
|
|
3227
2976
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
3228
|
-
const construction =
|
|
2977
|
+
const construction = VAR5.getConstruction(valueExpression, initialScope);
|
|
3229
2978
|
if (construction == null) return;
|
|
3230
|
-
if (
|
|
2979
|
+
if (ER26.isReactHookCall(construction.node)) {
|
|
3231
2980
|
return;
|
|
3232
2981
|
}
|
|
3233
2982
|
getOrElseUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
@@ -3242,7 +2991,7 @@ function create50(context) {
|
|
|
3242
2991
|
messageId: "unstableContextValue",
|
|
3243
2992
|
node: constructionNode,
|
|
3244
2993
|
data: {
|
|
3245
|
-
type:
|
|
2994
|
+
type: AST13.toDelimiterFormat(constructionNode),
|
|
3246
2995
|
suggestion
|
|
3247
2996
|
}
|
|
3248
2997
|
});
|
|
@@ -3258,26 +3007,26 @@ function isContextName(name5, isReact18OrBelow) {
|
|
|
3258
3007
|
}
|
|
3259
3008
|
return false;
|
|
3260
3009
|
}
|
|
3261
|
-
var
|
|
3262
|
-
var
|
|
3010
|
+
var RULE_NAME50 = "no-unstable-default-props";
|
|
3011
|
+
var RULE_FEATURES50 = [];
|
|
3263
3012
|
var no_unstable_default_props_default = createRule({
|
|
3264
3013
|
meta: {
|
|
3265
3014
|
type: "problem",
|
|
3266
3015
|
docs: {
|
|
3267
3016
|
description: "Prevents using referential-type values as default props in object destructuring.",
|
|
3268
|
-
[Symbol.for("rule_features")]:
|
|
3017
|
+
[Symbol.for("rule_features")]: RULE_FEATURES50
|
|
3269
3018
|
},
|
|
3270
3019
|
messages: {
|
|
3271
3020
|
noUnstableDefaultProps: "A/an '{{forbiddenType}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{forbiddenType}}'."
|
|
3272
3021
|
},
|
|
3273
3022
|
schema: []
|
|
3274
3023
|
},
|
|
3275
|
-
name:
|
|
3276
|
-
create:
|
|
3024
|
+
name: RULE_NAME50,
|
|
3025
|
+
create: create50,
|
|
3277
3026
|
defaultOptions: []
|
|
3278
3027
|
});
|
|
3279
|
-
function
|
|
3280
|
-
const { ctx, listeners } =
|
|
3028
|
+
function create50(context) {
|
|
3029
|
+
const { ctx, listeners } = ER26.useComponentCollector(context);
|
|
3281
3030
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3282
3031
|
return {
|
|
3283
3032
|
...listeners,
|
|
@@ -3299,18 +3048,18 @@ function create51(context) {
|
|
|
3299
3048
|
const { value } = prop;
|
|
3300
3049
|
const { right } = value;
|
|
3301
3050
|
const initialScope = context.sourceCode.getScope(value);
|
|
3302
|
-
const construction =
|
|
3051
|
+
const construction = VAR5.getConstruction(
|
|
3303
3052
|
value,
|
|
3304
3053
|
initialScope,
|
|
3305
|
-
|
|
3054
|
+
VAR5.ConstructionDetectionHint.StrictCallExpression
|
|
3306
3055
|
);
|
|
3307
3056
|
if (construction == null) {
|
|
3308
3057
|
continue;
|
|
3309
3058
|
}
|
|
3310
|
-
if (
|
|
3059
|
+
if (ER26.isReactHookCall(construction.node)) {
|
|
3311
3060
|
continue;
|
|
3312
3061
|
}
|
|
3313
|
-
const forbiddenType =
|
|
3062
|
+
const forbiddenType = AST13.toDelimiterFormat(right);
|
|
3314
3063
|
context.report({
|
|
3315
3064
|
messageId: "noUnstableDefaultProps",
|
|
3316
3065
|
node: right,
|
|
@@ -3332,8 +3081,8 @@ function create51(context) {
|
|
|
3332
3081
|
}
|
|
3333
3082
|
};
|
|
3334
3083
|
}
|
|
3335
|
-
var
|
|
3336
|
-
var
|
|
3084
|
+
var RULE_NAME51 = "no-unused-class-component-members";
|
|
3085
|
+
var RULE_FEATURES51 = [];
|
|
3337
3086
|
var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
3338
3087
|
"componentDidCatch",
|
|
3339
3088
|
"componentDidMount",
|
|
@@ -3359,25 +3108,25 @@ var no_unused_class_component_members_default = createRule({
|
|
|
3359
3108
|
type: "problem",
|
|
3360
3109
|
docs: {
|
|
3361
3110
|
description: "Warns unused class component methods and properties.",
|
|
3362
|
-
[Symbol.for("rule_features")]:
|
|
3111
|
+
[Symbol.for("rule_features")]: RULE_FEATURES51
|
|
3363
3112
|
},
|
|
3364
3113
|
messages: {
|
|
3365
3114
|
noUnusedClassComponentMembers: "Unused method or property '{{methodName}}'' of class '{{className}}'."
|
|
3366
3115
|
},
|
|
3367
3116
|
schema: []
|
|
3368
3117
|
},
|
|
3369
|
-
name:
|
|
3370
|
-
create:
|
|
3118
|
+
name: RULE_NAME51,
|
|
3119
|
+
create: create51,
|
|
3371
3120
|
defaultOptions: []
|
|
3372
3121
|
});
|
|
3373
|
-
function
|
|
3122
|
+
function create51(context) {
|
|
3374
3123
|
const classEntries = [];
|
|
3375
3124
|
const methodEntries = [];
|
|
3376
3125
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
3377
3126
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
3378
3127
|
function classEnter(node) {
|
|
3379
3128
|
classEntries.push(node);
|
|
3380
|
-
if (!
|
|
3129
|
+
if (!ER26.isClassComponent(node)) {
|
|
3381
3130
|
return;
|
|
3382
3131
|
}
|
|
3383
3132
|
propertyDefs.set(node, /* @__PURE__ */ new Set());
|
|
@@ -3385,17 +3134,17 @@ function create52(context) {
|
|
|
3385
3134
|
}
|
|
3386
3135
|
function classExit() {
|
|
3387
3136
|
const currentClass = classEntries.pop();
|
|
3388
|
-
if (currentClass == null || !
|
|
3137
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3389
3138
|
return;
|
|
3390
3139
|
}
|
|
3391
|
-
const className =
|
|
3140
|
+
const className = AST13.getClassId(currentClass)?.name;
|
|
3392
3141
|
const defs = propertyDefs.get(currentClass);
|
|
3393
3142
|
const usages = propertyUsages.get(currentClass);
|
|
3394
3143
|
if (defs == null) {
|
|
3395
3144
|
return;
|
|
3396
3145
|
}
|
|
3397
3146
|
for (const def of defs) {
|
|
3398
|
-
const methodName =
|
|
3147
|
+
const methodName = AST13.getPropertyName(def);
|
|
3399
3148
|
if (methodName == null) {
|
|
3400
3149
|
continue;
|
|
3401
3150
|
}
|
|
@@ -3415,7 +3164,7 @@ function create52(context) {
|
|
|
3415
3164
|
function methodEnter(node) {
|
|
3416
3165
|
methodEntries.push(node);
|
|
3417
3166
|
const currentClass = classEntries.at(-1);
|
|
3418
|
-
if (currentClass == null || !
|
|
3167
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3419
3168
|
return;
|
|
3420
3169
|
}
|
|
3421
3170
|
if (node.static) {
|
|
@@ -3439,17 +3188,17 @@ function create52(context) {
|
|
|
3439
3188
|
if (currentClass == null || currentMethod == null) {
|
|
3440
3189
|
return;
|
|
3441
3190
|
}
|
|
3442
|
-
if (!
|
|
3191
|
+
if (!ER26.isClassComponent(currentClass) || currentMethod.static) {
|
|
3443
3192
|
return;
|
|
3444
3193
|
}
|
|
3445
|
-
if (!
|
|
3194
|
+
if (!AST13.isThisExpression(node.object) || !isKeyLiteral2(node, node.property)) {
|
|
3446
3195
|
return;
|
|
3447
3196
|
}
|
|
3448
3197
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
3449
3198
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
3450
3199
|
return;
|
|
3451
3200
|
}
|
|
3452
|
-
const propertyName =
|
|
3201
|
+
const propertyName = AST13.getPropertyName(node.property);
|
|
3453
3202
|
if (propertyName != null) {
|
|
3454
3203
|
propertyUsages.get(currentClass)?.add(propertyName);
|
|
3455
3204
|
}
|
|
@@ -3464,13 +3213,13 @@ function create52(context) {
|
|
|
3464
3213
|
if (currentClass == null || currentMethod == null) {
|
|
3465
3214
|
return;
|
|
3466
3215
|
}
|
|
3467
|
-
if (!
|
|
3216
|
+
if (!ER26.isClassComponent(currentClass) || currentMethod.static) {
|
|
3468
3217
|
return;
|
|
3469
3218
|
}
|
|
3470
|
-
if (node.init != null &&
|
|
3219
|
+
if (node.init != null && AST13.isThisExpression(node.init) && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
3471
3220
|
for (const prop of node.id.properties) {
|
|
3472
3221
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral2(prop, prop.key)) {
|
|
3473
|
-
const keyName =
|
|
3222
|
+
const keyName = AST13.getPropertyName(prop.key);
|
|
3474
3223
|
if (keyName != null) {
|
|
3475
3224
|
propertyUsages.get(currentClass)?.add(keyName);
|
|
3476
3225
|
}
|
|
@@ -3480,8 +3229,8 @@ function create52(context) {
|
|
|
3480
3229
|
}
|
|
3481
3230
|
};
|
|
3482
3231
|
}
|
|
3483
|
-
var
|
|
3484
|
-
var
|
|
3232
|
+
var RULE_NAME52 = "no-unused-state";
|
|
3233
|
+
var RULE_FEATURES52 = [];
|
|
3485
3234
|
function isKeyLiteral3(node, key) {
|
|
3486
3235
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({ type: AST_NODE_TYPES.TemplateLiteral, expressions: [] }, constTrue).with({ type: AST_NODE_TYPES.Identifier }, () => !node.computed).otherwise(constFalse);
|
|
3487
3236
|
}
|
|
@@ -3490,18 +3239,18 @@ var no_unused_state_default = createRule({
|
|
|
3490
3239
|
type: "problem",
|
|
3491
3240
|
docs: {
|
|
3492
3241
|
description: "Warns unused class component state.",
|
|
3493
|
-
[Symbol.for("rule_features")]:
|
|
3242
|
+
[Symbol.for("rule_features")]: RULE_FEATURES52
|
|
3494
3243
|
},
|
|
3495
3244
|
messages: {
|
|
3496
3245
|
noUnusedState: "Unused class component state in '{{className}}'"
|
|
3497
3246
|
},
|
|
3498
3247
|
schema: []
|
|
3499
3248
|
},
|
|
3500
|
-
name:
|
|
3501
|
-
create:
|
|
3249
|
+
name: RULE_NAME52,
|
|
3250
|
+
create: create52,
|
|
3502
3251
|
defaultOptions: []
|
|
3503
3252
|
});
|
|
3504
|
-
function
|
|
3253
|
+
function create52(context) {
|
|
3505
3254
|
const classEntries = [];
|
|
3506
3255
|
const methodEntries = [];
|
|
3507
3256
|
const constructorEntries = [];
|
|
@@ -3511,10 +3260,10 @@ function create53(context) {
|
|
|
3511
3260
|
}
|
|
3512
3261
|
function classExit() {
|
|
3513
3262
|
const currentClass = classEntries.pop();
|
|
3514
|
-
if (currentClass == null || !
|
|
3263
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3515
3264
|
return;
|
|
3516
3265
|
}
|
|
3517
|
-
const className =
|
|
3266
|
+
const className = AST13.getClassId(currentClass)?.name;
|
|
3518
3267
|
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
3519
3268
|
if (defNode == null || isUsed) {
|
|
3520
3269
|
return;
|
|
@@ -3530,17 +3279,17 @@ function create53(context) {
|
|
|
3530
3279
|
function methodEnter(node) {
|
|
3531
3280
|
methodEntries.push(node);
|
|
3532
3281
|
const currentClass = classEntries.at(-1);
|
|
3533
|
-
if (currentClass == null || !
|
|
3282
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3534
3283
|
return;
|
|
3535
3284
|
}
|
|
3536
3285
|
if (node.static) {
|
|
3537
|
-
if (
|
|
3286
|
+
if (ER26.isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
3538
3287
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
3539
3288
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
3540
3289
|
}
|
|
3541
3290
|
return;
|
|
3542
3291
|
}
|
|
3543
|
-
if (
|
|
3292
|
+
if (AST13.getPropertyName(node.key) === "state") {
|
|
3544
3293
|
stateDefs.set(currentClass, { node: node.key, isUsed: false });
|
|
3545
3294
|
}
|
|
3546
3295
|
}
|
|
@@ -3555,11 +3304,11 @@ function create53(context) {
|
|
|
3555
3304
|
}
|
|
3556
3305
|
return {
|
|
3557
3306
|
AssignmentExpression(node) {
|
|
3558
|
-
if (!
|
|
3307
|
+
if (!ER26.isAssignmentToThisState(node)) {
|
|
3559
3308
|
return;
|
|
3560
3309
|
}
|
|
3561
3310
|
const currentClass = classEntries.at(-1);
|
|
3562
|
-
if (currentClass == null || !
|
|
3311
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3563
3312
|
return;
|
|
3564
3313
|
}
|
|
3565
3314
|
const currentConstructor = constructorEntries.at(-1);
|
|
@@ -3574,14 +3323,14 @@ function create53(context) {
|
|
|
3574
3323
|
ClassExpression: classEnter,
|
|
3575
3324
|
"ClassExpression:exit": classExit,
|
|
3576
3325
|
MemberExpression(node) {
|
|
3577
|
-
if (!
|
|
3326
|
+
if (!AST13.isThisExpression(node.object)) {
|
|
3578
3327
|
return;
|
|
3579
3328
|
}
|
|
3580
|
-
if (
|
|
3329
|
+
if (AST13.getPropertyName(node.property) !== "state") {
|
|
3581
3330
|
return;
|
|
3582
3331
|
}
|
|
3583
3332
|
const currentClass = classEntries.at(-1);
|
|
3584
|
-
if (currentClass == null || !
|
|
3333
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3585
3334
|
return;
|
|
3586
3335
|
}
|
|
3587
3336
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3605,7 +3354,7 @@ function create53(context) {
|
|
|
3605
3354
|
"PropertyDefinition:exit": methodExit,
|
|
3606
3355
|
VariableDeclarator(node) {
|
|
3607
3356
|
const currentClass = classEntries.at(-1);
|
|
3608
|
-
if (currentClass == null || !
|
|
3357
|
+
if (currentClass == null || !ER26.isClassComponent(currentClass)) {
|
|
3609
3358
|
return;
|
|
3610
3359
|
}
|
|
3611
3360
|
const currentMethod = methodEntries.at(-1);
|
|
@@ -3618,12 +3367,12 @@ function create53(context) {
|
|
|
3618
3367
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
3619
3368
|
return;
|
|
3620
3369
|
}
|
|
3621
|
-
if (node.init == null || !
|
|
3370
|
+
if (node.init == null || !AST13.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
3622
3371
|
return;
|
|
3623
3372
|
}
|
|
3624
3373
|
const hasState = node.id.properties.some((prop) => {
|
|
3625
3374
|
if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral3(prop, prop.key)) {
|
|
3626
|
-
return
|
|
3375
|
+
return AST13.getPropertyName(prop.key) === "state";
|
|
3627
3376
|
}
|
|
3628
3377
|
return false;
|
|
3629
3378
|
});
|
|
@@ -3635,8 +3384,8 @@ function create53(context) {
|
|
|
3635
3384
|
}
|
|
3636
3385
|
};
|
|
3637
3386
|
}
|
|
3638
|
-
var
|
|
3639
|
-
var
|
|
3387
|
+
var RULE_NAME53 = "no-use-context";
|
|
3388
|
+
var RULE_FEATURES53 = [
|
|
3640
3389
|
"MOD"
|
|
3641
3390
|
];
|
|
3642
3391
|
var no_use_context_default = createRule({
|
|
@@ -3644,7 +3393,7 @@ var no_use_context_default = createRule({
|
|
|
3644
3393
|
type: "problem",
|
|
3645
3394
|
docs: {
|
|
3646
3395
|
description: "Replaces usages of `useContext` with `use`.",
|
|
3647
|
-
[Symbol.for("rule_features")]:
|
|
3396
|
+
[Symbol.for("rule_features")]: RULE_FEATURES53
|
|
3648
3397
|
},
|
|
3649
3398
|
fixable: "code",
|
|
3650
3399
|
messages: {
|
|
@@ -3652,11 +3401,11 @@ var no_use_context_default = createRule({
|
|
|
3652
3401
|
},
|
|
3653
3402
|
schema: []
|
|
3654
3403
|
},
|
|
3655
|
-
name:
|
|
3656
|
-
create:
|
|
3404
|
+
name: RULE_NAME53,
|
|
3405
|
+
create: create53,
|
|
3657
3406
|
defaultOptions: []
|
|
3658
3407
|
});
|
|
3659
|
-
function
|
|
3408
|
+
function create53(context) {
|
|
3660
3409
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
3661
3410
|
const settings4 = getSettingsFromContext(context);
|
|
3662
3411
|
if (compare(settings4.version, "19.0.0", "<")) {
|
|
@@ -3666,7 +3415,7 @@ function create54(context) {
|
|
|
3666
3415
|
const hookCalls = /* @__PURE__ */ new Set();
|
|
3667
3416
|
return {
|
|
3668
3417
|
CallExpression(node) {
|
|
3669
|
-
if (!
|
|
3418
|
+
if (!ER26.isReactHookCall(node)) {
|
|
3670
3419
|
return;
|
|
3671
3420
|
}
|
|
3672
3421
|
hookCalls.add(node);
|
|
@@ -3705,7 +3454,7 @@ function create54(context) {
|
|
|
3705
3454
|
}
|
|
3706
3455
|
},
|
|
3707
3456
|
"Program:exit"() {
|
|
3708
|
-
const isUseContextCall =
|
|
3457
|
+
const isUseContextCall = ER26.isReactHookCallWithNameAlias(context, "useContext", [...useContextNames]);
|
|
3709
3458
|
for (const node of hookCalls) {
|
|
3710
3459
|
if (!isUseContextCall(node)) {
|
|
3711
3460
|
continue;
|
|
@@ -3739,32 +3488,32 @@ function getCorrelativeTokens(context, node) {
|
|
|
3739
3488
|
}
|
|
3740
3489
|
return tokens;
|
|
3741
3490
|
}
|
|
3742
|
-
var
|
|
3743
|
-
var
|
|
3491
|
+
var RULE_NAME54 = "no-useless-forward-ref";
|
|
3492
|
+
var RULE_FEATURES54 = [];
|
|
3744
3493
|
var no_useless_forward_ref_default = createRule({
|
|
3745
3494
|
meta: {
|
|
3746
3495
|
type: "problem",
|
|
3747
3496
|
docs: {
|
|
3748
3497
|
description: "Disallow useless `forwardRef` calls on components that don't use `ref`s.",
|
|
3749
|
-
[Symbol.for("rule_features")]:
|
|
3498
|
+
[Symbol.for("rule_features")]: RULE_FEATURES54
|
|
3750
3499
|
},
|
|
3751
3500
|
messages: {
|
|
3752
3501
|
noUselessForwardRef: "A 'forwardRef' is used with this component but no 'ref' parameter is set."
|
|
3753
3502
|
},
|
|
3754
3503
|
schema: []
|
|
3755
3504
|
},
|
|
3756
|
-
name:
|
|
3757
|
-
create:
|
|
3505
|
+
name: RULE_NAME54,
|
|
3506
|
+
create: create54,
|
|
3758
3507
|
defaultOptions: []
|
|
3759
3508
|
});
|
|
3760
|
-
function
|
|
3509
|
+
function create54(context) {
|
|
3761
3510
|
return {
|
|
3762
3511
|
CallExpression(node) {
|
|
3763
|
-
if (!
|
|
3512
|
+
if (!ER26.isForwardRefCall(context, node)) {
|
|
3764
3513
|
return;
|
|
3765
3514
|
}
|
|
3766
3515
|
const [component] = node.arguments;
|
|
3767
|
-
if (component == null || !
|
|
3516
|
+
if (component == null || !AST13.isFunction(component)) {
|
|
3768
3517
|
return;
|
|
3769
3518
|
}
|
|
3770
3519
|
const ref = component.params[1];
|
|
@@ -3778,8 +3527,158 @@ function create55(context) {
|
|
|
3778
3527
|
}
|
|
3779
3528
|
};
|
|
3780
3529
|
}
|
|
3530
|
+
var RULE_NAME55 = "no-useless-fragment";
|
|
3531
|
+
var defaultOptions3 = [{
|
|
3532
|
+
allowExpressions: true
|
|
3533
|
+
}];
|
|
3534
|
+
var no_useless_fragment_default = createRule({
|
|
3535
|
+
meta: {
|
|
3536
|
+
type: "problem",
|
|
3537
|
+
defaultOptions: [...defaultOptions3],
|
|
3538
|
+
docs: {
|
|
3539
|
+
description: "Disallow useless fragment elements."
|
|
3540
|
+
},
|
|
3541
|
+
fixable: "code",
|
|
3542
|
+
messages: {
|
|
3543
|
+
uselessFragment: "A fragment {{reason}} is useless."
|
|
3544
|
+
},
|
|
3545
|
+
schema: [{
|
|
3546
|
+
type: "object",
|
|
3547
|
+
additionalProperties: false,
|
|
3548
|
+
properties: {
|
|
3549
|
+
allowExpressions: {
|
|
3550
|
+
type: "boolean",
|
|
3551
|
+
description: "Allow fragments with a single expression child"
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
}]
|
|
3555
|
+
},
|
|
3556
|
+
name: RULE_NAME55,
|
|
3557
|
+
create: create55,
|
|
3558
|
+
defaultOptions: defaultOptions3
|
|
3559
|
+
});
|
|
3560
|
+
function create55(context, [option]) {
|
|
3561
|
+
const { allowExpressions = true } = option;
|
|
3562
|
+
return {
|
|
3563
|
+
JSXElement(node) {
|
|
3564
|
+
if (!ER26.isFragmentElement(context, node)) return;
|
|
3565
|
+
checkNode(context, node, allowExpressions);
|
|
3566
|
+
},
|
|
3567
|
+
JSXFragment(node) {
|
|
3568
|
+
checkNode(context, node, allowExpressions);
|
|
3569
|
+
}
|
|
3570
|
+
};
|
|
3571
|
+
}
|
|
3572
|
+
function isWhiteSpace(node) {
|
|
3573
|
+
return typeof node.value === "string" && node.raw.trim() === "";
|
|
3574
|
+
}
|
|
3575
|
+
function isPaddingSpaces(node) {
|
|
3576
|
+
return ER26.isJsxText(node) && isWhiteSpace(node) && node.raw.includes("\n");
|
|
3577
|
+
}
|
|
3578
|
+
function trimLikeReact(text) {
|
|
3579
|
+
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
3580
|
+
const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
|
|
3581
|
+
const start = leadingSpaces.includes("\n") ? leadingSpaces.length : 0;
|
|
3582
|
+
const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
|
|
3583
|
+
return text.slice(start, end);
|
|
3584
|
+
}
|
|
3585
|
+
function checkNode(context, node, allowExpressions) {
|
|
3586
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
3587
|
+
if (ER26.isKeyedElement(context, node, initialScope)) {
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
if (ER26.isHostElement(context, node.parent)) {
|
|
3591
|
+
context.report({
|
|
3592
|
+
messageId: "uselessFragment",
|
|
3593
|
+
node,
|
|
3594
|
+
data: {
|
|
3595
|
+
reason: "placed inside a host component"
|
|
3596
|
+
},
|
|
3597
|
+
fix: getFix2(context, node)
|
|
3598
|
+
});
|
|
3599
|
+
}
|
|
3600
|
+
if (node.children.length === 0) {
|
|
3601
|
+
context.report({
|
|
3602
|
+
messageId: "uselessFragment",
|
|
3603
|
+
node,
|
|
3604
|
+
data: {
|
|
3605
|
+
reason: "contains less than two children"
|
|
3606
|
+
},
|
|
3607
|
+
fix: getFix2(context, node)
|
|
3608
|
+
});
|
|
3609
|
+
return;
|
|
3610
|
+
}
|
|
3611
|
+
const isChildElement = AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3612
|
+
switch (true) {
|
|
3613
|
+
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3614
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && ER26.isJsxText(node.children.at(0))): {
|
|
3615
|
+
return;
|
|
3616
|
+
}
|
|
3617
|
+
// <Foo><>hello, world</></Foo>
|
|
3618
|
+
case (!allowExpressions && isChildElement): {
|
|
3619
|
+
context.report({
|
|
3620
|
+
messageId: "uselessFragment",
|
|
3621
|
+
node,
|
|
3622
|
+
data: {
|
|
3623
|
+
reason: "contains less than two children"
|
|
3624
|
+
},
|
|
3625
|
+
fix: getFix2(context, node)
|
|
3626
|
+
});
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
case (!allowExpressions && !isChildElement && node.children.length === 1): {
|
|
3630
|
+
context.report({
|
|
3631
|
+
messageId: "uselessFragment",
|
|
3632
|
+
node,
|
|
3633
|
+
data: {
|
|
3634
|
+
reason: "contains less than two children"
|
|
3635
|
+
},
|
|
3636
|
+
fix: getFix2(context, node)
|
|
3637
|
+
});
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
const nonPaddingChildren = node.children.filter((child) => !isPaddingSpaces(child));
|
|
3642
|
+
const firstNonPaddingChild = nonPaddingChildren.at(0);
|
|
3643
|
+
switch (true) {
|
|
3644
|
+
case nonPaddingChildren.length === 0:
|
|
3645
|
+
case (nonPaddingChildren.length === 1 && firstNonPaddingChild?.type !== AST_NODE_TYPES.JSXExpressionContainer): {
|
|
3646
|
+
context.report({
|
|
3647
|
+
messageId: "uselessFragment",
|
|
3648
|
+
node,
|
|
3649
|
+
data: {
|
|
3650
|
+
reason: "contains less than two children"
|
|
3651
|
+
},
|
|
3652
|
+
fix: getFix2(context, node)
|
|
3653
|
+
});
|
|
3654
|
+
return;
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
return;
|
|
3658
|
+
}
|
|
3659
|
+
function getFix2(context, node) {
|
|
3660
|
+
if (!canFix(context, node)) return null;
|
|
3661
|
+
return (fixer) => {
|
|
3662
|
+
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
3663
|
+
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
3664
|
+
const childrenText = opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing ? "" : context.sourceCode.getText().slice(opener.range[1], closer?.range[0]);
|
|
3665
|
+
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
function canFix(context, node) {
|
|
3669
|
+
if (node.parent.type === AST_NODE_TYPES.JSXElement || node.parent.type === AST_NODE_TYPES.JSXFragment) {
|
|
3670
|
+
return ER26.isHostElement(context, node.parent);
|
|
3671
|
+
}
|
|
3672
|
+
if (node.children.length === 0) {
|
|
3673
|
+
return false;
|
|
3674
|
+
}
|
|
3675
|
+
if (node.children.some((child) => ER26.isJsxText(child) && !isWhiteSpace(child) || AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(child))) {
|
|
3676
|
+
return false;
|
|
3677
|
+
}
|
|
3678
|
+
return true;
|
|
3679
|
+
}
|
|
3781
3680
|
var RULE_NAME56 = "prefer-destructuring-assignment";
|
|
3782
|
-
var
|
|
3681
|
+
var RULE_FEATURES55 = [];
|
|
3783
3682
|
function isMemberExpressionWithObjectName(node) {
|
|
3784
3683
|
return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
|
|
3785
3684
|
}
|
|
@@ -3788,7 +3687,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3788
3687
|
type: "problem",
|
|
3789
3688
|
docs: {
|
|
3790
3689
|
description: "Enforces destructuring assignment for component props and context.",
|
|
3791
|
-
[Symbol.for("rule_features")]:
|
|
3690
|
+
[Symbol.for("rule_features")]: RULE_FEATURES55
|
|
3792
3691
|
},
|
|
3793
3692
|
messages: {
|
|
3794
3693
|
preferDestructuringAssignment: "Use destructuring assignment for {{name}}."
|
|
@@ -3800,7 +3699,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3800
3699
|
defaultOptions: []
|
|
3801
3700
|
});
|
|
3802
3701
|
function create56(context) {
|
|
3803
|
-
const { ctx, listeners } =
|
|
3702
|
+
const { ctx, listeners } = ER26.useComponentCollector(context);
|
|
3804
3703
|
const memberExpressionWithNames = [];
|
|
3805
3704
|
return {
|
|
3806
3705
|
...listeners,
|
|
@@ -3815,11 +3714,11 @@ function create56(context) {
|
|
|
3815
3714
|
...ctx.getAllComponents(program).values()
|
|
3816
3715
|
];
|
|
3817
3716
|
function isFunctionComponent(block) {
|
|
3818
|
-
if (!
|
|
3717
|
+
if (!AST13.isFunction(block)) {
|
|
3819
3718
|
return false;
|
|
3820
3719
|
}
|
|
3821
|
-
const id =
|
|
3822
|
-
return id != null &&
|
|
3720
|
+
const id = AST13.getFunctionId(block);
|
|
3721
|
+
return id != null && ER26.isComponentNameLoose(id.name) && components.some((component) => component.node === block);
|
|
3823
3722
|
}
|
|
3824
3723
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
3825
3724
|
let scope = initialScope;
|
|
@@ -3860,7 +3759,7 @@ function create56(context) {
|
|
|
3860
3759
|
};
|
|
3861
3760
|
}
|
|
3862
3761
|
var RULE_NAME57 = "prefer-namespace-import";
|
|
3863
|
-
var
|
|
3762
|
+
var RULE_FEATURES56 = [
|
|
3864
3763
|
"FIX"
|
|
3865
3764
|
];
|
|
3866
3765
|
var prefer_namespace_import_default = createRule({
|
|
@@ -3868,7 +3767,7 @@ var prefer_namespace_import_default = createRule({
|
|
|
3868
3767
|
type: "problem",
|
|
3869
3768
|
docs: {
|
|
3870
3769
|
description: "Enforces React is imported via a namespace import.",
|
|
3871
|
-
[Symbol.for("rule_features")]:
|
|
3770
|
+
[Symbol.for("rule_features")]: RULE_FEATURES56
|
|
3872
3771
|
},
|
|
3873
3772
|
fixable: "code",
|
|
3874
3773
|
messages: {
|
|
@@ -3916,7 +3815,7 @@ function create57(context) {
|
|
|
3916
3815
|
};
|
|
3917
3816
|
}
|
|
3918
3817
|
var RULE_NAME58 = "prefer-read-only-props";
|
|
3919
|
-
var
|
|
3818
|
+
var RULE_FEATURES57 = [
|
|
3920
3819
|
"TSC",
|
|
3921
3820
|
"EXP"
|
|
3922
3821
|
];
|
|
@@ -3925,7 +3824,7 @@ var prefer_read_only_props_default = createRule({
|
|
|
3925
3824
|
type: "problem",
|
|
3926
3825
|
docs: {
|
|
3927
3826
|
description: "Enforces read-only props in components.",
|
|
3928
|
-
[Symbol.for("rule_features")]:
|
|
3827
|
+
[Symbol.for("rule_features")]: RULE_FEATURES57
|
|
3929
3828
|
},
|
|
3930
3829
|
messages: {
|
|
3931
3830
|
preferReadOnlyProps: "A function component's props should be read-only."
|
|
@@ -3938,12 +3837,14 @@ var prefer_read_only_props_default = createRule({
|
|
|
3938
3837
|
});
|
|
3939
3838
|
function create58(context) {
|
|
3940
3839
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3941
|
-
const { ctx, listeners } =
|
|
3840
|
+
const { ctx, listeners } = ER26.useComponentCollector(context);
|
|
3942
3841
|
return {
|
|
3943
3842
|
...listeners,
|
|
3944
3843
|
"Program:exit"(program) {
|
|
3945
3844
|
const components = ctx.getAllComponents(program);
|
|
3946
3845
|
for (const [, component] of components) {
|
|
3846
|
+
if (component.id == null) continue;
|
|
3847
|
+
if (component.name == null) continue;
|
|
3947
3848
|
const [props] = component.node.params;
|
|
3948
3849
|
if (props == null) {
|
|
3949
3850
|
continue;
|
|
@@ -3967,7 +3868,7 @@ function isTypeReadonlyLoose(services, type) {
|
|
|
3967
3868
|
}
|
|
3968
3869
|
}
|
|
3969
3870
|
var RULE_NAME59 = "prefer-use-state-lazy-initialization";
|
|
3970
|
-
var
|
|
3871
|
+
var RULE_FEATURES58 = [
|
|
3971
3872
|
"EXP"
|
|
3972
3873
|
];
|
|
3973
3874
|
var ALLOW_LIST = [
|
|
@@ -3980,7 +3881,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
3980
3881
|
type: "problem",
|
|
3981
3882
|
docs: {
|
|
3982
3883
|
description: "Enforces function calls made inside `useState` to be wrapped in an `initializer function`.",
|
|
3983
|
-
[Symbol.for("rule_features")]:
|
|
3884
|
+
[Symbol.for("rule_features")]: RULE_FEATURES58
|
|
3984
3885
|
},
|
|
3985
3886
|
messages: {
|
|
3986
3887
|
preferUseStateLazyInitialization: "To prevent re-computation, consider using lazy initial state for useState calls that involve function calls. Ex: 'useState(() => getValue())'."
|
|
@@ -3993,10 +3894,10 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
3993
3894
|
});
|
|
3994
3895
|
function create59(context) {
|
|
3995
3896
|
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
3996
|
-
const isUseStateCall =
|
|
3897
|
+
const isUseStateCall = ER26.isReactHookCallWithNameAlias(context, "useState", alias);
|
|
3997
3898
|
return {
|
|
3998
3899
|
CallExpression(node) {
|
|
3999
|
-
if (!
|
|
3900
|
+
if (!ER26.isReactHookCall(node)) {
|
|
4000
3901
|
return;
|
|
4001
3902
|
}
|
|
4002
3903
|
if (!isUseStateCall(node)) {
|
|
@@ -4006,20 +3907,20 @@ function create59(context) {
|
|
|
4006
3907
|
if (useStateInput == null) {
|
|
4007
3908
|
return;
|
|
4008
3909
|
}
|
|
4009
|
-
for (const expr of
|
|
3910
|
+
for (const expr of AST13.getNestedNewExpressions(useStateInput)) {
|
|
4010
3911
|
if (!("name" in expr.callee)) continue;
|
|
4011
3912
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
4012
|
-
if (
|
|
3913
|
+
if (AST13.findParentNode(expr, (n) => ER26.isUseCall(context, n)) != null) continue;
|
|
4013
3914
|
context.report({
|
|
4014
3915
|
messageId: "preferUseStateLazyInitialization",
|
|
4015
3916
|
node: expr
|
|
4016
3917
|
});
|
|
4017
3918
|
}
|
|
4018
|
-
for (const expr of
|
|
3919
|
+
for (const expr of AST13.getNestedCallExpressions(useStateInput)) {
|
|
4019
3920
|
if (!("name" in expr.callee)) continue;
|
|
4020
|
-
if (
|
|
3921
|
+
if (ER26.isReactHookName(expr.callee.name)) continue;
|
|
4021
3922
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
4022
|
-
if (
|
|
3923
|
+
if (AST13.findParentNode(expr, (n) => ER26.isUseCall(context, n)) != null) continue;
|
|
4023
3924
|
context.report({
|
|
4024
3925
|
messageId: "preferUseStateLazyInitialization",
|
|
4025
3926
|
node: expr
|
|
@@ -4028,6 +3929,337 @@ function create59(context) {
|
|
|
4028
3929
|
}
|
|
4029
3930
|
};
|
|
4030
3931
|
}
|
|
3932
|
+
var RULE_NAME60 = "avoid-shorthand-boolean";
|
|
3933
|
+
var RULE_FEATURES59 = [];
|
|
3934
|
+
var avoid_shorthand_boolean_default = createRule({
|
|
3935
|
+
meta: {
|
|
3936
|
+
type: "problem",
|
|
3937
|
+
deprecated: true,
|
|
3938
|
+
docs: {
|
|
3939
|
+
description: "Enforces explicit boolean values for boolean attributes.",
|
|
3940
|
+
[Symbol.for("rule_features")]: RULE_FEATURES59
|
|
3941
|
+
},
|
|
3942
|
+
fixable: "code",
|
|
3943
|
+
messages: {
|
|
3944
|
+
avoidShorthandBoolean: "Avoid using shorthand boolean attribute '{{propName}}'. Use '{{propName}}={true}' instead."
|
|
3945
|
+
},
|
|
3946
|
+
replacedBy: [
|
|
3947
|
+
"react-x/jsx-shorthand-boolean"
|
|
3948
|
+
],
|
|
3949
|
+
schema: []
|
|
3950
|
+
},
|
|
3951
|
+
name: RULE_NAME60,
|
|
3952
|
+
create: create60,
|
|
3953
|
+
defaultOptions: []
|
|
3954
|
+
});
|
|
3955
|
+
function create60(context) {
|
|
3956
|
+
return {
|
|
3957
|
+
JSXAttribute(node) {
|
|
3958
|
+
if (node.value == null) {
|
|
3959
|
+
context.report({
|
|
3960
|
+
messageId: "avoidShorthandBoolean",
|
|
3961
|
+
node,
|
|
3962
|
+
data: {
|
|
3963
|
+
propName: ER26.getAttributeName(context, node)
|
|
3964
|
+
},
|
|
3965
|
+
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
3966
|
+
});
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
};
|
|
3970
|
+
}
|
|
3971
|
+
var RULE_NAME61 = "avoid-shorthand-fragment";
|
|
3972
|
+
var RULE_FEATURES60 = [];
|
|
3973
|
+
var avoid_shorthand_fragment_default = createRule({
|
|
3974
|
+
meta: {
|
|
3975
|
+
type: "problem",
|
|
3976
|
+
deprecated: true,
|
|
3977
|
+
docs: {
|
|
3978
|
+
description: "Enforces explicit `<Fragment>` components instead of the shorthand `<>` or `</>` syntax.",
|
|
3979
|
+
[Symbol.for("rule_features")]: RULE_FEATURES60
|
|
3980
|
+
},
|
|
3981
|
+
messages: {
|
|
3982
|
+
avoidShorthandFragment: "Avoid using shorthand fragment syntax. Use '{{jsxFragmentFactory}}' component instead."
|
|
3983
|
+
},
|
|
3984
|
+
replacedBy: [
|
|
3985
|
+
"react-x/jsx-shorthand-fragment"
|
|
3986
|
+
],
|
|
3987
|
+
schema: []
|
|
3988
|
+
},
|
|
3989
|
+
name: RULE_NAME61,
|
|
3990
|
+
create: create61,
|
|
3991
|
+
defaultOptions: []
|
|
3992
|
+
});
|
|
3993
|
+
function create61(context) {
|
|
3994
|
+
const jsxConfigFromContext = JsxConfig.getFromContext(context);
|
|
3995
|
+
const jsxConfigFromAnnotation = JsxConfig.getFromAnnotation(context);
|
|
3996
|
+
const jsxConfig = {
|
|
3997
|
+
...jsxConfigFromContext,
|
|
3998
|
+
...jsxConfigFromAnnotation
|
|
3999
|
+
};
|
|
4000
|
+
return {
|
|
4001
|
+
JSXFragment(node) {
|
|
4002
|
+
context.report({
|
|
4003
|
+
messageId: "avoidShorthandFragment",
|
|
4004
|
+
node,
|
|
4005
|
+
data: {
|
|
4006
|
+
jsxFragmentFactory: jsxConfig.jsxFragmentFactory
|
|
4007
|
+
}
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
};
|
|
4011
|
+
}
|
|
4012
|
+
var RULE_NAME62 = "prefer-shorthand-boolean";
|
|
4013
|
+
var RULE_FEATURES61 = [
|
|
4014
|
+
"FIX"
|
|
4015
|
+
];
|
|
4016
|
+
var prefer_shorthand_boolean_default = createRule({
|
|
4017
|
+
meta: {
|
|
4018
|
+
type: "problem",
|
|
4019
|
+
deprecated: true,
|
|
4020
|
+
docs: {
|
|
4021
|
+
description: "Enforces shorthand syntax for boolean attributes.",
|
|
4022
|
+
[Symbol.for("rule_features")]: RULE_FEATURES61
|
|
4023
|
+
},
|
|
4024
|
+
fixable: "code",
|
|
4025
|
+
messages: {
|
|
4026
|
+
preferShorthandBoolean: "Use shorthand boolean attribute '{{propName}}'."
|
|
4027
|
+
},
|
|
4028
|
+
replacedBy: [
|
|
4029
|
+
"react-x/jsx-shorthand-boolean"
|
|
4030
|
+
],
|
|
4031
|
+
schema: []
|
|
4032
|
+
},
|
|
4033
|
+
name: RULE_NAME62,
|
|
4034
|
+
create: create62,
|
|
4035
|
+
defaultOptions: []
|
|
4036
|
+
});
|
|
4037
|
+
function create62(context) {
|
|
4038
|
+
return {
|
|
4039
|
+
JSXAttribute(node) {
|
|
4040
|
+
const { value } = node;
|
|
4041
|
+
const propName = ER26.getAttributeName(context, node);
|
|
4042
|
+
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
4043
|
+
if (!hasValueTrue) {
|
|
4044
|
+
return;
|
|
4045
|
+
}
|
|
4046
|
+
context.report({
|
|
4047
|
+
messageId: "preferShorthandBoolean",
|
|
4048
|
+
node: node.value ?? node,
|
|
4049
|
+
data: {
|
|
4050
|
+
propName
|
|
4051
|
+
},
|
|
4052
|
+
fix: (fixer) => fixer.removeRange([node.name.range[1], value.range[1]])
|
|
4053
|
+
});
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
4057
|
+
var RULE_NAME63 = "prefer-shorthand-fragment";
|
|
4058
|
+
var RULE_FEATURES62 = [
|
|
4059
|
+
"FIX"
|
|
4060
|
+
];
|
|
4061
|
+
var prefer_shorthand_fragment_default = createRule({
|
|
4062
|
+
meta: {
|
|
4063
|
+
type: "problem",
|
|
4064
|
+
deprecated: true,
|
|
4065
|
+
docs: {
|
|
4066
|
+
description: "Enforces shorthand syntax for fragments.",
|
|
4067
|
+
[Symbol.for("rule_features")]: RULE_FEATURES62
|
|
4068
|
+
},
|
|
4069
|
+
fixable: "code",
|
|
4070
|
+
messages: {
|
|
4071
|
+
preferShorthandFragment: "Use fragment shorthand syntax instead of 'Fragment' component."
|
|
4072
|
+
},
|
|
4073
|
+
replacedBy: [
|
|
4074
|
+
"react-x/jsx-shorthand-fragment"
|
|
4075
|
+
],
|
|
4076
|
+
schema: []
|
|
4077
|
+
},
|
|
4078
|
+
name: RULE_NAME63,
|
|
4079
|
+
create: create63,
|
|
4080
|
+
defaultOptions: []
|
|
4081
|
+
});
|
|
4082
|
+
function create63(context) {
|
|
4083
|
+
return {
|
|
4084
|
+
JSXElement(node) {
|
|
4085
|
+
if (!ER26.isFragmentElement(context, node)) return;
|
|
4086
|
+
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
4087
|
+
if (hasAttributes) {
|
|
4088
|
+
return;
|
|
4089
|
+
}
|
|
4090
|
+
context.report({
|
|
4091
|
+
messageId: "preferShorthandFragment",
|
|
4092
|
+
node,
|
|
4093
|
+
fix: (fixer) => {
|
|
4094
|
+
const { closingElement, openingElement } = node;
|
|
4095
|
+
if (closingElement == null) {
|
|
4096
|
+
return [];
|
|
4097
|
+
}
|
|
4098
|
+
return [
|
|
4099
|
+
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
4100
|
+
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
4101
|
+
];
|
|
4102
|
+
}
|
|
4103
|
+
});
|
|
4104
|
+
}
|
|
4105
|
+
};
|
|
4106
|
+
}
|
|
4107
|
+
var RULE_NAME64 = "prefer-react-namespace-import";
|
|
4108
|
+
var RULE_FEATURES63 = [
|
|
4109
|
+
"FIX"
|
|
4110
|
+
];
|
|
4111
|
+
var prefer_react_namespace_import_default = createRule({
|
|
4112
|
+
meta: {
|
|
4113
|
+
type: "problem",
|
|
4114
|
+
deprecated: true,
|
|
4115
|
+
docs: {
|
|
4116
|
+
description: "Enforces React is imported via a namespace import.",
|
|
4117
|
+
[Symbol.for("rule_features")]: RULE_FEATURES63
|
|
4118
|
+
},
|
|
4119
|
+
fixable: "code",
|
|
4120
|
+
messages: {
|
|
4121
|
+
preferReactNamespaceImport: `Prefer importing React as 'import * as React from "{{importSource}}"';`
|
|
4122
|
+
},
|
|
4123
|
+
replacedBy: [
|
|
4124
|
+
"react-x/prefer-namespace-import"
|
|
4125
|
+
],
|
|
4126
|
+
schema: []
|
|
4127
|
+
},
|
|
4128
|
+
name: RULE_NAME64,
|
|
4129
|
+
create: create64,
|
|
4130
|
+
defaultOptions: []
|
|
4131
|
+
});
|
|
4132
|
+
function create64(context) {
|
|
4133
|
+
const { importSource } = getSettingsFromContext(context);
|
|
4134
|
+
return {
|
|
4135
|
+
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
4136
|
+
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
4137
|
+
context.report({
|
|
4138
|
+
messageId: "preferReactNamespaceImport",
|
|
4139
|
+
node: hasOtherSpecifiers ? node : node.parent,
|
|
4140
|
+
data: { importSource },
|
|
4141
|
+
fix(fixer) {
|
|
4142
|
+
const importDeclarationText = context.sourceCode.getText(node.parent);
|
|
4143
|
+
const semi = importDeclarationText.endsWith(";") ? ";" : "";
|
|
4144
|
+
const quote = node.parent.source.raw.at(0) ?? "'";
|
|
4145
|
+
const isTypeImport = node.parent.importKind === "type";
|
|
4146
|
+
const importStringPrefix = `import${isTypeImport ? " type" : ""}`;
|
|
4147
|
+
const importSourceQuoted = `${quote}${importSource}${quote}`;
|
|
4148
|
+
if (!hasOtherSpecifiers) {
|
|
4149
|
+
return fixer.replaceText(
|
|
4150
|
+
node.parent,
|
|
4151
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`
|
|
4152
|
+
);
|
|
4153
|
+
}
|
|
4154
|
+
const specifiers = importDeclarationText.slice(importDeclarationText.indexOf("{"), importDeclarationText.indexOf("}") + 1);
|
|
4155
|
+
return fixer.replaceText(
|
|
4156
|
+
node.parent,
|
|
4157
|
+
[
|
|
4158
|
+
`${importStringPrefix} * as ${node.local.name} from ${importSourceQuoted}${semi}`,
|
|
4159
|
+
`${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semi}`
|
|
4160
|
+
].join("\n")
|
|
4161
|
+
);
|
|
4162
|
+
}
|
|
4163
|
+
});
|
|
4164
|
+
}
|
|
4165
|
+
};
|
|
4166
|
+
}
|
|
4167
|
+
var RULE_NAME65 = "no-comment-textnodes";
|
|
4168
|
+
var RULE_FEATURES64 = [];
|
|
4169
|
+
var no_comment_textnodes_default = createRule({
|
|
4170
|
+
meta: {
|
|
4171
|
+
type: "problem",
|
|
4172
|
+
deprecated: true,
|
|
4173
|
+
docs: {
|
|
4174
|
+
description: "Prevents comments from being inserted as text nodes.",
|
|
4175
|
+
[Symbol.for("rule_features")]: RULE_FEATURES64
|
|
4176
|
+
},
|
|
4177
|
+
messages: {
|
|
4178
|
+
noCommentTextnodes: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces."
|
|
4179
|
+
},
|
|
4180
|
+
replacedBy: [
|
|
4181
|
+
"react-x/jsx-no-comment-textnodes"
|
|
4182
|
+
],
|
|
4183
|
+
schema: []
|
|
4184
|
+
},
|
|
4185
|
+
name: RULE_NAME65,
|
|
4186
|
+
create: create65,
|
|
4187
|
+
defaultOptions: []
|
|
4188
|
+
});
|
|
4189
|
+
function create65(context) {
|
|
4190
|
+
function hasCommentLike(node) {
|
|
4191
|
+
if (AST13.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
4192
|
+
return false;
|
|
4193
|
+
}
|
|
4194
|
+
const rawValue = context.sourceCode.getText(node);
|
|
4195
|
+
return /^\s*\/(?:\/|\*)/mu.test(rawValue);
|
|
4196
|
+
}
|
|
4197
|
+
const visitorFunction = (node) => {
|
|
4198
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent)) {
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
4201
|
+
if (!hasCommentLike(node)) {
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
if (!node.parent.type.includes("JSX")) {
|
|
4205
|
+
return;
|
|
4206
|
+
}
|
|
4207
|
+
context.report({
|
|
4208
|
+
messageId: "noCommentTextnodes",
|
|
4209
|
+
node
|
|
4210
|
+
});
|
|
4211
|
+
};
|
|
4212
|
+
return {
|
|
4213
|
+
JSXText: visitorFunction,
|
|
4214
|
+
Literal: visitorFunction
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
var RULE_NAME66 = "no-complex-conditional-rendering";
|
|
4218
|
+
var RULE_FEATURES65 = [
|
|
4219
|
+
"EXP"
|
|
4220
|
+
];
|
|
4221
|
+
var no_complex_conditional_rendering_default = createRule({
|
|
4222
|
+
meta: {
|
|
4223
|
+
type: "problem",
|
|
4224
|
+
deprecated: true,
|
|
4225
|
+
docs: {
|
|
4226
|
+
description: "Disallow complex conditional rendering in JSX expressions.",
|
|
4227
|
+
[Symbol.for("rule_features")]: RULE_FEATURES65
|
|
4228
|
+
},
|
|
4229
|
+
messages: {
|
|
4230
|
+
noComplexConditionalRendering: "Avoid complex conditional rendering. Extract the logic into separate elements or components."
|
|
4231
|
+
},
|
|
4232
|
+
schema: []
|
|
4233
|
+
},
|
|
4234
|
+
name: RULE_NAME66,
|
|
4235
|
+
create: create66,
|
|
4236
|
+
defaultOptions: []
|
|
4237
|
+
});
|
|
4238
|
+
function create66(context) {
|
|
4239
|
+
const visitorFunction = (node) => {
|
|
4240
|
+
const jsxExpContainer = node.parent?.parent;
|
|
4241
|
+
if (!AST13.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
4242
|
+
return;
|
|
4243
|
+
}
|
|
4244
|
+
if (!AST13.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(jsxExpContainer.parent)) {
|
|
4245
|
+
return;
|
|
4246
|
+
}
|
|
4247
|
+
if (!jsxExpContainer.parent.children.includes(jsxExpContainer)) {
|
|
4248
|
+
return;
|
|
4249
|
+
}
|
|
4250
|
+
context.report({
|
|
4251
|
+
messageId: "noComplexConditionalRendering",
|
|
4252
|
+
node: jsxExpContainer
|
|
4253
|
+
});
|
|
4254
|
+
};
|
|
4255
|
+
return {
|
|
4256
|
+
"JSXExpressionContainer > ConditionalExpression > ConditionalExpression": visitorFunction,
|
|
4257
|
+
"JSXExpressionContainer > ConditionalExpression > LogicalExpression": visitorFunction,
|
|
4258
|
+
"JSXExpressionContainer > LogicalExpression > ConditionalExpression": visitorFunction,
|
|
4259
|
+
"JSXExpressionContainer > LogicalExpression[operator='&&'] > LogicalExpression[operator='||']": visitorFunction,
|
|
4260
|
+
"JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
|
|
4261
|
+
};
|
|
4262
|
+
}
|
|
4031
4263
|
|
|
4032
4264
|
// src/plugin.ts
|
|
4033
4265
|
var plugin = {
|
|
@@ -4039,6 +4271,7 @@ var plugin = {
|
|
|
4039
4271
|
"jsx-key-before-spread": jsx_key_before_spread_default,
|
|
4040
4272
|
"jsx-no-comment-textnodes": jsx_no_comment_textnodes_default,
|
|
4041
4273
|
"jsx-no-duplicate-props": jsx_no_duplicate_props_default,
|
|
4274
|
+
"jsx-no-iife": jsx_no_iife_default,
|
|
4042
4275
|
"jsx-no-undef": jsx_no_undef_default,
|
|
4043
4276
|
"jsx-shorthand-boolean": jsx_shorthand_boolean_default,
|
|
4044
4277
|
"jsx-shorthand-fragment": jsx_shorthand_fragment_default,
|
|
@@ -4061,8 +4294,6 @@ var plugin = {
|
|
|
4061
4294
|
"no-create-ref": no_create_ref_default,
|
|
4062
4295
|
"no-default-props": no_default_props_default,
|
|
4063
4296
|
"no-direct-mutation-state": no_direct_mutation_state_default,
|
|
4064
|
-
"no-direct-set-state-in-use-effect": no_direct_set_state_in_use_effect_default,
|
|
4065
|
-
"no-direct-set-state-in-use-layout-effect": no_direct_set_state_in_use_layout_effect_default,
|
|
4066
4297
|
"no-duplicate-key": no_duplicate_key_default,
|
|
4067
4298
|
"no-forward-ref": no_forward_ref_default,
|
|
4068
4299
|
"no-implicit-key": no_implicit_key_default,
|
|
@@ -4091,10 +4322,19 @@ var plugin = {
|
|
|
4091
4322
|
"no-unused-state": no_unused_state_default,
|
|
4092
4323
|
"no-use-context": no_use_context_default,
|
|
4093
4324
|
"no-useless-forward-ref": no_useless_forward_ref_default,
|
|
4325
|
+
"no-useless-fragment": no_useless_fragment_default,
|
|
4094
4326
|
"prefer-destructuring-assignment": prefer_destructuring_assignment_default,
|
|
4095
4327
|
"prefer-namespace-import": prefer_namespace_import_default,
|
|
4096
4328
|
"prefer-read-only-props": prefer_read_only_props_default,
|
|
4097
|
-
"prefer-use-state-lazy-initialization": prefer_use_state_lazy_initialization_default
|
|
4329
|
+
"prefer-use-state-lazy-initialization": prefer_use_state_lazy_initialization_default,
|
|
4330
|
+
// Removed rules
|
|
4331
|
+
"avoid-shorthand-boolean": avoid_shorthand_boolean_default,
|
|
4332
|
+
"avoid-shorthand-fragment": avoid_shorthand_fragment_default,
|
|
4333
|
+
"no-comment-textnodes": no_comment_textnodes_default,
|
|
4334
|
+
"no-complex-conditional-rendering": no_complex_conditional_rendering_default,
|
|
4335
|
+
"prefer-react-namespace-import": prefer_react_namespace_import_default,
|
|
4336
|
+
"prefer-shorthand-boolean": prefer_shorthand_boolean_default,
|
|
4337
|
+
"prefer-shorthand-fragment": prefer_shorthand_fragment_default
|
|
4098
4338
|
}
|
|
4099
4339
|
};
|
|
4100
4340
|
|