eslint-plugin-react-x 1.23.3-next.3 → 1.23.3-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +49 -43
- package/dist/index.mjs +51 -45
- package/package.json +16 -16
package/dist/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.23.3-next.
|
|
45
|
+
var version = "1.23.3-next.5";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -299,16 +299,6 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
299
299
|
["reduceRight", 2],
|
|
300
300
|
["some", 1]
|
|
301
301
|
]);
|
|
302
|
-
var isToStringCall = tsPattern.isMatching({
|
|
303
|
-
type: types.AST_NODE_TYPES.CallExpression,
|
|
304
|
-
callee: {
|
|
305
|
-
type: types.AST_NODE_TYPES.MemberExpression,
|
|
306
|
-
property: {
|
|
307
|
-
type: types.AST_NODE_TYPES.Identifier,
|
|
308
|
-
name: "toString"
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
302
|
function isReactChildrenMethod(name2) {
|
|
313
303
|
return reactChildrenMethod.some((method) => method === name2);
|
|
314
304
|
}
|
|
@@ -375,40 +365,57 @@ var no_array_index_key_default = createRule({
|
|
|
375
365
|
name: RULE_NAME5,
|
|
376
366
|
create(context) {
|
|
377
367
|
const indexParamNames = [];
|
|
378
|
-
const isCreateOrCloneElementCall = eff.or(core.isCreateElementCall(context), core.isCloneElementCall(context));
|
|
379
368
|
function isArrayIndex(node) {
|
|
380
369
|
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some(eff.O.exists((name2) => name2 === node.name));
|
|
381
370
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
return [
|
|
371
|
+
function isCreateOrCloneElementCall(node) {
|
|
372
|
+
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
373
|
+
}
|
|
374
|
+
function getReportDescriptors(node) {
|
|
375
|
+
switch (node.type) {
|
|
376
|
+
// key={bar}
|
|
377
|
+
case types.AST_NODE_TYPES.Identifier: {
|
|
378
|
+
if (indexParamNames.some(eff.O.exists((name2) => name2 === node.name))) {
|
|
379
|
+
return [{
|
|
380
|
+
messageId: "noArrayIndexKey",
|
|
381
|
+
node
|
|
382
|
+
}];
|
|
391
383
|
}
|
|
392
|
-
return acc;
|
|
393
|
-
}, []);
|
|
394
|
-
}
|
|
395
|
-
if (isToStringCall(node)) {
|
|
396
|
-
if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
|
|
397
384
|
return [];
|
|
398
385
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
386
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
387
|
+
case types.AST_NODE_TYPES.TemplateLiteral:
|
|
388
|
+
case types.AST_NODE_TYPES.BinaryExpression: {
|
|
389
|
+
const descriptors = [];
|
|
390
|
+
const expressions = node.type === types.AST_NODE_TYPES.TemplateLiteral ? node.expressions : AST11__namespace.getIdentifiersFromBinaryExpression(node);
|
|
391
|
+
for (const expression of expressions) {
|
|
392
|
+
if (isArrayIndex(expression)) {
|
|
393
|
+
descriptors.push({
|
|
394
|
+
messageId: "noArrayIndexKey",
|
|
395
|
+
node: expression
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return descriptors;
|
|
400
|
+
}
|
|
401
|
+
// key={bar.toString()} or key={String(bar)}
|
|
402
|
+
case types.AST_NODE_TYPES.CallExpression: {
|
|
403
|
+
switch (true) {
|
|
404
|
+
// key={bar.toString()}
|
|
405
|
+
case (node.callee.type === types.AST_NODE_TYPES.MemberExpression && node.callee.property.type === types.AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object)): {
|
|
406
|
+
return [{
|
|
407
|
+
messageId: "noArrayIndexKey",
|
|
408
|
+
node: node.callee.object
|
|
409
|
+
}];
|
|
410
|
+
}
|
|
411
|
+
// key={String(bar)}
|
|
412
|
+
case (node.callee.type === types.AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] && isArrayIndex(node.arguments[0])): {
|
|
413
|
+
return [{
|
|
414
|
+
messageId: "noArrayIndexKey",
|
|
415
|
+
node: node.arguments[0]
|
|
416
|
+
}];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
421
|
return [];
|
|
@@ -433,7 +440,7 @@ var no_array_index_key_default = createRule({
|
|
|
433
440
|
if (!("value" in prop)) {
|
|
434
441
|
continue;
|
|
435
442
|
}
|
|
436
|
-
const descriptors =
|
|
443
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
437
444
|
for (const descriptor of descriptors) {
|
|
438
445
|
context.report(descriptor);
|
|
439
446
|
}
|
|
@@ -449,11 +456,10 @@ var no_array_index_key_default = createRule({
|
|
|
449
456
|
if (indexParamNames.length === 0) {
|
|
450
457
|
return;
|
|
451
458
|
}
|
|
452
|
-
|
|
453
|
-
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
459
|
+
if (node.value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
454
460
|
return;
|
|
455
461
|
}
|
|
456
|
-
const descriptors =
|
|
462
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
457
463
|
for (const descriptor of descriptors) {
|
|
458
464
|
context.report(descriptor);
|
|
459
465
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F, O,
|
|
1
|
+
import { F, O, isString, not, or, isNullable } from '@eslint-react/eff';
|
|
2
2
|
import * as JSX7 from '@eslint-react/jsx';
|
|
3
3
|
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
|
|
4
4
|
import * as AST11 from '@eslint-react/ast';
|
|
5
|
-
import { isForwardRefCall, isThisSetState, isClassComponent,
|
|
5
|
+
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var name = "eslint-plugin-react-x";
|
|
18
|
-
var version = "1.23.3-next.
|
|
18
|
+
var version = "1.23.3-next.5";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -272,16 +272,6 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
272
272
|
["reduceRight", 2],
|
|
273
273
|
["some", 1]
|
|
274
274
|
]);
|
|
275
|
-
var isToStringCall = isMatching({
|
|
276
|
-
type: AST_NODE_TYPES.CallExpression,
|
|
277
|
-
callee: {
|
|
278
|
-
type: AST_NODE_TYPES.MemberExpression,
|
|
279
|
-
property: {
|
|
280
|
-
type: AST_NODE_TYPES.Identifier,
|
|
281
|
-
name: "toString"
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
275
|
function isReactChildrenMethod(name2) {
|
|
286
276
|
return reactChildrenMethod.some((method) => method === name2);
|
|
287
277
|
}
|
|
@@ -348,40 +338,57 @@ var no_array_index_key_default = createRule({
|
|
|
348
338
|
name: RULE_NAME5,
|
|
349
339
|
create(context) {
|
|
350
340
|
const indexParamNames = [];
|
|
351
|
-
const isCreateOrCloneElementCall = or(isCreateElementCall(context), isCloneElementCall(context));
|
|
352
341
|
function isArrayIndex(node) {
|
|
353
342
|
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some(O.exists((name2) => name2 === node.name));
|
|
354
343
|
}
|
|
355
|
-
function
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if (
|
|
363
|
-
return [
|
|
344
|
+
function isCreateOrCloneElementCall(node) {
|
|
345
|
+
return isCreateElementCall(node, context) || isCloneElementCall(node, context);
|
|
346
|
+
}
|
|
347
|
+
function getReportDescriptors(node) {
|
|
348
|
+
switch (node.type) {
|
|
349
|
+
// key={bar}
|
|
350
|
+
case AST_NODE_TYPES.Identifier: {
|
|
351
|
+
if (indexParamNames.some(O.exists((name2) => name2 === node.name))) {
|
|
352
|
+
return [{
|
|
353
|
+
messageId: "noArrayIndexKey",
|
|
354
|
+
node
|
|
355
|
+
}];
|
|
364
356
|
}
|
|
365
|
-
return acc;
|
|
366
|
-
}, []);
|
|
367
|
-
}
|
|
368
|
-
if (isToStringCall(node)) {
|
|
369
|
-
if (!("object" in node.callee && isArrayIndex(node.callee.object))) {
|
|
370
357
|
return [];
|
|
371
358
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
359
|
+
// key={`foo-${bar}`} or key={'foo' + bar}
|
|
360
|
+
case AST_NODE_TYPES.TemplateLiteral:
|
|
361
|
+
case AST_NODE_TYPES.BinaryExpression: {
|
|
362
|
+
const descriptors = [];
|
|
363
|
+
const expressions = node.type === AST_NODE_TYPES.TemplateLiteral ? node.expressions : AST11.getIdentifiersFromBinaryExpression(node);
|
|
364
|
+
for (const expression of expressions) {
|
|
365
|
+
if (isArrayIndex(expression)) {
|
|
366
|
+
descriptors.push({
|
|
367
|
+
messageId: "noArrayIndexKey",
|
|
368
|
+
node: expression
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return descriptors;
|
|
373
|
+
}
|
|
374
|
+
// key={bar.toString()} or key={String(bar)}
|
|
375
|
+
case AST_NODE_TYPES.CallExpression: {
|
|
376
|
+
switch (true) {
|
|
377
|
+
// key={bar.toString()}
|
|
378
|
+
case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "toString" && isArrayIndex(node.callee.object)): {
|
|
379
|
+
return [{
|
|
380
|
+
messageId: "noArrayIndexKey",
|
|
381
|
+
node: node.callee.object
|
|
382
|
+
}];
|
|
383
|
+
}
|
|
384
|
+
// key={String(bar)}
|
|
385
|
+
case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === "String" && node.arguments[0] && isArrayIndex(node.arguments[0])): {
|
|
386
|
+
return [{
|
|
387
|
+
messageId: "noArrayIndexKey",
|
|
388
|
+
node: node.arguments[0]
|
|
389
|
+
}];
|
|
390
|
+
}
|
|
391
|
+
}
|
|
385
392
|
}
|
|
386
393
|
}
|
|
387
394
|
return [];
|
|
@@ -406,7 +413,7 @@ var no_array_index_key_default = createRule({
|
|
|
406
413
|
if (!("value" in prop)) {
|
|
407
414
|
continue;
|
|
408
415
|
}
|
|
409
|
-
const descriptors =
|
|
416
|
+
const descriptors = getReportDescriptors(prop.value);
|
|
410
417
|
for (const descriptor of descriptors) {
|
|
411
418
|
context.report(descriptor);
|
|
412
419
|
}
|
|
@@ -422,11 +429,10 @@ var no_array_index_key_default = createRule({
|
|
|
422
429
|
if (indexParamNames.length === 0) {
|
|
423
430
|
return;
|
|
424
431
|
}
|
|
425
|
-
|
|
426
|
-
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
432
|
+
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
|
|
427
433
|
return;
|
|
428
434
|
}
|
|
429
|
-
const descriptors =
|
|
435
|
+
const descriptors = getReportDescriptors(node.value.expression);
|
|
430
436
|
for (const descriptor of descriptors) {
|
|
431
437
|
context.report(descriptor);
|
|
432
438
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.23.3-next.
|
|
3
|
+
"version": "1.23.3-next.5",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "Eva1ent<rel1cx@proton.me>",
|
|
23
|
-
"sideEffects": false,
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
25
|
"import": {
|
|
@@ -35,7 +34,6 @@
|
|
|
35
34
|
"./package.json": "./package.json"
|
|
36
35
|
},
|
|
37
36
|
"main": "dist/index.js",
|
|
38
|
-
"module": "dist/index.mjs",
|
|
39
37
|
"types": "dist/index.d.ts",
|
|
40
38
|
"files": [
|
|
41
39
|
"dist",
|
|
@@ -50,34 +48,34 @@
|
|
|
50
48
|
"is-immutable-type": "^5.0.1",
|
|
51
49
|
"string-ts": "^2.2.0",
|
|
52
50
|
"ts-pattern": "^5.6.0",
|
|
53
|
-
"@eslint-react/ast": "1.23.3-next.
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
58
|
-
"@eslint-react/
|
|
59
|
-
"@eslint-react/
|
|
51
|
+
"@eslint-react/ast": "1.23.3-next.5",
|
|
52
|
+
"@eslint-react/core": "1.23.3-next.5",
|
|
53
|
+
"@eslint-react/eff": "1.23.3-next.5",
|
|
54
|
+
"@eslint-react/shared": "1.23.3-next.5",
|
|
55
|
+
"@eslint-react/types": "1.23.3-next.5",
|
|
56
|
+
"@eslint-react/var": "1.23.3-next.5",
|
|
57
|
+
"@eslint-react/jsx": "1.23.3-next.5"
|
|
60
58
|
},
|
|
61
59
|
"devDependencies": {
|
|
62
|
-
"@types/react": "^19.0.
|
|
60
|
+
"@types/react": "^19.0.4",
|
|
63
61
|
"@types/react-dom": "^19.0.2",
|
|
64
|
-
"tsup": "^8.3.5",
|
|
65
62
|
"ts-api-utils": "^2.0.0",
|
|
63
|
+
"tsup": "^8.3.5",
|
|
66
64
|
"@workspace/configs": "0.0.0"
|
|
67
65
|
},
|
|
68
66
|
"peerDependencies": {
|
|
69
67
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
68
|
+
"ts-api-utils": "^2.0.0",
|
|
69
|
+
"typescript": "^4.9.5 || ^5.3.3"
|
|
72
70
|
},
|
|
73
71
|
"peerDependenciesMeta": {
|
|
74
72
|
"eslint": {
|
|
75
73
|
"optional": false
|
|
76
74
|
},
|
|
77
|
-
"
|
|
75
|
+
"ts-api-utils": {
|
|
78
76
|
"optional": true
|
|
79
77
|
},
|
|
80
|
-
"
|
|
78
|
+
"typescript": {
|
|
81
79
|
"optional": true
|
|
82
80
|
}
|
|
83
81
|
},
|
|
@@ -88,6 +86,8 @@
|
|
|
88
86
|
"publishConfig": {
|
|
89
87
|
"access": "public"
|
|
90
88
|
},
|
|
89
|
+
"sideEffects": false,
|
|
90
|
+
"module": "dist/index.mjs",
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "tsup --dts-resolve",
|
|
93
93
|
"lint:publish": "publint",
|