eslint-plugin-react-x 1.37.4-next.0 → 1.38.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -27
- package/dist/index.d.ts +29 -27
- package/dist/index.js +493 -451
- package/dist/index.mjs +490 -448
- package/package.json +8 -7
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
1
|
+
import { getDocsUrl, getSettingsFromContext, unsafeDecodeSettings, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
|
+
import * as JSX9 from '@eslint-react/jsx';
|
|
3
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
|
+
import * as VAR2 from '@eslint-react/var';
|
|
3
6
|
import * as AST11 from '@eslint-react/ast';
|
|
4
7
|
import { isClassComponent, isThisSetState, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isComponentNameLoose, isCreateRefCall, isAssignmentToThisState, isForwardRefCall, useComponentCollector, DEFAULT_COMPONENT_HINT, ERComponentFlag, getInstanceId, isInstanceIdEqual, DISPLAY_NAME_ASSIGNMENT_SELECTOR, isCreateContextCall, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideRenderMethod, isCreateElementCall, isReactHookCall, isReactHookCallWithNameAlias, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
5
|
-
import { _, flow, getOrUpdate, constTrue, constFalse
|
|
6
|
-
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
8
|
+
import { _, flow, getOrUpdate, constTrue, constFalse } from '@eslint-react/eff';
|
|
7
9
|
import { isMatching, match, P } from 'ts-pattern';
|
|
10
|
+
import { createReport } from '@eslint-react/kit';
|
|
8
11
|
import { compare } from 'compare-versions';
|
|
9
|
-
import * as VAR from '@eslint-react/var';
|
|
10
12
|
import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
|
|
11
|
-
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
12
13
|
import { unionTypeParts, isTypeFlagSet, isTrueLiteralType, isFalseLiteralType } from 'ts-api-utils';
|
|
13
14
|
import ts from 'typescript';
|
|
14
15
|
import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReadonlyDeep } from 'is-immutable-type';
|
|
@@ -28,6 +29,9 @@ __export(recommended_exports, {
|
|
|
28
29
|
});
|
|
29
30
|
var name = "react-x/recommended";
|
|
30
31
|
var rules = {
|
|
32
|
+
"react-x/jsx-no-duplicate-props": "warn",
|
|
33
|
+
"react-x/jsx-no-undef": "error",
|
|
34
|
+
"react-x/jsx-uses-vars": "warn",
|
|
31
35
|
"react-x/no-access-state-in-setstate": "error",
|
|
32
36
|
"react-x/no-array-index-key": "warn",
|
|
33
37
|
"react-x/no-children-count": "warn",
|
|
@@ -44,7 +48,6 @@ var rules = {
|
|
|
44
48
|
"react-x/no-create-ref": "error",
|
|
45
49
|
"react-x/no-default-props": "error",
|
|
46
50
|
"react-x/no-direct-mutation-state": "error",
|
|
47
|
-
"react-x/no-duplicate-jsx-props": "warn",
|
|
48
51
|
"react-x/no-duplicate-key": "warn",
|
|
49
52
|
"react-x/no-forward-ref": "warn",
|
|
50
53
|
"react-x/no-implicit-key": "warn",
|
|
@@ -64,8 +67,7 @@ var rules = {
|
|
|
64
67
|
"react-x/no-unused-class-component-members": "warn",
|
|
65
68
|
"react-x/no-unused-state": "warn",
|
|
66
69
|
"react-x/no-use-context": "warn",
|
|
67
|
-
"react-x/no-useless-forward-ref": "warn"
|
|
68
|
-
"react-x/use-jsx-vars": "warn"
|
|
70
|
+
"react-x/no-useless-forward-ref": "warn"
|
|
69
71
|
};
|
|
70
72
|
var settings = {
|
|
71
73
|
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
@@ -89,8 +91,9 @@ __export(recommended_typescript_exports, {
|
|
|
89
91
|
var name2 = "react-x/recommended-typescript";
|
|
90
92
|
var rules2 = {
|
|
91
93
|
...rules,
|
|
92
|
-
"react-x/no-duplicate-
|
|
93
|
-
"react-x/
|
|
94
|
+
"react-x/jsx-no-duplicate-props": "off",
|
|
95
|
+
"react-x/jsx-no-undef": "off",
|
|
96
|
+
"react-x/jsx-uses-vars": "off"
|
|
94
97
|
};
|
|
95
98
|
var settings2 = {
|
|
96
99
|
...settings
|
|
@@ -109,8 +112,8 @@ var settings3 = {
|
|
|
109
112
|
|
|
110
113
|
// package.json
|
|
111
114
|
var name4 = "eslint-plugin-react-x";
|
|
112
|
-
var version = "1.
|
|
113
|
-
var createRule =
|
|
115
|
+
var version = "1.38.0-beta.10";
|
|
116
|
+
var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
|
|
114
117
|
|
|
115
118
|
// src/rules/avoid-shorthand-boolean.ts
|
|
116
119
|
var RULE_NAME = "avoid-shorthand-boolean";
|
|
@@ -140,7 +143,7 @@ function create(context) {
|
|
|
140
143
|
messageId: "avoidShorthandBoolean",
|
|
141
144
|
node,
|
|
142
145
|
data: {
|
|
143
|
-
propName:
|
|
146
|
+
propName: JSX9.getAttributeName(node)
|
|
144
147
|
},
|
|
145
148
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
146
149
|
});
|
|
@@ -178,8 +181,131 @@ function create2(context) {
|
|
|
178
181
|
}
|
|
179
182
|
};
|
|
180
183
|
}
|
|
181
|
-
var RULE_NAME3 = "no-
|
|
184
|
+
var RULE_NAME3 = "jsx-no-duplicate-props";
|
|
182
185
|
var RULE_FEATURES3 = [];
|
|
186
|
+
var jsx_no_duplicate_props_default = createRule({
|
|
187
|
+
meta: {
|
|
188
|
+
type: "problem",
|
|
189
|
+
docs: {
|
|
190
|
+
description: "Disallow duplicate props in JSX elements.",
|
|
191
|
+
[Symbol.for("rule_features")]: RULE_FEATURES3
|
|
192
|
+
},
|
|
193
|
+
messages: {
|
|
194
|
+
jsxNoDuplicateProps: "This JSX property is assigned multiple times."
|
|
195
|
+
},
|
|
196
|
+
schema: []
|
|
197
|
+
},
|
|
198
|
+
name: RULE_NAME3,
|
|
199
|
+
create: create3,
|
|
200
|
+
defaultOptions: []
|
|
201
|
+
});
|
|
202
|
+
function create3(context) {
|
|
203
|
+
return {
|
|
204
|
+
JSXOpeningElement(node) {
|
|
205
|
+
const props = [];
|
|
206
|
+
for (const attr of node.attributes) {
|
|
207
|
+
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const name5 = attr.name.name;
|
|
211
|
+
if (typeof name5 !== "string") {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!props.includes(name5)) {
|
|
215
|
+
props.push(name5);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
context.report({
|
|
219
|
+
messageId: "jsxNoDuplicateProps",
|
|
220
|
+
node: attr
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
var RULE_NAME4 = "jsx-no-undef";
|
|
227
|
+
var RULE_FEATURES4 = [];
|
|
228
|
+
var jsx_no_undef_default = createRule({
|
|
229
|
+
meta: {
|
|
230
|
+
type: "problem",
|
|
231
|
+
docs: {
|
|
232
|
+
description: "Disallow undefined variables in JSX.",
|
|
233
|
+
[Symbol.for("rule_features")]: RULE_FEATURES4
|
|
234
|
+
},
|
|
235
|
+
messages: {
|
|
236
|
+
jsxNoUndef: "JSX variable '{{name}}' is not defined."
|
|
237
|
+
},
|
|
238
|
+
schema: []
|
|
239
|
+
},
|
|
240
|
+
name: RULE_NAME4,
|
|
241
|
+
create: create4,
|
|
242
|
+
defaultOptions: []
|
|
243
|
+
});
|
|
244
|
+
function create4(context) {
|
|
245
|
+
return {
|
|
246
|
+
JSXIdentifier(node) {
|
|
247
|
+
if (node.name === "this") {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (/^[a-z]/u.test(node.name)) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const initialScope = context.sourceCode.getScope(node);
|
|
257
|
+
if (VAR2.findVariable(node.name, initialScope) == null) {
|
|
258
|
+
context.report({
|
|
259
|
+
messageId: "jsxNoUndef",
|
|
260
|
+
node,
|
|
261
|
+
data: { name: node.name }
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
var RULE_NAME5 = "jsx-uses-vars";
|
|
268
|
+
var RULE_FEATURES5 = [];
|
|
269
|
+
var jsx_uses_vars_default = createRule({
|
|
270
|
+
meta: {
|
|
271
|
+
type: "problem",
|
|
272
|
+
docs: {
|
|
273
|
+
description: "Marks variables used in JSX elements as used.",
|
|
274
|
+
[Symbol.for("rule_features")]: RULE_FEATURES5
|
|
275
|
+
},
|
|
276
|
+
messages: {
|
|
277
|
+
jsxUsesVars: "JSX variables should be marked as used."
|
|
278
|
+
},
|
|
279
|
+
schema: []
|
|
280
|
+
},
|
|
281
|
+
name: RULE_NAME5,
|
|
282
|
+
create: create5,
|
|
283
|
+
defaultOptions: []
|
|
284
|
+
});
|
|
285
|
+
function create5(context) {
|
|
286
|
+
return {
|
|
287
|
+
JSXOpeningElement(node) {
|
|
288
|
+
switch (node.name.type) {
|
|
289
|
+
case AST_NODE_TYPES.JSXIdentifier: {
|
|
290
|
+
if (/^[a-z]/u.test(node.name.name)) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
context.sourceCode.markVariableAsUsed(node.name.name, node);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
case AST_NODE_TYPES.JSXMemberExpression: {
|
|
297
|
+
const { object } = node.name;
|
|
298
|
+
if (object.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
299
|
+
context.sourceCode.markVariableAsUsed(object.name, node);
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
var RULE_NAME6 = "no-access-state-in-setstate";
|
|
308
|
+
var RULE_FEATURES6 = [];
|
|
183
309
|
function isKeyLiteral(node, key) {
|
|
184
310
|
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);
|
|
185
311
|
}
|
|
@@ -188,18 +314,18 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
188
314
|
type: "problem",
|
|
189
315
|
docs: {
|
|
190
316
|
description: "Disallow accessing `this.state` inside `setState` calls.",
|
|
191
|
-
[Symbol.for("rule_features")]:
|
|
317
|
+
[Symbol.for("rule_features")]: RULE_FEATURES6
|
|
192
318
|
},
|
|
193
319
|
messages: {
|
|
194
320
|
noAccessStateInSetstate: "Do not access 'this.state' within 'setState'. Use the update function instead."
|
|
195
321
|
},
|
|
196
322
|
schema: []
|
|
197
323
|
},
|
|
198
|
-
name:
|
|
199
|
-
create:
|
|
324
|
+
name: RULE_NAME6,
|
|
325
|
+
create: create6,
|
|
200
326
|
defaultOptions: []
|
|
201
327
|
});
|
|
202
|
-
function
|
|
328
|
+
function create6(context) {
|
|
203
329
|
if (!context.sourceCode.text.includes("setState")) {
|
|
204
330
|
return {};
|
|
205
331
|
}
|
|
@@ -290,23 +416,9 @@ function create3(context) {
|
|
|
290
416
|
}
|
|
291
417
|
};
|
|
292
418
|
}
|
|
293
|
-
var
|
|
294
|
-
var
|
|
419
|
+
var RULE_NAME7 = "no-array-index-key";
|
|
420
|
+
var RULE_FEATURES7 = [];
|
|
295
421
|
var reactChildrenMethod = ["forEach", "map"];
|
|
296
|
-
var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
297
|
-
["every", 1],
|
|
298
|
-
["filter", 1],
|
|
299
|
-
["find", 1],
|
|
300
|
-
["findIndex", 1],
|
|
301
|
-
["findLast", 1],
|
|
302
|
-
["findLastIndex", 1],
|
|
303
|
-
["flatMap", 1],
|
|
304
|
-
["forEach", 1],
|
|
305
|
-
["map", 1],
|
|
306
|
-
["reduce", 2],
|
|
307
|
-
["reduceRight", 2],
|
|
308
|
-
["some", 1]
|
|
309
|
-
]);
|
|
310
422
|
function isReactChildrenMethod(name5) {
|
|
311
423
|
return reactChildrenMethod.some((method) => method === name5);
|
|
312
424
|
}
|
|
@@ -337,7 +449,7 @@ function getMapIndexParamName(context, node) {
|
|
|
337
449
|
return _;
|
|
338
450
|
}
|
|
339
451
|
const { name: name5 } = callee.property;
|
|
340
|
-
if (!
|
|
452
|
+
if (!AST11.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.has(name5)) {
|
|
341
453
|
return _;
|
|
342
454
|
}
|
|
343
455
|
const callbackArg = node.arguments[isUsingReactChildren(context, node) ? 1 : 0];
|
|
@@ -348,7 +460,7 @@ function getMapIndexParamName(context, node) {
|
|
|
348
460
|
return _;
|
|
349
461
|
}
|
|
350
462
|
const { params } = callbackArg;
|
|
351
|
-
const indexParamPosition =
|
|
463
|
+
const indexParamPosition = AST11.ITERATOR_FUNCTION_INDEX_PARAM_POSITION.get(name5);
|
|
352
464
|
if (indexParamPosition == null) {
|
|
353
465
|
return _;
|
|
354
466
|
}
|
|
@@ -375,18 +487,18 @@ var no_array_index_key_default = createRule({
|
|
|
375
487
|
type: "problem",
|
|
376
488
|
docs: {
|
|
377
489
|
description: "Disallow an item's index in the array as its key.",
|
|
378
|
-
[Symbol.for("rule_features")]:
|
|
490
|
+
[Symbol.for("rule_features")]: RULE_FEATURES7
|
|
379
491
|
},
|
|
380
492
|
messages: {
|
|
381
493
|
noArrayIndexKey: "Do not use item index in the array as its key."
|
|
382
494
|
},
|
|
383
495
|
schema: []
|
|
384
496
|
},
|
|
385
|
-
name:
|
|
386
|
-
create:
|
|
497
|
+
name: RULE_NAME7,
|
|
498
|
+
create: create7,
|
|
387
499
|
defaultOptions: []
|
|
388
500
|
});
|
|
389
|
-
function
|
|
501
|
+
function create7(context) {
|
|
390
502
|
const report = createReport(context);
|
|
391
503
|
const indexParamNames = [];
|
|
392
504
|
function isArrayIndex(node) {
|
|
@@ -484,25 +596,25 @@ function create4(context) {
|
|
|
484
596
|
}
|
|
485
597
|
};
|
|
486
598
|
}
|
|
487
|
-
var
|
|
488
|
-
var
|
|
599
|
+
var RULE_NAME8 = "no-children-count";
|
|
600
|
+
var RULE_FEATURES8 = [];
|
|
489
601
|
var no_children_count_default = createRule({
|
|
490
602
|
meta: {
|
|
491
603
|
type: "problem",
|
|
492
604
|
docs: {
|
|
493
605
|
description: "Disallow `Children.count`.",
|
|
494
|
-
[Symbol.for("rule_features")]:
|
|
606
|
+
[Symbol.for("rule_features")]: RULE_FEATURES8
|
|
495
607
|
},
|
|
496
608
|
messages: {
|
|
497
609
|
noChildrenCount: "Using 'Children.count' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
498
610
|
},
|
|
499
611
|
schema: []
|
|
500
612
|
},
|
|
501
|
-
name:
|
|
502
|
-
create:
|
|
613
|
+
name: RULE_NAME8,
|
|
614
|
+
create: create8,
|
|
503
615
|
defaultOptions: []
|
|
504
616
|
});
|
|
505
|
-
function
|
|
617
|
+
function create8(context) {
|
|
506
618
|
return {
|
|
507
619
|
MemberExpression(node) {
|
|
508
620
|
if (isChildrenCount(context, node)) {
|
|
@@ -514,25 +626,25 @@ function create5(context) {
|
|
|
514
626
|
}
|
|
515
627
|
};
|
|
516
628
|
}
|
|
517
|
-
var
|
|
518
|
-
var
|
|
629
|
+
var RULE_NAME9 = "no-children-for-each";
|
|
630
|
+
var RULE_FEATURES9 = [];
|
|
519
631
|
var no_children_for_each_default = createRule({
|
|
520
632
|
meta: {
|
|
521
633
|
type: "problem",
|
|
522
634
|
docs: {
|
|
523
635
|
description: "Disallow 'Children.forEach'.",
|
|
524
|
-
[Symbol.for("rule_features")]:
|
|
636
|
+
[Symbol.for("rule_features")]: RULE_FEATURES9
|
|
525
637
|
},
|
|
526
638
|
messages: {
|
|
527
639
|
noChildrenForEach: "Using 'Children.forEach' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
528
640
|
},
|
|
529
641
|
schema: []
|
|
530
642
|
},
|
|
531
|
-
name:
|
|
532
|
-
create:
|
|
643
|
+
name: RULE_NAME9,
|
|
644
|
+
create: create9,
|
|
533
645
|
defaultOptions: []
|
|
534
646
|
});
|
|
535
|
-
function
|
|
647
|
+
function create9(context) {
|
|
536
648
|
return {
|
|
537
649
|
MemberExpression(node) {
|
|
538
650
|
if (isChildrenForEach(context, node)) {
|
|
@@ -544,25 +656,25 @@ function create6(context) {
|
|
|
544
656
|
}
|
|
545
657
|
};
|
|
546
658
|
}
|
|
547
|
-
var
|
|
548
|
-
var
|
|
659
|
+
var RULE_NAME10 = "no-children-map";
|
|
660
|
+
var RULE_FEATURES10 = [];
|
|
549
661
|
var no_children_map_default = createRule({
|
|
550
662
|
meta: {
|
|
551
663
|
type: "problem",
|
|
552
664
|
docs: {
|
|
553
665
|
description: "Disallow `Children.map`.",
|
|
554
|
-
[Symbol.for("rule_features")]:
|
|
666
|
+
[Symbol.for("rule_features")]: RULE_FEATURES10
|
|
555
667
|
},
|
|
556
668
|
messages: {
|
|
557
669
|
noChildrenMap: "Using 'Children.map' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
558
670
|
},
|
|
559
671
|
schema: []
|
|
560
672
|
},
|
|
561
|
-
name:
|
|
562
|
-
create:
|
|
673
|
+
name: RULE_NAME10,
|
|
674
|
+
create: create10,
|
|
563
675
|
defaultOptions: []
|
|
564
676
|
});
|
|
565
|
-
function
|
|
677
|
+
function create10(context) {
|
|
566
678
|
return {
|
|
567
679
|
MemberExpression(node) {
|
|
568
680
|
if (isChildrenMap(context, node)) {
|
|
@@ -574,25 +686,25 @@ function create7(context) {
|
|
|
574
686
|
}
|
|
575
687
|
};
|
|
576
688
|
}
|
|
577
|
-
var
|
|
578
|
-
var
|
|
689
|
+
var RULE_NAME11 = "no-children-only";
|
|
690
|
+
var RULE_FEATURES11 = [];
|
|
579
691
|
var no_children_only_default = createRule({
|
|
580
692
|
meta: {
|
|
581
693
|
type: "problem",
|
|
582
694
|
docs: {
|
|
583
695
|
description: "Disallow `Children.only`.",
|
|
584
|
-
[Symbol.for("rule_features")]:
|
|
696
|
+
[Symbol.for("rule_features")]: RULE_FEATURES11
|
|
585
697
|
},
|
|
586
698
|
messages: {
|
|
587
699
|
noChildrenOnly: "Using 'Children.only' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
588
700
|
},
|
|
589
701
|
schema: []
|
|
590
702
|
},
|
|
591
|
-
name:
|
|
592
|
-
create:
|
|
703
|
+
name: RULE_NAME11,
|
|
704
|
+
create: create11,
|
|
593
705
|
defaultOptions: []
|
|
594
706
|
});
|
|
595
|
-
function
|
|
707
|
+
function create11(context) {
|
|
596
708
|
return {
|
|
597
709
|
MemberExpression(node) {
|
|
598
710
|
if (isChildrenOnly(context, node)) {
|
|
@@ -604,28 +716,28 @@ function create8(context) {
|
|
|
604
716
|
}
|
|
605
717
|
};
|
|
606
718
|
}
|
|
607
|
-
var
|
|
608
|
-
var
|
|
719
|
+
var RULE_NAME12 = "no-children-prop";
|
|
720
|
+
var RULE_FEATURES12 = [];
|
|
609
721
|
var no_children_prop_default = createRule({
|
|
610
722
|
meta: {
|
|
611
723
|
type: "problem",
|
|
612
724
|
docs: {
|
|
613
725
|
description: "Disallow passing `children` as a prop.",
|
|
614
|
-
[Symbol.for("rule_features")]:
|
|
726
|
+
[Symbol.for("rule_features")]: RULE_FEATURES12
|
|
615
727
|
},
|
|
616
728
|
messages: {
|
|
617
729
|
noChildrenProp: "Do not pass 'children' as props."
|
|
618
730
|
},
|
|
619
731
|
schema: []
|
|
620
732
|
},
|
|
621
|
-
name:
|
|
622
|
-
create:
|
|
733
|
+
name: RULE_NAME12,
|
|
734
|
+
create: create12,
|
|
623
735
|
defaultOptions: []
|
|
624
736
|
});
|
|
625
|
-
function
|
|
737
|
+
function create12(context) {
|
|
626
738
|
return {
|
|
627
739
|
JSXElement(node) {
|
|
628
|
-
const attribute =
|
|
740
|
+
const attribute = JSX9.getAttribute(
|
|
629
741
|
"children",
|
|
630
742
|
node.openingElement.attributes,
|
|
631
743
|
context.sourceCode.getScope(node)
|
|
@@ -639,25 +751,25 @@ function create9(context) {
|
|
|
639
751
|
}
|
|
640
752
|
};
|
|
641
753
|
}
|
|
642
|
-
var
|
|
643
|
-
var
|
|
754
|
+
var RULE_NAME13 = "no-children-to-array";
|
|
755
|
+
var RULE_FEATURES13 = [];
|
|
644
756
|
var no_children_to_array_default = createRule({
|
|
645
757
|
meta: {
|
|
646
758
|
type: "problem",
|
|
647
759
|
docs: {
|
|
648
760
|
description: "Disallow `Children.toArray`.",
|
|
649
|
-
[Symbol.for("rule_features")]:
|
|
761
|
+
[Symbol.for("rule_features")]: RULE_FEATURES13
|
|
650
762
|
},
|
|
651
763
|
messages: {
|
|
652
764
|
noChildrenToArray: "Using 'Children.toArray' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
653
765
|
},
|
|
654
766
|
schema: []
|
|
655
767
|
},
|
|
656
|
-
name:
|
|
657
|
-
create:
|
|
768
|
+
name: RULE_NAME13,
|
|
769
|
+
create: create13,
|
|
658
770
|
defaultOptions: []
|
|
659
771
|
});
|
|
660
|
-
function
|
|
772
|
+
function create13(context) {
|
|
661
773
|
return {
|
|
662
774
|
MemberExpression(node) {
|
|
663
775
|
if (isChildrenToArray(context, node)) {
|
|
@@ -669,25 +781,25 @@ function create10(context) {
|
|
|
669
781
|
}
|
|
670
782
|
};
|
|
671
783
|
}
|
|
672
|
-
var
|
|
673
|
-
var
|
|
784
|
+
var RULE_NAME14 = "no-class-component";
|
|
785
|
+
var RULE_FEATURES14 = [];
|
|
674
786
|
var no_class_component_default = createRule({
|
|
675
787
|
meta: {
|
|
676
788
|
type: "problem",
|
|
677
789
|
docs: {
|
|
678
790
|
description: "Disallow class components.",
|
|
679
|
-
[Symbol.for("rule_features")]:
|
|
791
|
+
[Symbol.for("rule_features")]: RULE_FEATURES14
|
|
680
792
|
},
|
|
681
793
|
messages: {
|
|
682
794
|
noClassComponent: "Do not use class components. Use function components instead."
|
|
683
795
|
},
|
|
684
796
|
schema: []
|
|
685
797
|
},
|
|
686
|
-
name:
|
|
687
|
-
create:
|
|
798
|
+
name: RULE_NAME14,
|
|
799
|
+
create: create14,
|
|
688
800
|
defaultOptions: []
|
|
689
801
|
});
|
|
690
|
-
function
|
|
802
|
+
function create14(context) {
|
|
691
803
|
if (!context.sourceCode.text.includes("Component")) return {};
|
|
692
804
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
693
805
|
return {
|
|
@@ -709,25 +821,25 @@ function create11(context) {
|
|
|
709
821
|
}
|
|
710
822
|
};
|
|
711
823
|
}
|
|
712
|
-
var
|
|
713
|
-
var
|
|
824
|
+
var RULE_NAME15 = "no-clone-element";
|
|
825
|
+
var RULE_FEATURES15 = [];
|
|
714
826
|
var no_clone_element_default = createRule({
|
|
715
827
|
meta: {
|
|
716
828
|
type: "problem",
|
|
717
829
|
docs: {
|
|
718
830
|
description: "Disallow `cloneElement`.",
|
|
719
|
-
[Symbol.for("rule_features")]:
|
|
831
|
+
[Symbol.for("rule_features")]: RULE_FEATURES15
|
|
720
832
|
},
|
|
721
833
|
messages: {
|
|
722
834
|
noCloneElement: "Using 'cloneElement' is uncommon and can lead to fragile code. Use alternatives instead."
|
|
723
835
|
},
|
|
724
836
|
schema: []
|
|
725
837
|
},
|
|
726
|
-
name:
|
|
727
|
-
create:
|
|
838
|
+
name: RULE_NAME15,
|
|
839
|
+
create: create15,
|
|
728
840
|
defaultOptions: []
|
|
729
841
|
});
|
|
730
|
-
function
|
|
842
|
+
function create15(context) {
|
|
731
843
|
return {
|
|
732
844
|
CallExpression(node) {
|
|
733
845
|
if (!isCloneElementCall(context, node)) {
|
|
@@ -740,25 +852,25 @@ function create12(context) {
|
|
|
740
852
|
}
|
|
741
853
|
};
|
|
742
854
|
}
|
|
743
|
-
var
|
|
744
|
-
var
|
|
855
|
+
var RULE_NAME16 = "no-comment-textnodes";
|
|
856
|
+
var RULE_FEATURES16 = [];
|
|
745
857
|
var no_comment_textnodes_default = createRule({
|
|
746
858
|
meta: {
|
|
747
859
|
type: "problem",
|
|
748
860
|
docs: {
|
|
749
861
|
description: "Prevents comments from being inserted as text nodes.",
|
|
750
|
-
[Symbol.for("rule_features")]:
|
|
862
|
+
[Symbol.for("rule_features")]: RULE_FEATURES16
|
|
751
863
|
},
|
|
752
864
|
messages: {
|
|
753
865
|
noCommentTextnodes: "Possible misused comment in text node. Comments inside children section of tag should be placed inside braces."
|
|
754
866
|
},
|
|
755
867
|
schema: []
|
|
756
868
|
},
|
|
757
|
-
name:
|
|
758
|
-
create:
|
|
869
|
+
name: RULE_NAME16,
|
|
870
|
+
create: create16,
|
|
759
871
|
defaultOptions: []
|
|
760
872
|
});
|
|
761
|
-
function
|
|
873
|
+
function create16(context) {
|
|
762
874
|
function hasCommentLike(node) {
|
|
763
875
|
if (AST11.isOneOf([AST_NODE_TYPES.JSXAttribute, AST_NODE_TYPES.JSXExpressionContainer])(node.parent)) {
|
|
764
876
|
return false;
|
|
@@ -786,25 +898,27 @@ function create13(context) {
|
|
|
786
898
|
Literal: visitorFunction
|
|
787
899
|
};
|
|
788
900
|
}
|
|
789
|
-
var
|
|
790
|
-
var
|
|
901
|
+
var RULE_NAME17 = "no-complex-conditional-rendering";
|
|
902
|
+
var RULE_FEATURES17 = [
|
|
903
|
+
"EXP"
|
|
904
|
+
];
|
|
791
905
|
var no_complex_conditional_rendering_default = createRule({
|
|
792
906
|
meta: {
|
|
793
907
|
type: "problem",
|
|
794
908
|
docs: {
|
|
795
909
|
description: "Disallow complex conditional rendering in JSX expressions.",
|
|
796
|
-
[Symbol.for("rule_features")]:
|
|
910
|
+
[Symbol.for("rule_features")]: RULE_FEATURES17
|
|
797
911
|
},
|
|
798
912
|
messages: {
|
|
799
913
|
noComplexConditionalRendering: "Avoid complex conditional rendering. Extract the logic into separate elements or components."
|
|
800
914
|
},
|
|
801
915
|
schema: []
|
|
802
916
|
},
|
|
803
|
-
name:
|
|
804
|
-
create:
|
|
917
|
+
name: RULE_NAME17,
|
|
918
|
+
create: create17,
|
|
805
919
|
defaultOptions: []
|
|
806
920
|
});
|
|
807
|
-
function
|
|
921
|
+
function create17(context) {
|
|
808
922
|
const visitorFunction = (node) => {
|
|
809
923
|
const jsxExpContainer = node.parent?.parent;
|
|
810
924
|
if (!AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(jsxExpContainer)) {
|
|
@@ -829,8 +943,8 @@ function create14(context) {
|
|
|
829
943
|
"JSXExpressionContainer > LogicalExpression[operator='||'] > LogicalExpression[operator='&&']": visitorFunction
|
|
830
944
|
};
|
|
831
945
|
}
|
|
832
|
-
var
|
|
833
|
-
var
|
|
946
|
+
var RULE_NAME18 = "no-component-will-mount";
|
|
947
|
+
var RULE_FEATURES18 = [
|
|
834
948
|
"MOD"
|
|
835
949
|
];
|
|
836
950
|
function isComponentWillMount(node) {
|
|
@@ -841,7 +955,7 @@ var no_component_will_mount_default = createRule({
|
|
|
841
955
|
type: "problem",
|
|
842
956
|
docs: {
|
|
843
957
|
description: "Replace usages of `componentWillMount` with `UNSAFE_componentWillMount`.",
|
|
844
|
-
[Symbol.for("rule_features")]:
|
|
958
|
+
[Symbol.for("rule_features")]: RULE_FEATURES18
|
|
845
959
|
},
|
|
846
960
|
fixable: "code",
|
|
847
961
|
messages: {
|
|
@@ -849,11 +963,11 @@ var no_component_will_mount_default = createRule({
|
|
|
849
963
|
},
|
|
850
964
|
schema: []
|
|
851
965
|
},
|
|
852
|
-
name:
|
|
853
|
-
create:
|
|
966
|
+
name: RULE_NAME18,
|
|
967
|
+
create: create18,
|
|
854
968
|
defaultOptions: []
|
|
855
969
|
});
|
|
856
|
-
function
|
|
970
|
+
function create18(context) {
|
|
857
971
|
if (!context.sourceCode.text.includes("componentWillMount")) return {};
|
|
858
972
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
859
973
|
return {
|
|
@@ -880,8 +994,8 @@ function create15(context) {
|
|
|
880
994
|
}
|
|
881
995
|
};
|
|
882
996
|
}
|
|
883
|
-
var
|
|
884
|
-
var
|
|
997
|
+
var RULE_NAME19 = "no-component-will-receive-props";
|
|
998
|
+
var RULE_FEATURES19 = [
|
|
885
999
|
"MOD"
|
|
886
1000
|
];
|
|
887
1001
|
function isComponentWillUpdate(node) {
|
|
@@ -892,7 +1006,7 @@ var no_component_will_receive_props_default = createRule({
|
|
|
892
1006
|
type: "problem",
|
|
893
1007
|
docs: {
|
|
894
1008
|
description: "Replace usages of `componentWillReceiveProps` with `UNSAFE_componentWillReceiveProps`.",
|
|
895
|
-
[Symbol.for("rule_features")]:
|
|
1009
|
+
[Symbol.for("rule_features")]: RULE_FEATURES19
|
|
896
1010
|
},
|
|
897
1011
|
fixable: "code",
|
|
898
1012
|
messages: {
|
|
@@ -900,11 +1014,11 @@ var no_component_will_receive_props_default = createRule({
|
|
|
900
1014
|
},
|
|
901
1015
|
schema: []
|
|
902
1016
|
},
|
|
903
|
-
name:
|
|
904
|
-
create:
|
|
1017
|
+
name: RULE_NAME19,
|
|
1018
|
+
create: create19,
|
|
905
1019
|
defaultOptions: []
|
|
906
1020
|
});
|
|
907
|
-
function
|
|
1021
|
+
function create19(context) {
|
|
908
1022
|
if (!context.sourceCode.text.includes("componentWillReceiveProps")) return {};
|
|
909
1023
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
910
1024
|
return {
|
|
@@ -931,8 +1045,8 @@ function create16(context) {
|
|
|
931
1045
|
}
|
|
932
1046
|
};
|
|
933
1047
|
}
|
|
934
|
-
var
|
|
935
|
-
var
|
|
1048
|
+
var RULE_NAME20 = "no-component-will-update";
|
|
1049
|
+
var RULE_FEATURES20 = [
|
|
936
1050
|
"MOD"
|
|
937
1051
|
];
|
|
938
1052
|
function isComponentWillUpdate2(node) {
|
|
@@ -943,7 +1057,7 @@ var no_component_will_update_default = createRule({
|
|
|
943
1057
|
type: "problem",
|
|
944
1058
|
docs: {
|
|
945
1059
|
description: "Replace usages of `componentWillUpdate` with `UNSAFE_componentWillUpdate`.",
|
|
946
|
-
[Symbol.for("rule_features")]:
|
|
1060
|
+
[Symbol.for("rule_features")]: RULE_FEATURES20
|
|
947
1061
|
},
|
|
948
1062
|
fixable: "code",
|
|
949
1063
|
messages: {
|
|
@@ -951,11 +1065,11 @@ var no_component_will_update_default = createRule({
|
|
|
951
1065
|
},
|
|
952
1066
|
schema: []
|
|
953
1067
|
},
|
|
954
|
-
name:
|
|
955
|
-
create:
|
|
1068
|
+
name: RULE_NAME20,
|
|
1069
|
+
create: create20,
|
|
956
1070
|
defaultOptions: []
|
|
957
1071
|
});
|
|
958
|
-
function
|
|
1072
|
+
function create20(context) {
|
|
959
1073
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
960
1074
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
961
1075
|
return {
|
|
@@ -982,8 +1096,8 @@ function create17(context) {
|
|
|
982
1096
|
}
|
|
983
1097
|
};
|
|
984
1098
|
}
|
|
985
|
-
var
|
|
986
|
-
var
|
|
1099
|
+
var RULE_NAME21 = "no-context-provider";
|
|
1100
|
+
var RULE_FEATURES21 = [
|
|
987
1101
|
"MOD"
|
|
988
1102
|
];
|
|
989
1103
|
var no_context_provider_default = createRule({
|
|
@@ -991,7 +1105,7 @@ var no_context_provider_default = createRule({
|
|
|
991
1105
|
type: "problem",
|
|
992
1106
|
docs: {
|
|
993
1107
|
description: "Replace usages of `<Context.Provider>` with `<Context>`.",
|
|
994
|
-
[Symbol.for("rule_features")]:
|
|
1108
|
+
[Symbol.for("rule_features")]: RULE_FEATURES21
|
|
995
1109
|
},
|
|
996
1110
|
fixable: "code",
|
|
997
1111
|
messages: {
|
|
@@ -999,17 +1113,17 @@ var no_context_provider_default = createRule({
|
|
|
999
1113
|
},
|
|
1000
1114
|
schema: []
|
|
1001
1115
|
},
|
|
1002
|
-
name:
|
|
1003
|
-
create:
|
|
1116
|
+
name: RULE_NAME21,
|
|
1117
|
+
create: create21,
|
|
1004
1118
|
defaultOptions: []
|
|
1005
1119
|
});
|
|
1006
|
-
function
|
|
1120
|
+
function create21(context) {
|
|
1007
1121
|
if (!context.sourceCode.text.includes("Provider")) return {};
|
|
1008
1122
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1009
1123
|
if (compare(version2, "19.0.0", "<")) return {};
|
|
1010
1124
|
return {
|
|
1011
1125
|
JSXElement(node) {
|
|
1012
|
-
const fullName =
|
|
1126
|
+
const fullName = JSX9.getElementType(node);
|
|
1013
1127
|
const parts = fullName.split(".");
|
|
1014
1128
|
const selfName = parts.pop();
|
|
1015
1129
|
const contextFullName = parts.join(".");
|
|
@@ -1035,25 +1149,25 @@ function create18(context) {
|
|
|
1035
1149
|
}
|
|
1036
1150
|
};
|
|
1037
1151
|
}
|
|
1038
|
-
var
|
|
1039
|
-
var
|
|
1152
|
+
var RULE_NAME22 = "no-create-ref";
|
|
1153
|
+
var RULE_FEATURES22 = [];
|
|
1040
1154
|
var no_create_ref_default = createRule({
|
|
1041
1155
|
meta: {
|
|
1042
1156
|
type: "problem",
|
|
1043
1157
|
docs: {
|
|
1044
1158
|
description: "Disallow `createRef` in function components.",
|
|
1045
|
-
[Symbol.for("rule_features")]:
|
|
1159
|
+
[Symbol.for("rule_features")]: RULE_FEATURES22
|
|
1046
1160
|
},
|
|
1047
1161
|
messages: {
|
|
1048
1162
|
noCreateRef: "[Deprecated] Use 'useRef' instead."
|
|
1049
1163
|
},
|
|
1050
1164
|
schema: []
|
|
1051
1165
|
},
|
|
1052
|
-
name:
|
|
1053
|
-
create:
|
|
1166
|
+
name: RULE_NAME22,
|
|
1167
|
+
create: create22,
|
|
1054
1168
|
defaultOptions: []
|
|
1055
1169
|
});
|
|
1056
|
-
function
|
|
1170
|
+
function create22(context) {
|
|
1057
1171
|
return {
|
|
1058
1172
|
CallExpression(node) {
|
|
1059
1173
|
if (isCreateRefCall(context, node) && AST11.findParentNode(node, isClassComponent) == null) {
|
|
@@ -1062,25 +1176,25 @@ function create19(context) {
|
|
|
1062
1176
|
}
|
|
1063
1177
|
};
|
|
1064
1178
|
}
|
|
1065
|
-
var
|
|
1066
|
-
var
|
|
1179
|
+
var RULE_NAME23 = "no-default-props";
|
|
1180
|
+
var RULE_FEATURES23 = [];
|
|
1067
1181
|
var no_default_props_default = createRule({
|
|
1068
1182
|
meta: {
|
|
1069
1183
|
type: "problem",
|
|
1070
1184
|
docs: {
|
|
1071
1185
|
description: "Disallow `defaultProps` property in favor of ES6 default parameters.",
|
|
1072
|
-
[Symbol.for("rule_features")]:
|
|
1186
|
+
[Symbol.for("rule_features")]: RULE_FEATURES23
|
|
1073
1187
|
},
|
|
1074
1188
|
messages: {
|
|
1075
1189
|
noDefaultProps: "[Deprecated] Use ES6 default parameters instead."
|
|
1076
1190
|
},
|
|
1077
1191
|
schema: []
|
|
1078
1192
|
},
|
|
1079
|
-
name:
|
|
1080
|
-
create:
|
|
1193
|
+
name: RULE_NAME23,
|
|
1194
|
+
create: create23,
|
|
1081
1195
|
defaultOptions: []
|
|
1082
1196
|
});
|
|
1083
|
-
function
|
|
1197
|
+
function create23(context) {
|
|
1084
1198
|
if (!context.sourceCode.text.includes("defaultProps")) return {};
|
|
1085
1199
|
return {
|
|
1086
1200
|
AssignmentExpression(node) {
|
|
@@ -1097,8 +1211,8 @@ function create20(context) {
|
|
|
1097
1211
|
if (!isComponentNameLoose(object.name)) {
|
|
1098
1212
|
return;
|
|
1099
1213
|
}
|
|
1100
|
-
const variable =
|
|
1101
|
-
const variableNode =
|
|
1214
|
+
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1215
|
+
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
1102
1216
|
if (variableNode == null) return;
|
|
1103
1217
|
if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
|
|
1104
1218
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
@@ -1114,8 +1228,8 @@ function create20(context) {
|
|
|
1114
1228
|
}
|
|
1115
1229
|
};
|
|
1116
1230
|
}
|
|
1117
|
-
var
|
|
1118
|
-
var
|
|
1231
|
+
var RULE_NAME24 = "no-direct-mutation-state";
|
|
1232
|
+
var RULE_FEATURES24 = [];
|
|
1119
1233
|
function isConstructorFunction(node) {
|
|
1120
1234
|
return AST11.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && AST11.isMethodOrProperty(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
|
|
1121
1235
|
}
|
|
@@ -1124,18 +1238,18 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1124
1238
|
type: "problem",
|
|
1125
1239
|
docs: {
|
|
1126
1240
|
description: "Disallow direct mutation of `this.state`.",
|
|
1127
|
-
[Symbol.for("rule_features")]:
|
|
1241
|
+
[Symbol.for("rule_features")]: RULE_FEATURES24
|
|
1128
1242
|
},
|
|
1129
1243
|
messages: {
|
|
1130
1244
|
noDirectMutationState: "Do not mutate state directly. Use 'setState()' instead."
|
|
1131
1245
|
},
|
|
1132
1246
|
schema: []
|
|
1133
1247
|
},
|
|
1134
|
-
name:
|
|
1135
|
-
create:
|
|
1248
|
+
name: RULE_NAME24,
|
|
1249
|
+
create: create24,
|
|
1136
1250
|
defaultOptions: []
|
|
1137
1251
|
});
|
|
1138
|
-
function
|
|
1252
|
+
function create24(context) {
|
|
1139
1253
|
return {
|
|
1140
1254
|
AssignmentExpression(node) {
|
|
1141
1255
|
if (!isAssignmentToThisState(node)) return;
|
|
@@ -1156,67 +1270,25 @@ function create21(context) {
|
|
|
1156
1270
|
}
|
|
1157
1271
|
};
|
|
1158
1272
|
}
|
|
1159
|
-
var
|
|
1160
|
-
var
|
|
1161
|
-
var no_duplicate_jsx_props_default = createRule({
|
|
1162
|
-
meta: {
|
|
1163
|
-
type: "problem",
|
|
1164
|
-
docs: {
|
|
1165
|
-
description: "Disallow duplicate props in JSX elements.",
|
|
1166
|
-
[Symbol.for("rule_features")]: RULE_FEATURES22
|
|
1167
|
-
},
|
|
1168
|
-
messages: {
|
|
1169
|
-
noDuplicateJsxProps: "This JSX property is assigned multiple times."
|
|
1170
|
-
},
|
|
1171
|
-
schema: []
|
|
1172
|
-
},
|
|
1173
|
-
name: RULE_NAME22,
|
|
1174
|
-
create: create22,
|
|
1175
|
-
defaultOptions: []
|
|
1176
|
-
});
|
|
1177
|
-
function create22(context) {
|
|
1178
|
-
return {
|
|
1179
|
-
JSXOpeningElement(node) {
|
|
1180
|
-
const props = [];
|
|
1181
|
-
for (const attr of node.attributes) {
|
|
1182
|
-
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1183
|
-
continue;
|
|
1184
|
-
}
|
|
1185
|
-
const name5 = attr.name.name;
|
|
1186
|
-
if (typeof name5 !== "string") {
|
|
1187
|
-
continue;
|
|
1188
|
-
}
|
|
1189
|
-
if (!props.includes(name5)) {
|
|
1190
|
-
props.push(name5);
|
|
1191
|
-
continue;
|
|
1192
|
-
}
|
|
1193
|
-
context.report({
|
|
1194
|
-
messageId: "noDuplicateJsxProps",
|
|
1195
|
-
node: attr
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
var RULE_NAME23 = "no-duplicate-key";
|
|
1202
|
-
var RULE_FEATURES23 = [];
|
|
1273
|
+
var RULE_NAME25 = "no-duplicate-key";
|
|
1274
|
+
var RULE_FEATURES25 = [];
|
|
1203
1275
|
var no_duplicate_key_default = createRule({
|
|
1204
1276
|
meta: {
|
|
1205
1277
|
type: "problem",
|
|
1206
1278
|
docs: {
|
|
1207
1279
|
description: "Disallow duplicate `key` on elements in the same array or a list of `children`.",
|
|
1208
|
-
[Symbol.for("rule_features")]:
|
|
1280
|
+
[Symbol.for("rule_features")]: RULE_FEATURES25
|
|
1209
1281
|
},
|
|
1210
1282
|
messages: {
|
|
1211
1283
|
noDuplicateKey: "A key must be unique. '{{value}}' is duplicated."
|
|
1212
1284
|
},
|
|
1213
1285
|
schema: []
|
|
1214
1286
|
},
|
|
1215
|
-
name:
|
|
1216
|
-
create:
|
|
1287
|
+
name: RULE_NAME25,
|
|
1288
|
+
create: create25,
|
|
1217
1289
|
defaultOptions: []
|
|
1218
1290
|
});
|
|
1219
|
-
function
|
|
1291
|
+
function create25(context) {
|
|
1220
1292
|
if (!context.sourceCode.getText().includes("key=")) {
|
|
1221
1293
|
return {};
|
|
1222
1294
|
}
|
|
@@ -1246,7 +1318,7 @@ function create23(context) {
|
|
|
1246
1318
|
break;
|
|
1247
1319
|
}
|
|
1248
1320
|
default: {
|
|
1249
|
-
const call = AST11.findParentNode(jsxElement, AST11.
|
|
1321
|
+
const call = AST11.findParentNode(jsxElement, AST11.isArrayMapCallLoose);
|
|
1250
1322
|
const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
|
|
1251
1323
|
if (!AST11.isFunction(iter)) return;
|
|
1252
1324
|
const arg0 = call?.arguments[0];
|
|
@@ -1280,8 +1352,8 @@ function create23(context) {
|
|
|
1280
1352
|
}
|
|
1281
1353
|
};
|
|
1282
1354
|
}
|
|
1283
|
-
var
|
|
1284
|
-
var
|
|
1355
|
+
var RULE_NAME26 = "no-forward-ref";
|
|
1356
|
+
var RULE_FEATURES26 = [
|
|
1285
1357
|
"MOD"
|
|
1286
1358
|
];
|
|
1287
1359
|
var no_forward_ref_default = createRule({
|
|
@@ -1289,7 +1361,7 @@ var no_forward_ref_default = createRule({
|
|
|
1289
1361
|
type: "problem",
|
|
1290
1362
|
docs: {
|
|
1291
1363
|
description: "Replaces usages of `forwardRef` with passing `ref` as a prop.",
|
|
1292
|
-
[Symbol.for("rule_features")]:
|
|
1364
|
+
[Symbol.for("rule_features")]: RULE_FEATURES26
|
|
1293
1365
|
},
|
|
1294
1366
|
fixable: "code",
|
|
1295
1367
|
messages: {
|
|
@@ -1297,11 +1369,11 @@ var no_forward_ref_default = createRule({
|
|
|
1297
1369
|
},
|
|
1298
1370
|
schema: []
|
|
1299
1371
|
},
|
|
1300
|
-
name:
|
|
1301
|
-
create:
|
|
1372
|
+
name: RULE_NAME26,
|
|
1373
|
+
create: create26,
|
|
1302
1374
|
defaultOptions: []
|
|
1303
1375
|
});
|
|
1304
|
-
function
|
|
1376
|
+
function create26(context) {
|
|
1305
1377
|
if (!context.sourceCode.text.includes("forwardRef")) {
|
|
1306
1378
|
return {};
|
|
1307
1379
|
}
|
|
@@ -1389,29 +1461,31 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
|
|
|
1389
1461
|
...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]
|
|
1390
1462
|
];
|
|
1391
1463
|
}
|
|
1392
|
-
var
|
|
1393
|
-
var
|
|
1464
|
+
var RULE_NAME27 = "no-implicit-key";
|
|
1465
|
+
var RULE_FEATURES27 = [
|
|
1466
|
+
"EXP"
|
|
1467
|
+
];
|
|
1394
1468
|
var no_implicit_key_default = createRule({
|
|
1395
1469
|
meta: {
|
|
1396
1470
|
type: "problem",
|
|
1397
1471
|
docs: {
|
|
1398
1472
|
description: "Prevents `key` from not being explicitly specified (e.g. spreading `key` from objects).",
|
|
1399
|
-
[Symbol.for("rule_features")]:
|
|
1473
|
+
[Symbol.for("rule_features")]: RULE_FEATURES27
|
|
1400
1474
|
},
|
|
1401
1475
|
messages: {
|
|
1402
1476
|
noImplicitKey: "Do not use implicit 'key' props."
|
|
1403
1477
|
},
|
|
1404
1478
|
schema: []
|
|
1405
1479
|
},
|
|
1406
|
-
name:
|
|
1407
|
-
create:
|
|
1480
|
+
name: RULE_NAME27,
|
|
1481
|
+
create: create27,
|
|
1408
1482
|
defaultOptions: []
|
|
1409
1483
|
});
|
|
1410
|
-
function
|
|
1484
|
+
function create27(context) {
|
|
1411
1485
|
return {
|
|
1412
1486
|
JSXOpeningElement(node) {
|
|
1413
1487
|
const initialScope = context.sourceCode.getScope(node);
|
|
1414
|
-
const keyPropFound =
|
|
1488
|
+
const keyPropFound = JSX9.getAttribute("key", node.attributes, initialScope);
|
|
1415
1489
|
const keyPropOnElement = node.attributes.some(
|
|
1416
1490
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1417
1491
|
);
|
|
@@ -1421,8 +1495,8 @@ function create25(context) {
|
|
|
1421
1495
|
}
|
|
1422
1496
|
};
|
|
1423
1497
|
}
|
|
1424
|
-
var
|
|
1425
|
-
var
|
|
1498
|
+
var RULE_NAME28 = "no-leaked-conditional-rendering";
|
|
1499
|
+
var RULE_FEATURES28 = [
|
|
1426
1500
|
"TSC"
|
|
1427
1501
|
];
|
|
1428
1502
|
var tsHelpers = {
|
|
@@ -1508,18 +1582,18 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1508
1582
|
type: "problem",
|
|
1509
1583
|
docs: {
|
|
1510
1584
|
description: "Prevents problematic leaked values from being rendered.",
|
|
1511
|
-
[Symbol.for("rule_features")]:
|
|
1585
|
+
[Symbol.for("rule_features")]: RULE_FEATURES28
|
|
1512
1586
|
},
|
|
1513
1587
|
messages: {
|
|
1514
1588
|
noLeakedConditionalRendering: "Potential leaked value {{value}} that might cause unintentionally rendered values or rendering crashes."
|
|
1515
1589
|
},
|
|
1516
1590
|
schema: []
|
|
1517
1591
|
},
|
|
1518
|
-
name:
|
|
1519
|
-
create:
|
|
1592
|
+
name: RULE_NAME28,
|
|
1593
|
+
create: create28,
|
|
1520
1594
|
defaultOptions: []
|
|
1521
1595
|
});
|
|
1522
|
-
function
|
|
1596
|
+
function create28(context) {
|
|
1523
1597
|
if (!context.sourceCode.text.includes("&&") && !context.sourceCode.text.includes("?")) return {};
|
|
1524
1598
|
const { version: version2 } = getSettingsFromContext(context);
|
|
1525
1599
|
const allowedVariants = [
|
|
@@ -1543,7 +1617,7 @@ function create26(context) {
|
|
|
1543
1617
|
return getReportDescriptor(right);
|
|
1544
1618
|
}
|
|
1545
1619
|
const initialScope = context.sourceCode.getScope(left);
|
|
1546
|
-
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" ||
|
|
1620
|
+
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR2.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1547
1621
|
if (isLeftNan) {
|
|
1548
1622
|
return {
|
|
1549
1623
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1565,9 +1639,9 @@ function create26(context) {
|
|
|
1565
1639
|
}).with({ type: AST_NODE_TYPES.ConditionalExpression }, ({ alternate, consequent }) => {
|
|
1566
1640
|
return getReportDescriptor(consequent) ?? getReportDescriptor(alternate);
|
|
1567
1641
|
}).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
1568
|
-
const variable =
|
|
1569
|
-
const
|
|
1570
|
-
return getReportDescriptor(
|
|
1642
|
+
const variable = VAR2.findVariable(n.name, context.sourceCode.getScope(n));
|
|
1643
|
+
const variableDefNode = variable?.defs.at(0)?.node;
|
|
1644
|
+
return match(variableDefNode).with({ init: P.select({ type: P.not(AST_NODE_TYPES.VariableDeclaration) }) }, getReportDescriptor).otherwise(() => _);
|
|
1571
1645
|
}).otherwise(() => _);
|
|
1572
1646
|
}
|
|
1573
1647
|
const visitorFunction = flow(getReportDescriptor, createReport(context));
|
|
@@ -1576,25 +1650,25 @@ function create26(context) {
|
|
|
1576
1650
|
"JSXExpressionContainer > LogicalExpression": visitorFunction
|
|
1577
1651
|
};
|
|
1578
1652
|
}
|
|
1579
|
-
var
|
|
1580
|
-
var
|
|
1653
|
+
var RULE_NAME29 = "no-missing-component-display-name";
|
|
1654
|
+
var RULE_FEATURES29 = [];
|
|
1581
1655
|
var no_missing_component_display_name_default = createRule({
|
|
1582
1656
|
meta: {
|
|
1583
1657
|
type: "problem",
|
|
1584
1658
|
docs: {
|
|
1585
1659
|
description: "Enforces that all components have a `displayName` which can be used in devtools.",
|
|
1586
|
-
[Symbol.for("rule_features")]:
|
|
1660
|
+
[Symbol.for("rule_features")]: RULE_FEATURES29
|
|
1587
1661
|
},
|
|
1588
1662
|
messages: {
|
|
1589
1663
|
noMissingComponentDisplayName: "Add missing 'displayName' for component."
|
|
1590
1664
|
},
|
|
1591
1665
|
schema: []
|
|
1592
1666
|
},
|
|
1593
|
-
name:
|
|
1594
|
-
create:
|
|
1667
|
+
name: RULE_NAME29,
|
|
1668
|
+
create: create29,
|
|
1595
1669
|
defaultOptions: []
|
|
1596
1670
|
});
|
|
1597
|
-
function
|
|
1671
|
+
function create29(context) {
|
|
1598
1672
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) return {};
|
|
1599
1673
|
const {
|
|
1600
1674
|
ctx,
|
|
@@ -1629,25 +1703,25 @@ function create27(context) {
|
|
|
1629
1703
|
}
|
|
1630
1704
|
};
|
|
1631
1705
|
}
|
|
1632
|
-
var
|
|
1633
|
-
var
|
|
1706
|
+
var RULE_NAME30 = "no-missing-context-display-name";
|
|
1707
|
+
var RULE_FEATURES30 = [];
|
|
1634
1708
|
var no_missing_context_display_name_default = createRule({
|
|
1635
1709
|
meta: {
|
|
1636
1710
|
type: "problem",
|
|
1637
1711
|
docs: {
|
|
1638
1712
|
description: "Enforces that all contexts have a `displayName` which can be used in devtools.",
|
|
1639
|
-
[Symbol.for("rule_features")]:
|
|
1713
|
+
[Symbol.for("rule_features")]: RULE_FEATURES30
|
|
1640
1714
|
},
|
|
1641
1715
|
messages: {
|
|
1642
1716
|
noMissingContextDisplayName: "Add missing 'displayName' for context."
|
|
1643
1717
|
},
|
|
1644
1718
|
schema: []
|
|
1645
1719
|
},
|
|
1646
|
-
name:
|
|
1647
|
-
create:
|
|
1720
|
+
name: RULE_NAME30,
|
|
1721
|
+
create: create30,
|
|
1648
1722
|
defaultOptions: []
|
|
1649
1723
|
});
|
|
1650
|
-
function
|
|
1724
|
+
function create30(context) {
|
|
1651
1725
|
if (!context.sourceCode.text.includes("createContext")) return {};
|
|
1652
1726
|
const createCalls = [];
|
|
1653
1727
|
const displayNameAssignments = [];
|
|
@@ -1685,14 +1759,14 @@ function create28(context) {
|
|
|
1685
1759
|
}
|
|
1686
1760
|
};
|
|
1687
1761
|
}
|
|
1688
|
-
var
|
|
1689
|
-
var
|
|
1762
|
+
var RULE_NAME31 = "no-missing-key";
|
|
1763
|
+
var RULE_FEATURES31 = [];
|
|
1690
1764
|
var no_missing_key_default = createRule({
|
|
1691
1765
|
meta: {
|
|
1692
1766
|
type: "problem",
|
|
1693
1767
|
docs: {
|
|
1694
1768
|
description: "Disallow missing `key` on items in list rendering.",
|
|
1695
|
-
[Symbol.for("rule_features")]:
|
|
1769
|
+
[Symbol.for("rule_features")]: RULE_FEATURES31
|
|
1696
1770
|
},
|
|
1697
1771
|
messages: {
|
|
1698
1772
|
missingKey: "Missing 'key' for element when rendering list.",
|
|
@@ -1700,18 +1774,18 @@ var no_missing_key_default = createRule({
|
|
|
1700
1774
|
},
|
|
1701
1775
|
schema: []
|
|
1702
1776
|
},
|
|
1703
|
-
name:
|
|
1704
|
-
create:
|
|
1777
|
+
name: RULE_NAME31,
|
|
1778
|
+
create: create31,
|
|
1705
1779
|
defaultOptions: []
|
|
1706
1780
|
});
|
|
1707
|
-
function
|
|
1781
|
+
function create31(context) {
|
|
1708
1782
|
const report = createReport(context);
|
|
1709
1783
|
const state = { isWithinChildrenToArray: false };
|
|
1710
1784
|
function checkIteratorElement(node) {
|
|
1711
1785
|
switch (node.type) {
|
|
1712
1786
|
case AST_NODE_TYPES.JSXElement: {
|
|
1713
1787
|
const initialScope = context.sourceCode.getScope(node);
|
|
1714
|
-
if (!
|
|
1788
|
+
if (!JSX9.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1715
1789
|
return {
|
|
1716
1790
|
messageId: "missingKey",
|
|
1717
1791
|
node
|
|
@@ -1768,7 +1842,7 @@ function create29(context) {
|
|
|
1768
1842
|
}
|
|
1769
1843
|
const initialScope = context.sourceCode.getScope(node);
|
|
1770
1844
|
for (const element of elements) {
|
|
1771
|
-
if (!
|
|
1845
|
+
if (!JSX9.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1772
1846
|
report({
|
|
1773
1847
|
messageId: "missingKey",
|
|
1774
1848
|
node: element
|
|
@@ -1781,7 +1855,7 @@ function create29(context) {
|
|
|
1781
1855
|
if (state.isWithinChildrenToArray) {
|
|
1782
1856
|
return;
|
|
1783
1857
|
}
|
|
1784
|
-
const isMapCall = AST11.
|
|
1858
|
+
const isMapCall = AST11.isArrayMapCallLoose(node);
|
|
1785
1859
|
if (!isMapCall && !isArrayFromCall(node)) {
|
|
1786
1860
|
return;
|
|
1787
1861
|
}
|
|
@@ -1817,27 +1891,26 @@ function create29(context) {
|
|
|
1817
1891
|
function isArrayFromCall(node) {
|
|
1818
1892
|
return node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "from";
|
|
1819
1893
|
}
|
|
1820
|
-
var
|
|
1821
|
-
var
|
|
1894
|
+
var RULE_NAME32 = "no-nested-component-definitions";
|
|
1895
|
+
var RULE_FEATURES32 = [];
|
|
1822
1896
|
var no_nested_component_definitions_default = createRule({
|
|
1823
1897
|
meta: {
|
|
1824
1898
|
type: "problem",
|
|
1825
1899
|
docs: {
|
|
1826
1900
|
description: "Disallow nesting component definitions inside other components.",
|
|
1827
|
-
[Symbol.for("rule_features")]:
|
|
1901
|
+
[Symbol.for("rule_features")]: RULE_FEATURES32
|
|
1828
1902
|
},
|
|
1829
1903
|
messages: {
|
|
1830
|
-
|
|
1831
|
-
noNestedComponentDefinitionInProps: "Do not nest component definitions inside props. Move it to the top level or pass it as a prop."
|
|
1904
|
+
noNestedComponentDefinitions: "Do not nest component definitions inside other components or props. {{suggestion}}"
|
|
1832
1905
|
},
|
|
1833
1906
|
schema: []
|
|
1834
1907
|
},
|
|
1835
|
-
name:
|
|
1836
|
-
create:
|
|
1908
|
+
name: RULE_NAME32,
|
|
1909
|
+
create: create32,
|
|
1837
1910
|
defaultOptions: []
|
|
1838
1911
|
});
|
|
1839
|
-
function
|
|
1840
|
-
const hint = ERComponentHint.
|
|
1912
|
+
function create32(context) {
|
|
1913
|
+
const hint = ERComponentHint.SkipArrayMapArgument | ERComponentHint.SkipNullLiteral | ERComponentHint.SkipUndefined | ERComponentHint.SkipBooleanLiteral | ERComponentHint.SkipStringLiteral | ERComponentHint.SkipNumberLiteral | ERComponentHint.StrictLogical | ERComponentHint.StrictConditional;
|
|
1841
1914
|
const collector = useComponentCollector(context, { hint });
|
|
1842
1915
|
const collectorLegacy = useComponentCollectorLegacy();
|
|
1843
1916
|
return {
|
|
@@ -1862,10 +1935,11 @@ function create30(context) {
|
|
|
1862
1935
|
if (isInsideJSXAttributeValue(component)) {
|
|
1863
1936
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1864
1937
|
context.report({
|
|
1865
|
-
messageId: "
|
|
1938
|
+
messageId: "noNestedComponentDefinitions",
|
|
1866
1939
|
node: component,
|
|
1867
1940
|
data: {
|
|
1868
|
-
name: name5
|
|
1941
|
+
name: name5,
|
|
1942
|
+
suggestion: "Move it to the top level or pass it as a prop."
|
|
1869
1943
|
}
|
|
1870
1944
|
});
|
|
1871
1945
|
}
|
|
@@ -1873,10 +1947,11 @@ function create30(context) {
|
|
|
1873
1947
|
}
|
|
1874
1948
|
if (isInsideCreateElementProps(context, component)) {
|
|
1875
1949
|
context.report({
|
|
1876
|
-
messageId: "
|
|
1950
|
+
messageId: "noNestedComponentDefinitions",
|
|
1877
1951
|
node: component,
|
|
1878
1952
|
data: {
|
|
1879
|
-
name: name5
|
|
1953
|
+
name: name5,
|
|
1954
|
+
suggestion: "Move it to the top level or pass it as a prop."
|
|
1880
1955
|
}
|
|
1881
1956
|
});
|
|
1882
1957
|
continue;
|
|
@@ -1884,20 +1959,22 @@ function create30(context) {
|
|
|
1884
1959
|
const parentComponent = AST11.findParentNode(component, isFunctionComponent);
|
|
1885
1960
|
if (parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent)) {
|
|
1886
1961
|
context.report({
|
|
1887
|
-
messageId:
|
|
1962
|
+
messageId: "noNestedComponentDefinitions",
|
|
1888
1963
|
node: component,
|
|
1889
1964
|
data: {
|
|
1890
|
-
name: name5
|
|
1965
|
+
name: name5,
|
|
1966
|
+
suggestion: component.parent.type === AST_NODE_TYPES.Property ? "Move it to the top level or pass it as a prop." : "Move it to the top level."
|
|
1891
1967
|
}
|
|
1892
1968
|
});
|
|
1893
1969
|
continue;
|
|
1894
1970
|
}
|
|
1895
1971
|
if (isInsideRenderMethod(component)) {
|
|
1896
1972
|
context.report({
|
|
1897
|
-
messageId: "
|
|
1973
|
+
messageId: "noNestedComponentDefinitions",
|
|
1898
1974
|
node: component,
|
|
1899
1975
|
data: {
|
|
1900
|
-
name: name5
|
|
1976
|
+
name: name5,
|
|
1977
|
+
suggestion: "Move it to the top level."
|
|
1901
1978
|
}
|
|
1902
1979
|
});
|
|
1903
1980
|
}
|
|
@@ -1907,10 +1984,11 @@ function create30(context) {
|
|
|
1907
1984
|
continue;
|
|
1908
1985
|
}
|
|
1909
1986
|
context.report({
|
|
1910
|
-
messageId: "
|
|
1987
|
+
messageId: "noNestedComponentDefinitions",
|
|
1911
1988
|
node: component,
|
|
1912
1989
|
data: {
|
|
1913
|
-
name: name5
|
|
1990
|
+
name: name5,
|
|
1991
|
+
suggestion: component.parent.type === AST_NODE_TYPES.Property ? "Move it to the top level or pass it as a prop." : "Move it to the top level."
|
|
1914
1992
|
}
|
|
1915
1993
|
});
|
|
1916
1994
|
}
|
|
@@ -1918,7 +1996,7 @@ function create30(context) {
|
|
|
1918
1996
|
};
|
|
1919
1997
|
}
|
|
1920
1998
|
function isInsideJSXAttributeValue(node) {
|
|
1921
|
-
return node.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
1999
|
+
return node.parent.type === AST_NODE_TYPES.JSXAttribute || JSX9.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1922
2000
|
}
|
|
1923
2001
|
function isInsideCreateElementProps(context, node) {
|
|
1924
2002
|
const call = AST11.findParentNode(node, isCreateElementCall(context));
|
|
@@ -1927,25 +2005,25 @@ function isInsideCreateElementProps(context, node) {
|
|
|
1927
2005
|
if (prop == null) return false;
|
|
1928
2006
|
return prop === call.arguments[1];
|
|
1929
2007
|
}
|
|
1930
|
-
var
|
|
1931
|
-
var
|
|
2008
|
+
var RULE_NAME33 = "no-prop-types";
|
|
2009
|
+
var RULE_FEATURES33 = [];
|
|
1932
2010
|
var no_prop_types_default = createRule({
|
|
1933
2011
|
meta: {
|
|
1934
2012
|
type: "problem",
|
|
1935
2013
|
docs: {
|
|
1936
2014
|
description: "Disallow `propTypes` in favor of TypeScript or another type-checking solution.",
|
|
1937
|
-
[Symbol.for("rule_features")]:
|
|
2015
|
+
[Symbol.for("rule_features")]: RULE_FEATURES33
|
|
1938
2016
|
},
|
|
1939
2017
|
messages: {
|
|
1940
2018
|
noPropTypes: "[Deprecated] Use TypeScript or another type-checking solution instead."
|
|
1941
2019
|
},
|
|
1942
2020
|
schema: []
|
|
1943
2021
|
},
|
|
1944
|
-
name:
|
|
1945
|
-
create:
|
|
2022
|
+
name: RULE_NAME33,
|
|
2023
|
+
create: create33,
|
|
1946
2024
|
defaultOptions: []
|
|
1947
2025
|
});
|
|
1948
|
-
function
|
|
2026
|
+
function create33(context) {
|
|
1949
2027
|
if (!context.sourceCode.text.includes("propTypes")) {
|
|
1950
2028
|
return {};
|
|
1951
2029
|
}
|
|
@@ -1964,8 +2042,8 @@ function create31(context) {
|
|
|
1964
2042
|
if (!isComponentNameLoose(object.name)) {
|
|
1965
2043
|
return;
|
|
1966
2044
|
}
|
|
1967
|
-
const variable =
|
|
1968
|
-
const variableNode =
|
|
2045
|
+
const variable = VAR2.findVariable(object.name, context.sourceCode.getScope(node));
|
|
2046
|
+
const variableNode = VAR2.getVariableInitNode(variable, 0);
|
|
1969
2047
|
if (variableNode != null && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
|
|
1970
2048
|
context.report({ messageId: "noPropTypes", node: property });
|
|
1971
2049
|
}
|
|
@@ -1981,8 +2059,8 @@ function create31(context) {
|
|
|
1981
2059
|
}
|
|
1982
2060
|
};
|
|
1983
2061
|
}
|
|
1984
|
-
var
|
|
1985
|
-
var
|
|
2062
|
+
var RULE_NAME34 = "no-redundant-should-component-update";
|
|
2063
|
+
var RULE_FEATURES34 = [];
|
|
1986
2064
|
function isShouldComponentUpdate(node) {
|
|
1987
2065
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
1988
2066
|
}
|
|
@@ -1991,18 +2069,18 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1991
2069
|
type: "problem",
|
|
1992
2070
|
docs: {
|
|
1993
2071
|
description: "Disallow `shouldComponentUpdate` when extending `React.PureComponent`.",
|
|
1994
|
-
[Symbol.for("rule_features")]:
|
|
2072
|
+
[Symbol.for("rule_features")]: RULE_FEATURES34
|
|
1995
2073
|
},
|
|
1996
2074
|
messages: {
|
|
1997
2075
|
noRedundantShouldComponentUpdate: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'."
|
|
1998
2076
|
},
|
|
1999
2077
|
schema: []
|
|
2000
2078
|
},
|
|
2001
|
-
name:
|
|
2002
|
-
create:
|
|
2079
|
+
name: RULE_NAME34,
|
|
2080
|
+
create: create34,
|
|
2003
2081
|
defaultOptions: []
|
|
2004
2082
|
});
|
|
2005
|
-
function
|
|
2083
|
+
function create34(context) {
|
|
2006
2084
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
2007
2085
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2008
2086
|
return {
|
|
@@ -2029,8 +2107,8 @@ function create32(context) {
|
|
|
2029
2107
|
}
|
|
2030
2108
|
};
|
|
2031
2109
|
}
|
|
2032
|
-
var
|
|
2033
|
-
var
|
|
2110
|
+
var RULE_NAME35 = "no-set-state-in-component-did-mount";
|
|
2111
|
+
var RULE_FEATURES35 = [];
|
|
2034
2112
|
function isComponentDidMount(node) {
|
|
2035
2113
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
|
|
2036
2114
|
}
|
|
@@ -2039,18 +2117,18 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2039
2117
|
type: "problem",
|
|
2040
2118
|
docs: {
|
|
2041
2119
|
description: "Disallow calling `this.setState` in `componentDidMount` outside of functions, such as callbacks.",
|
|
2042
|
-
[Symbol.for("rule_features")]:
|
|
2120
|
+
[Symbol.for("rule_features")]: RULE_FEATURES35
|
|
2043
2121
|
},
|
|
2044
2122
|
messages: {
|
|
2045
2123
|
noSetStateInComponentDidMount: "Do not call `this.setState` in `componentDidMount` outside of functions, such as callbacks."
|
|
2046
2124
|
},
|
|
2047
2125
|
schema: []
|
|
2048
2126
|
},
|
|
2049
|
-
name:
|
|
2050
|
-
create:
|
|
2127
|
+
name: RULE_NAME35,
|
|
2128
|
+
create: create35,
|
|
2051
2129
|
defaultOptions: []
|
|
2052
2130
|
});
|
|
2053
|
-
function
|
|
2131
|
+
function create35(context) {
|
|
2054
2132
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2055
2133
|
return {
|
|
2056
2134
|
CallExpression(node) {
|
|
@@ -2071,8 +2149,8 @@ function create33(context) {
|
|
|
2071
2149
|
}
|
|
2072
2150
|
};
|
|
2073
2151
|
}
|
|
2074
|
-
var
|
|
2075
|
-
var
|
|
2152
|
+
var RULE_NAME36 = "no-set-state-in-component-did-update";
|
|
2153
|
+
var RULE_FEATURES36 = [];
|
|
2076
2154
|
function isComponentDidUpdate(node) {
|
|
2077
2155
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
|
|
2078
2156
|
}
|
|
@@ -2081,18 +2159,18 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2081
2159
|
type: "problem",
|
|
2082
2160
|
docs: {
|
|
2083
2161
|
description: "Disallows calling `this.setState` in `componentDidUpdate` outside of functions, such as callbacks.",
|
|
2084
|
-
[Symbol.for("rule_features")]:
|
|
2162
|
+
[Symbol.for("rule_features")]: RULE_FEATURES36
|
|
2085
2163
|
},
|
|
2086
2164
|
messages: {
|
|
2087
2165
|
noSetStateInComponentDidUpdate: "Do not call `this.setState` in `componentDidUpdate` outside of functions, such as callbacks."
|
|
2088
2166
|
},
|
|
2089
2167
|
schema: []
|
|
2090
2168
|
},
|
|
2091
|
-
name:
|
|
2092
|
-
create:
|
|
2169
|
+
name: RULE_NAME36,
|
|
2170
|
+
create: create36,
|
|
2093
2171
|
defaultOptions: []
|
|
2094
2172
|
});
|
|
2095
|
-
function
|
|
2173
|
+
function create36(context) {
|
|
2096
2174
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2097
2175
|
return {
|
|
2098
2176
|
CallExpression(node) {
|
|
@@ -2113,8 +2191,8 @@ function create34(context) {
|
|
|
2113
2191
|
}
|
|
2114
2192
|
};
|
|
2115
2193
|
}
|
|
2116
|
-
var
|
|
2117
|
-
var
|
|
2194
|
+
var RULE_NAME37 = "no-set-state-in-component-will-update";
|
|
2195
|
+
var RULE_FEATURES37 = [];
|
|
2118
2196
|
function isComponentWillUpdate3(node) {
|
|
2119
2197
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
|
|
2120
2198
|
}
|
|
@@ -2123,18 +2201,18 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2123
2201
|
type: "problem",
|
|
2124
2202
|
docs: {
|
|
2125
2203
|
description: "Disallows calling `this.setState` in `componentWillUpdate` outside of functions, such as callbacks.",
|
|
2126
|
-
[Symbol.for("rule_features")]:
|
|
2204
|
+
[Symbol.for("rule_features")]: RULE_FEATURES37
|
|
2127
2205
|
},
|
|
2128
2206
|
messages: {
|
|
2129
2207
|
noSetStateInComponentWillUpdate: "Do not call `this.setState` in `componentWillUpdate` outside of functions, such as callbacks."
|
|
2130
2208
|
},
|
|
2131
2209
|
schema: []
|
|
2132
2210
|
},
|
|
2133
|
-
name:
|
|
2134
|
-
create:
|
|
2211
|
+
name: RULE_NAME37,
|
|
2212
|
+
create: create37,
|
|
2135
2213
|
defaultOptions: []
|
|
2136
2214
|
});
|
|
2137
|
-
function
|
|
2215
|
+
function create37(context) {
|
|
2138
2216
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2139
2217
|
return {
|
|
2140
2218
|
CallExpression(node) {
|
|
@@ -2155,8 +2233,8 @@ function create35(context) {
|
|
|
2155
2233
|
}
|
|
2156
2234
|
};
|
|
2157
2235
|
}
|
|
2158
|
-
var
|
|
2159
|
-
var
|
|
2236
|
+
var RULE_NAME38 = "no-string-refs";
|
|
2237
|
+
var RULE_FEATURES38 = [];
|
|
2160
2238
|
function containsStringLiteral({ value }) {
|
|
2161
2239
|
return value?.type === AST_NODE_TYPES.Literal && typeof value.value === "string";
|
|
2162
2240
|
}
|
|
@@ -2174,18 +2252,18 @@ var no_string_refs_default = createRule({
|
|
|
2174
2252
|
type: "problem",
|
|
2175
2253
|
docs: {
|
|
2176
2254
|
description: "Disallow deprecated string `refs`.",
|
|
2177
|
-
[Symbol.for("rule_features")]:
|
|
2255
|
+
[Symbol.for("rule_features")]: RULE_FEATURES38
|
|
2178
2256
|
},
|
|
2179
2257
|
messages: {
|
|
2180
2258
|
noStringRefs: "[Deprecated] Use callback refs instead."
|
|
2181
2259
|
},
|
|
2182
2260
|
schema: []
|
|
2183
2261
|
},
|
|
2184
|
-
name:
|
|
2185
|
-
create:
|
|
2262
|
+
name: RULE_NAME38,
|
|
2263
|
+
create: create38,
|
|
2186
2264
|
defaultOptions: []
|
|
2187
2265
|
});
|
|
2188
|
-
function
|
|
2266
|
+
function create38(context) {
|
|
2189
2267
|
return {
|
|
2190
2268
|
JSXAttribute(node) {
|
|
2191
2269
|
if (node.name.name !== "ref") {
|
|
@@ -2200,8 +2278,8 @@ function create36(context) {
|
|
|
2200
2278
|
}
|
|
2201
2279
|
};
|
|
2202
2280
|
}
|
|
2203
|
-
var
|
|
2204
|
-
var
|
|
2281
|
+
var RULE_NAME39 = "no-unsafe-component-will-mount";
|
|
2282
|
+
var RULE_FEATURES39 = [];
|
|
2205
2283
|
function isUnsafeComponentWillMount(node) {
|
|
2206
2284
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
|
|
2207
2285
|
}
|
|
@@ -2210,18 +2288,18 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2210
2288
|
type: "problem",
|
|
2211
2289
|
docs: {
|
|
2212
2290
|
description: "Warns the usage of `UNSAFE_componentWillMount` in class components.",
|
|
2213
|
-
[Symbol.for("rule_features")]:
|
|
2291
|
+
[Symbol.for("rule_features")]: RULE_FEATURES39
|
|
2214
2292
|
},
|
|
2215
2293
|
messages: {
|
|
2216
2294
|
noUnsafeComponentWillMount: "Do not use 'UNSAFE_componentWillMount'."
|
|
2217
2295
|
},
|
|
2218
2296
|
schema: []
|
|
2219
2297
|
},
|
|
2220
|
-
name:
|
|
2221
|
-
create:
|
|
2298
|
+
name: RULE_NAME39,
|
|
2299
|
+
create: create39,
|
|
2222
2300
|
defaultOptions: []
|
|
2223
2301
|
});
|
|
2224
|
-
function
|
|
2302
|
+
function create39(context) {
|
|
2225
2303
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2226
2304
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2227
2305
|
return {
|
|
@@ -2242,8 +2320,8 @@ function create37(context) {
|
|
|
2242
2320
|
}
|
|
2243
2321
|
};
|
|
2244
2322
|
}
|
|
2245
|
-
var
|
|
2246
|
-
var
|
|
2323
|
+
var RULE_NAME40 = "no-unsafe-component-will-receive-props";
|
|
2324
|
+
var RULE_FEATURES40 = [];
|
|
2247
2325
|
function isUnsafeComponentWillReceiveProps(node) {
|
|
2248
2326
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
|
|
2249
2327
|
}
|
|
@@ -2252,18 +2330,18 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2252
2330
|
type: "problem",
|
|
2253
2331
|
docs: {
|
|
2254
2332
|
description: "Warns the usage of `UNSAFE_componentWillReceiveProps` in class components.",
|
|
2255
|
-
[Symbol.for("rule_features")]:
|
|
2333
|
+
[Symbol.for("rule_features")]: RULE_FEATURES40
|
|
2256
2334
|
},
|
|
2257
2335
|
messages: {
|
|
2258
2336
|
noUnsafeComponentWillReceiveProps: "Do not use 'UNSAFE_componentWillReceiveProps'."
|
|
2259
2337
|
},
|
|
2260
2338
|
schema: []
|
|
2261
2339
|
},
|
|
2262
|
-
name:
|
|
2263
|
-
create:
|
|
2340
|
+
name: RULE_NAME40,
|
|
2341
|
+
create: create40,
|
|
2264
2342
|
defaultOptions: []
|
|
2265
2343
|
});
|
|
2266
|
-
function
|
|
2344
|
+
function create40(context) {
|
|
2267
2345
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) {
|
|
2268
2346
|
return {};
|
|
2269
2347
|
}
|
|
@@ -2286,8 +2364,8 @@ function create38(context) {
|
|
|
2286
2364
|
}
|
|
2287
2365
|
};
|
|
2288
2366
|
}
|
|
2289
|
-
var
|
|
2290
|
-
var
|
|
2367
|
+
var RULE_NAME41 = "no-unsafe-component-will-update";
|
|
2368
|
+
var RULE_FEATURES41 = [];
|
|
2291
2369
|
function isUnsafeComponentWillUpdate(node) {
|
|
2292
2370
|
return AST11.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
|
|
2293
2371
|
}
|
|
@@ -2296,18 +2374,18 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2296
2374
|
type: "problem",
|
|
2297
2375
|
docs: {
|
|
2298
2376
|
description: "Warns the usage of `UNSAFE_componentWillUpdate` in class components.",
|
|
2299
|
-
[Symbol.for("rule_features")]:
|
|
2377
|
+
[Symbol.for("rule_features")]: RULE_FEATURES41
|
|
2300
2378
|
},
|
|
2301
2379
|
messages: {
|
|
2302
2380
|
noUnsafeComponentWillUpdate: "Do not use 'UNSAFE_componentWillUpdate'."
|
|
2303
2381
|
},
|
|
2304
2382
|
schema: []
|
|
2305
2383
|
},
|
|
2306
|
-
name:
|
|
2307
|
-
create:
|
|
2384
|
+
name: RULE_NAME41,
|
|
2385
|
+
create: create41,
|
|
2308
2386
|
defaultOptions: []
|
|
2309
2387
|
});
|
|
2310
|
-
function
|
|
2388
|
+
function create41(context) {
|
|
2311
2389
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2312
2390
|
const { ctx, listeners } = useComponentCollectorLegacy();
|
|
2313
2391
|
return {
|
|
@@ -2328,25 +2406,25 @@ function create39(context) {
|
|
|
2328
2406
|
}
|
|
2329
2407
|
};
|
|
2330
2408
|
}
|
|
2331
|
-
var
|
|
2332
|
-
var
|
|
2409
|
+
var RULE_NAME42 = "no-unstable-context-value";
|
|
2410
|
+
var RULE_FEATURES42 = [];
|
|
2333
2411
|
var no_unstable_context_value_default = createRule({
|
|
2334
2412
|
meta: {
|
|
2335
2413
|
type: "problem",
|
|
2336
2414
|
docs: {
|
|
2337
2415
|
description: "Prevents non-stable values (i.e. object literals) from being used as a value for `Context.Provider`.",
|
|
2338
|
-
[Symbol.for("rule_features")]:
|
|
2416
|
+
[Symbol.for("rule_features")]: RULE_FEATURES42
|
|
2339
2417
|
},
|
|
2340
2418
|
messages: {
|
|
2341
2419
|
unstableContextValue: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}"
|
|
2342
2420
|
},
|
|
2343
2421
|
schema: []
|
|
2344
2422
|
},
|
|
2345
|
-
name:
|
|
2346
|
-
create:
|
|
2423
|
+
name: RULE_NAME42,
|
|
2424
|
+
create: create42,
|
|
2347
2425
|
defaultOptions: []
|
|
2348
2426
|
});
|
|
2349
|
-
function
|
|
2427
|
+
function create42(context) {
|
|
2350
2428
|
const { version: version2 } = getSettingsFromContext(context);
|
|
2351
2429
|
const isReact18OrBelow = compare(version2, "19.0.0", "<");
|
|
2352
2430
|
const { ctx, listeners } = useComponentCollector(context);
|
|
@@ -2354,7 +2432,7 @@ function create40(context) {
|
|
|
2354
2432
|
return {
|
|
2355
2433
|
...listeners,
|
|
2356
2434
|
JSXOpeningElement(node) {
|
|
2357
|
-
const fullName =
|
|
2435
|
+
const fullName = JSX9.getElementType(node.parent);
|
|
2358
2436
|
const selfName = fullName.split(".").at(-1);
|
|
2359
2437
|
if (selfName == null) return;
|
|
2360
2438
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
@@ -2368,7 +2446,7 @@ function create40(context) {
|
|
|
2368
2446
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2369
2447
|
const valueExpression = value.expression;
|
|
2370
2448
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2371
|
-
const construction =
|
|
2449
|
+
const construction = VAR2.getValueConstruction(valueExpression, initialScope);
|
|
2372
2450
|
if (construction == null) return;
|
|
2373
2451
|
if (isReactHookCall(construction.node)) {
|
|
2374
2452
|
return;
|
|
@@ -2401,25 +2479,25 @@ function isContextName(name5, isReact18OrBelow) {
|
|
|
2401
2479
|
}
|
|
2402
2480
|
return false;
|
|
2403
2481
|
}
|
|
2404
|
-
var
|
|
2405
|
-
var
|
|
2482
|
+
var RULE_NAME43 = "no-unstable-default-props";
|
|
2483
|
+
var RULE_FEATURES43 = [];
|
|
2406
2484
|
var no_unstable_default_props_default = createRule({
|
|
2407
2485
|
meta: {
|
|
2408
2486
|
type: "problem",
|
|
2409
2487
|
docs: {
|
|
2410
2488
|
description: "Prevents using referential-type values as default props in object destructuring.",
|
|
2411
|
-
[Symbol.for("rule_features")]:
|
|
2489
|
+
[Symbol.for("rule_features")]: RULE_FEATURES43
|
|
2412
2490
|
},
|
|
2413
2491
|
messages: {
|
|
2414
2492
|
noUnstableDefaultProps: "A/an '{{forbiddenType}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{forbiddenType}}'."
|
|
2415
2493
|
},
|
|
2416
2494
|
schema: []
|
|
2417
2495
|
},
|
|
2418
|
-
name:
|
|
2419
|
-
create:
|
|
2496
|
+
name: RULE_NAME43,
|
|
2497
|
+
create: create43,
|
|
2420
2498
|
defaultOptions: []
|
|
2421
2499
|
});
|
|
2422
|
-
function
|
|
2500
|
+
function create43(context) {
|
|
2423
2501
|
const { ctx, listeners } = useComponentCollector(context);
|
|
2424
2502
|
const declarators = /* @__PURE__ */ new Map();
|
|
2425
2503
|
return {
|
|
@@ -2442,10 +2520,10 @@ function create41(context) {
|
|
|
2442
2520
|
const { value } = prop;
|
|
2443
2521
|
const { right } = value;
|
|
2444
2522
|
const initialScope = context.sourceCode.getScope(value);
|
|
2445
|
-
const construction =
|
|
2523
|
+
const construction = VAR2.getValueConstruction(
|
|
2446
2524
|
value,
|
|
2447
2525
|
initialScope,
|
|
2448
|
-
|
|
2526
|
+
VAR2.ValueConstructionHint.StrictCallExpression
|
|
2449
2527
|
);
|
|
2450
2528
|
if (construction == null) {
|
|
2451
2529
|
continue;
|
|
@@ -2475,8 +2553,8 @@ function create41(context) {
|
|
|
2475
2553
|
}
|
|
2476
2554
|
};
|
|
2477
2555
|
}
|
|
2478
|
-
var
|
|
2479
|
-
var
|
|
2556
|
+
var RULE_NAME44 = "no-unused-class-component-members";
|
|
2557
|
+
var RULE_FEATURES44 = [];
|
|
2480
2558
|
var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
|
|
2481
2559
|
"componentDidCatch",
|
|
2482
2560
|
"componentDidMount",
|
|
@@ -2502,18 +2580,18 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2502
2580
|
type: "problem",
|
|
2503
2581
|
docs: {
|
|
2504
2582
|
description: "Warns unused class component methods and properties.",
|
|
2505
|
-
[Symbol.for("rule_features")]:
|
|
2583
|
+
[Symbol.for("rule_features")]: RULE_FEATURES44
|
|
2506
2584
|
},
|
|
2507
2585
|
messages: {
|
|
2508
2586
|
noUnusedClassComponentMembers: "Unused method or property '{{methodName}}'' of class '{{className}}'."
|
|
2509
2587
|
},
|
|
2510
2588
|
schema: []
|
|
2511
2589
|
},
|
|
2512
|
-
name:
|
|
2513
|
-
create:
|
|
2590
|
+
name: RULE_NAME44,
|
|
2591
|
+
create: create44,
|
|
2514
2592
|
defaultOptions: []
|
|
2515
2593
|
});
|
|
2516
|
-
function
|
|
2594
|
+
function create44(context) {
|
|
2517
2595
|
const classEntries = [];
|
|
2518
2596
|
const methodEntries = [];
|
|
2519
2597
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
@@ -2623,8 +2701,8 @@ function create42(context) {
|
|
|
2623
2701
|
}
|
|
2624
2702
|
};
|
|
2625
2703
|
}
|
|
2626
|
-
var
|
|
2627
|
-
var
|
|
2704
|
+
var RULE_NAME45 = "no-unused-state";
|
|
2705
|
+
var RULE_FEATURES45 = [];
|
|
2628
2706
|
function isKeyLiteral3(node, key) {
|
|
2629
2707
|
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);
|
|
2630
2708
|
}
|
|
@@ -2633,18 +2711,18 @@ var no_unused_state_default = createRule({
|
|
|
2633
2711
|
type: "problem",
|
|
2634
2712
|
docs: {
|
|
2635
2713
|
description: "Warns unused class component state.",
|
|
2636
|
-
[Symbol.for("rule_features")]:
|
|
2714
|
+
[Symbol.for("rule_features")]: RULE_FEATURES45
|
|
2637
2715
|
},
|
|
2638
2716
|
messages: {
|
|
2639
2717
|
noUnusedState: "Unused class component state in '{{className}}'"
|
|
2640
2718
|
},
|
|
2641
2719
|
schema: []
|
|
2642
2720
|
},
|
|
2643
|
-
name:
|
|
2644
|
-
create:
|
|
2721
|
+
name: RULE_NAME45,
|
|
2722
|
+
create: create45,
|
|
2645
2723
|
defaultOptions: []
|
|
2646
2724
|
});
|
|
2647
|
-
function
|
|
2725
|
+
function create45(context) {
|
|
2648
2726
|
const classEntries = [];
|
|
2649
2727
|
const methodEntries = [];
|
|
2650
2728
|
const constructorEntries = [];
|
|
@@ -2778,8 +2856,8 @@ function create43(context) {
|
|
|
2778
2856
|
}
|
|
2779
2857
|
};
|
|
2780
2858
|
}
|
|
2781
|
-
var
|
|
2782
|
-
var
|
|
2859
|
+
var RULE_NAME46 = "no-use-context";
|
|
2860
|
+
var RULE_FEATURES46 = [
|
|
2783
2861
|
"MOD"
|
|
2784
2862
|
];
|
|
2785
2863
|
var no_use_context_default = createRule({
|
|
@@ -2787,7 +2865,7 @@ var no_use_context_default = createRule({
|
|
|
2787
2865
|
type: "problem",
|
|
2788
2866
|
docs: {
|
|
2789
2867
|
description: "Replaces usages of `useContext` with `use`.",
|
|
2790
|
-
[Symbol.for("rule_features")]:
|
|
2868
|
+
[Symbol.for("rule_features")]: RULE_FEATURES46
|
|
2791
2869
|
},
|
|
2792
2870
|
fixable: "code",
|
|
2793
2871
|
messages: {
|
|
@@ -2795,11 +2873,11 @@ var no_use_context_default = createRule({
|
|
|
2795
2873
|
},
|
|
2796
2874
|
schema: []
|
|
2797
2875
|
},
|
|
2798
|
-
name:
|
|
2799
|
-
create:
|
|
2876
|
+
name: RULE_NAME46,
|
|
2877
|
+
create: create46,
|
|
2800
2878
|
defaultOptions: []
|
|
2801
2879
|
});
|
|
2802
|
-
function
|
|
2880
|
+
function create46(context) {
|
|
2803
2881
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
2804
2882
|
const settings4 = getSettingsFromContext(context);
|
|
2805
2883
|
const useContextAlias = /* @__PURE__ */ new Set();
|
|
@@ -2877,25 +2955,25 @@ function getAssociatedTokens(context, node) {
|
|
|
2877
2955
|
return tokens;
|
|
2878
2956
|
}
|
|
2879
2957
|
}
|
|
2880
|
-
var
|
|
2881
|
-
var
|
|
2958
|
+
var RULE_NAME47 = "no-useless-forward-ref";
|
|
2959
|
+
var RULE_FEATURES47 = [];
|
|
2882
2960
|
var no_useless_forward_ref_default = createRule({
|
|
2883
2961
|
meta: {
|
|
2884
2962
|
type: "problem",
|
|
2885
2963
|
docs: {
|
|
2886
2964
|
description: "Disallow useless `forwardRef` calls on components that don't use `ref`s.",
|
|
2887
|
-
[Symbol.for("rule_features")]:
|
|
2965
|
+
[Symbol.for("rule_features")]: RULE_FEATURES47
|
|
2888
2966
|
},
|
|
2889
2967
|
messages: {
|
|
2890
2968
|
noUselessForwardRef: "A 'forwardRef' is used with this component but no 'ref' parameter is set."
|
|
2891
2969
|
},
|
|
2892
2970
|
schema: []
|
|
2893
2971
|
},
|
|
2894
|
-
name:
|
|
2895
|
-
create:
|
|
2972
|
+
name: RULE_NAME47,
|
|
2973
|
+
create: create47,
|
|
2896
2974
|
defaultOptions: []
|
|
2897
2975
|
});
|
|
2898
|
-
function
|
|
2976
|
+
function create47(context) {
|
|
2899
2977
|
return {
|
|
2900
2978
|
CallExpression(node) {
|
|
2901
2979
|
if (!isForwardRefCall(context, node)) {
|
|
@@ -2916,7 +2994,7 @@ function create45(context) {
|
|
|
2916
2994
|
}
|
|
2917
2995
|
};
|
|
2918
2996
|
}
|
|
2919
|
-
var
|
|
2997
|
+
var RULE_NAME48 = "no-useless-fragment";
|
|
2920
2998
|
var defaultOptions = [{
|
|
2921
2999
|
allowExpressions: true
|
|
2922
3000
|
}];
|
|
@@ -2942,15 +3020,15 @@ var no_useless_fragment_default = createRule({
|
|
|
2942
3020
|
}
|
|
2943
3021
|
}]
|
|
2944
3022
|
},
|
|
2945
|
-
name:
|
|
2946
|
-
create:
|
|
3023
|
+
name: RULE_NAME48,
|
|
3024
|
+
create: create48,
|
|
2947
3025
|
defaultOptions
|
|
2948
3026
|
});
|
|
2949
|
-
function
|
|
3027
|
+
function create48(context, [option]) {
|
|
2950
3028
|
const { allowExpressions = true } = option;
|
|
2951
3029
|
return {
|
|
2952
3030
|
JSXElement(node) {
|
|
2953
|
-
if (!
|
|
3031
|
+
if (!JSX9.isFragmentElement(node)) return;
|
|
2954
3032
|
doCheck(context, node, allowExpressions);
|
|
2955
3033
|
},
|
|
2956
3034
|
JSXFragment(node) {
|
|
@@ -2972,12 +3050,12 @@ function doCheck(context, node, allowExpressions) {
|
|
|
2972
3050
|
return null;
|
|
2973
3051
|
}
|
|
2974
3052
|
if (node.children.some(
|
|
2975
|
-
(child) =>
|
|
3053
|
+
(child) => JSX9.isLiteral(child) && !JSX9.isWhiteSpace(child) || AST11.is(AST_NODE_TYPES.JSXExpressionContainer)(child)
|
|
2976
3054
|
)) {
|
|
2977
3055
|
return null;
|
|
2978
3056
|
}
|
|
2979
3057
|
}
|
|
2980
|
-
if (
|
|
3058
|
+
if (JSX9.isUserDefinedElement(node.parent)) {
|
|
2981
3059
|
return null;
|
|
2982
3060
|
}
|
|
2983
3061
|
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
@@ -2986,10 +3064,10 @@ function doCheck(context, node, allowExpressions) {
|
|
|
2986
3064
|
return fixer.replaceText(node, trimLikeReact(childrenText));
|
|
2987
3065
|
}
|
|
2988
3066
|
const initialScope = context.sourceCode.getScope(node);
|
|
2989
|
-
if (
|
|
3067
|
+
if (JSX9.isKeyedElement(node, initialScope)) {
|
|
2990
3068
|
return;
|
|
2991
3069
|
}
|
|
2992
|
-
if (
|
|
3070
|
+
if (JSX9.isBuiltInElement(node.parent)) {
|
|
2993
3071
|
context.report({
|
|
2994
3072
|
messageId: "uselessFragment",
|
|
2995
3073
|
node,
|
|
@@ -3013,7 +3091,7 @@ function doCheck(context, node, allowExpressions) {
|
|
|
3013
3091
|
const isChildElement = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
3014
3092
|
switch (true) {
|
|
3015
3093
|
// <Foo content={<>ee eeee eeee ...</>} />
|
|
3016
|
-
case (allowExpressions && !isChildElement && node.children.length === 1 &&
|
|
3094
|
+
case (allowExpressions && !isChildElement && node.children.length === 1 && JSX9.isLiteral(node.children.at(0))): {
|
|
3017
3095
|
return;
|
|
3018
3096
|
}
|
|
3019
3097
|
// <Foo><>hello, world</></Foo>
|
|
@@ -3040,7 +3118,7 @@ function doCheck(context, node, allowExpressions) {
|
|
|
3040
3118
|
return;
|
|
3041
3119
|
}
|
|
3042
3120
|
}
|
|
3043
|
-
const nonPaddingChildren = node.children.filter((child) => !
|
|
3121
|
+
const nonPaddingChildren = node.children.filter((child) => !JSX9.isPaddingSpaces(child));
|
|
3044
3122
|
const firstNonPaddingChild = nonPaddingChildren.at(0);
|
|
3045
3123
|
switch (true) {
|
|
3046
3124
|
case nonPaddingChildren.length === 0:
|
|
@@ -3058,8 +3136,8 @@ function doCheck(context, node, allowExpressions) {
|
|
|
3058
3136
|
}
|
|
3059
3137
|
return;
|
|
3060
3138
|
}
|
|
3061
|
-
var
|
|
3062
|
-
var
|
|
3139
|
+
var RULE_NAME49 = "prefer-destructuring-assignment";
|
|
3140
|
+
var RULE_FEATURES48 = [];
|
|
3063
3141
|
function isMemberExpressionWithObjectName(node) {
|
|
3064
3142
|
return node.object.type === AST_NODE_TYPES.Identifier && "name" in node.object;
|
|
3065
3143
|
}
|
|
@@ -3068,18 +3146,18 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3068
3146
|
type: "problem",
|
|
3069
3147
|
docs: {
|
|
3070
3148
|
description: "Enforces destructuring assignment for component props and context.",
|
|
3071
|
-
[Symbol.for("rule_features")]:
|
|
3149
|
+
[Symbol.for("rule_features")]: RULE_FEATURES48
|
|
3072
3150
|
},
|
|
3073
3151
|
messages: {
|
|
3074
3152
|
preferDestructuringAssignment: "Use destructuring assignment for {{name}}."
|
|
3075
3153
|
},
|
|
3076
3154
|
schema: []
|
|
3077
3155
|
},
|
|
3078
|
-
name:
|
|
3079
|
-
create:
|
|
3156
|
+
name: RULE_NAME49,
|
|
3157
|
+
create: create49,
|
|
3080
3158
|
defaultOptions: []
|
|
3081
3159
|
});
|
|
3082
|
-
function
|
|
3160
|
+
function create49(context) {
|
|
3083
3161
|
const { ctx, listeners } = useComponentCollector(context);
|
|
3084
3162
|
const memberExpressionWithNames = [];
|
|
3085
3163
|
return {
|
|
@@ -3139,16 +3217,17 @@ function create47(context) {
|
|
|
3139
3217
|
}
|
|
3140
3218
|
};
|
|
3141
3219
|
}
|
|
3142
|
-
var
|
|
3143
|
-
var
|
|
3144
|
-
"FIX"
|
|
3220
|
+
var RULE_NAME50 = "prefer-react-namespace-import";
|
|
3221
|
+
var RULE_FEATURES49 = [
|
|
3222
|
+
"FIX",
|
|
3223
|
+
"EXP"
|
|
3145
3224
|
];
|
|
3146
3225
|
var prefer_react_namespace_import_default = createRule({
|
|
3147
3226
|
meta: {
|
|
3148
3227
|
type: "problem",
|
|
3149
3228
|
docs: {
|
|
3150
3229
|
description: "Enforces React is imported via a namespace import.",
|
|
3151
|
-
[Symbol.for("rule_features")]:
|
|
3230
|
+
[Symbol.for("rule_features")]: RULE_FEATURES49
|
|
3152
3231
|
},
|
|
3153
3232
|
fixable: "code",
|
|
3154
3233
|
messages: {
|
|
@@ -3156,11 +3235,11 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
3156
3235
|
},
|
|
3157
3236
|
schema: []
|
|
3158
3237
|
},
|
|
3159
|
-
name:
|
|
3160
|
-
create:
|
|
3238
|
+
name: RULE_NAME50,
|
|
3239
|
+
create: create50,
|
|
3161
3240
|
defaultOptions: []
|
|
3162
3241
|
});
|
|
3163
|
-
function
|
|
3242
|
+
function create50(context) {
|
|
3164
3243
|
const { importSource } = getSettingsFromContext(context);
|
|
3165
3244
|
return {
|
|
3166
3245
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
@@ -3193,27 +3272,28 @@ ${importStringPrefix} ${specifiers} from ${importSourceQuoted}${semiColon}`
|
|
|
3193
3272
|
}
|
|
3194
3273
|
};
|
|
3195
3274
|
}
|
|
3196
|
-
var
|
|
3197
|
-
var
|
|
3198
|
-
"TSC"
|
|
3275
|
+
var RULE_NAME51 = "prefer-read-only-props";
|
|
3276
|
+
var RULE_FEATURES50 = [
|
|
3277
|
+
"TSC",
|
|
3278
|
+
"EXP"
|
|
3199
3279
|
];
|
|
3200
3280
|
var prefer_read_only_props_default = createRule({
|
|
3201
3281
|
meta: {
|
|
3202
3282
|
type: "problem",
|
|
3203
3283
|
docs: {
|
|
3204
3284
|
description: "Enforces read-only props in components.",
|
|
3205
|
-
[Symbol.for("rule_features")]:
|
|
3285
|
+
[Symbol.for("rule_features")]: RULE_FEATURES50
|
|
3206
3286
|
},
|
|
3207
3287
|
messages: {
|
|
3208
3288
|
preferReadOnlyProps: "A function component's props should be read-only."
|
|
3209
3289
|
},
|
|
3210
3290
|
schema: []
|
|
3211
3291
|
},
|
|
3212
|
-
name:
|
|
3213
|
-
create:
|
|
3292
|
+
name: RULE_NAME51,
|
|
3293
|
+
create: create51,
|
|
3214
3294
|
defaultOptions: []
|
|
3215
3295
|
});
|
|
3216
|
-
function
|
|
3296
|
+
function create51(context) {
|
|
3217
3297
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3218
3298
|
const { ctx, listeners } = useComponentCollector(context);
|
|
3219
3299
|
return {
|
|
@@ -3243,8 +3323,8 @@ function isTypeReadonlyLoose(services, type) {
|
|
|
3243
3323
|
return true;
|
|
3244
3324
|
}
|
|
3245
3325
|
}
|
|
3246
|
-
var
|
|
3247
|
-
var
|
|
3326
|
+
var RULE_NAME52 = "prefer-shorthand-boolean";
|
|
3327
|
+
var RULE_FEATURES51 = [
|
|
3248
3328
|
"FIX"
|
|
3249
3329
|
];
|
|
3250
3330
|
var prefer_shorthand_boolean_default = createRule({
|
|
@@ -3252,7 +3332,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3252
3332
|
type: "problem",
|
|
3253
3333
|
docs: {
|
|
3254
3334
|
description: "Enforces shorthand syntax for boolean attributes.",
|
|
3255
|
-
[Symbol.for("rule_features")]:
|
|
3335
|
+
[Symbol.for("rule_features")]: RULE_FEATURES51
|
|
3256
3336
|
},
|
|
3257
3337
|
fixable: "code",
|
|
3258
3338
|
messages: {
|
|
@@ -3260,15 +3340,15 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3260
3340
|
},
|
|
3261
3341
|
schema: []
|
|
3262
3342
|
},
|
|
3263
|
-
name:
|
|
3264
|
-
create:
|
|
3343
|
+
name: RULE_NAME52,
|
|
3344
|
+
create: create52,
|
|
3265
3345
|
defaultOptions: []
|
|
3266
3346
|
});
|
|
3267
|
-
function
|
|
3347
|
+
function create52(context) {
|
|
3268
3348
|
return {
|
|
3269
3349
|
JSXAttribute(node) {
|
|
3270
3350
|
const { value } = node;
|
|
3271
|
-
const propName =
|
|
3351
|
+
const propName = JSX9.getAttributeName(node);
|
|
3272
3352
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3273
3353
|
if (!hasValueTrue) {
|
|
3274
3354
|
return;
|
|
@@ -3284,8 +3364,8 @@ function create50(context) {
|
|
|
3284
3364
|
}
|
|
3285
3365
|
};
|
|
3286
3366
|
}
|
|
3287
|
-
var
|
|
3288
|
-
var
|
|
3367
|
+
var RULE_NAME53 = "prefer-shorthand-fragment";
|
|
3368
|
+
var RULE_FEATURES52 = [
|
|
3289
3369
|
"FIX"
|
|
3290
3370
|
];
|
|
3291
3371
|
var prefer_shorthand_fragment_default = createRule({
|
|
@@ -3293,7 +3373,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3293
3373
|
type: "problem",
|
|
3294
3374
|
docs: {
|
|
3295
3375
|
description: "Enforces shorthand syntax for fragments.",
|
|
3296
|
-
[Symbol.for("rule_features")]:
|
|
3376
|
+
[Symbol.for("rule_features")]: RULE_FEATURES52
|
|
3297
3377
|
},
|
|
3298
3378
|
fixable: "code",
|
|
3299
3379
|
messages: {
|
|
@@ -3301,14 +3381,14 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3301
3381
|
},
|
|
3302
3382
|
schema: []
|
|
3303
3383
|
},
|
|
3304
|
-
name:
|
|
3305
|
-
create:
|
|
3384
|
+
name: RULE_NAME53,
|
|
3385
|
+
create: create53,
|
|
3306
3386
|
defaultOptions: []
|
|
3307
3387
|
});
|
|
3308
|
-
function
|
|
3388
|
+
function create53(context) {
|
|
3309
3389
|
return {
|
|
3310
3390
|
JSXElement(node) {
|
|
3311
|
-
if (!
|
|
3391
|
+
if (!JSX9.isFragmentElement(node)) return;
|
|
3312
3392
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3313
3393
|
if (hasAttributes) {
|
|
3314
3394
|
return;
|
|
@@ -3330,46 +3410,6 @@ function create51(context) {
|
|
|
3330
3410
|
}
|
|
3331
3411
|
};
|
|
3332
3412
|
}
|
|
3333
|
-
var RULE_NAME52 = "use-jsx-vars";
|
|
3334
|
-
var RULE_FEATURES51 = [];
|
|
3335
|
-
var use_jsx_vars_default = createRule({
|
|
3336
|
-
meta: {
|
|
3337
|
-
type: "problem",
|
|
3338
|
-
docs: {
|
|
3339
|
-
description: "Marks variables used in JSX as used.",
|
|
3340
|
-
[Symbol.for("rule_features")]: RULE_FEATURES51
|
|
3341
|
-
},
|
|
3342
|
-
messages: {
|
|
3343
|
-
useJsxVars: ""
|
|
3344
|
-
},
|
|
3345
|
-
schema: []
|
|
3346
|
-
},
|
|
3347
|
-
name: RULE_NAME52,
|
|
3348
|
-
create: create52,
|
|
3349
|
-
defaultOptions: []
|
|
3350
|
-
});
|
|
3351
|
-
function create52(context) {
|
|
3352
|
-
return {
|
|
3353
|
-
JSXOpeningElement(node) {
|
|
3354
|
-
switch (node.name.type) {
|
|
3355
|
-
case AST_NODE_TYPES.JSXIdentifier: {
|
|
3356
|
-
if (/^[a-z]/u.test(node.name.name)) {
|
|
3357
|
-
return;
|
|
3358
|
-
}
|
|
3359
|
-
context.sourceCode.markVariableAsUsed(node.name.name, node);
|
|
3360
|
-
break;
|
|
3361
|
-
}
|
|
3362
|
-
case AST_NODE_TYPES.JSXMemberExpression: {
|
|
3363
|
-
const { object } = node.name;
|
|
3364
|
-
if (object.type === AST_NODE_TYPES.JSXIdentifier) {
|
|
3365
|
-
context.sourceCode.markVariableAsUsed(object.name, node);
|
|
3366
|
-
}
|
|
3367
|
-
break;
|
|
3368
|
-
}
|
|
3369
|
-
}
|
|
3370
|
-
}
|
|
3371
|
-
};
|
|
3372
|
-
}
|
|
3373
3413
|
|
|
3374
3414
|
// src/plugin.ts
|
|
3375
3415
|
var plugin = {
|
|
@@ -3399,7 +3439,6 @@ var plugin = {
|
|
|
3399
3439
|
"no-create-ref": no_create_ref_default,
|
|
3400
3440
|
"no-default-props": no_default_props_default,
|
|
3401
3441
|
"no-direct-mutation-state": no_direct_mutation_state_default,
|
|
3402
|
-
"no-duplicate-jsx-props": no_duplicate_jsx_props_default,
|
|
3403
3442
|
"no-duplicate-key": no_duplicate_key_default,
|
|
3404
3443
|
"no-forward-ref": no_forward_ref_default,
|
|
3405
3444
|
"no-implicit-key": no_implicit_key_default,
|
|
@@ -3429,18 +3468,21 @@ var plugin = {
|
|
|
3429
3468
|
"prefer-read-only-props": prefer_read_only_props_default,
|
|
3430
3469
|
"prefer-shorthand-boolean": prefer_shorthand_boolean_default,
|
|
3431
3470
|
"prefer-shorthand-fragment": prefer_shorthand_fragment_default,
|
|
3432
|
-
|
|
3471
|
+
// Part: JSX only rules
|
|
3472
|
+
"jsx-no-duplicate-props": jsx_no_duplicate_props_default,
|
|
3473
|
+
"jsx-no-undef": jsx_no_undef_default,
|
|
3474
|
+
"jsx-uses-vars": jsx_uses_vars_default,
|
|
3433
3475
|
// Part: deprecated rules
|
|
3434
3476
|
/** @deprecated Use `no-useless-forward-ref` instead */
|
|
3435
3477
|
"ensure-forward-ref-using-ref": no_useless_forward_ref_default,
|
|
3436
|
-
/** @deprecated Use `no-duplicate-jsx-props` instead */
|
|
3437
|
-
"jsx-no-duplicate-props": no_duplicate_jsx_props_default,
|
|
3438
|
-
/** @deprecated Use `use-jsx-vars` instead */
|
|
3439
|
-
"jsx-uses-vars": use_jsx_vars_default,
|
|
3440
3478
|
/** @deprecated Use `no-complex-conditional-rendering` instead */
|
|
3441
3479
|
"no-complicated-conditional-rendering": no_complex_conditional_rendering_default,
|
|
3480
|
+
/** @deprecated Use `jsx-no-duplicate-props` instead */
|
|
3481
|
+
"no-duplicate-jsx-props": jsx_no_duplicate_props_default,
|
|
3442
3482
|
/** @deprecated Use `no-nested-component-definitions` instead */
|
|
3443
|
-
"no-nested-components": no_nested_component_definitions_default
|
|
3483
|
+
"no-nested-components": no_nested_component_definitions_default,
|
|
3484
|
+
/** @deprecated Use `jsx-uses-vars` instead */
|
|
3485
|
+
"use-jsx-vars": jsx_uses_vars_default
|
|
3444
3486
|
}
|
|
3445
3487
|
};
|
|
3446
3488
|
|