eslint-plugin-react-x 5.24.9 → 5.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +19 -22
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -135,7 +135,7 @@ const rules$6 = {
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region package.json
|
|
137
137
|
var name$6 = "eslint-plugin-react-x";
|
|
138
|
-
var version = "5.
|
|
138
|
+
var version = "5.25.0";
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/utils/create-rule.ts
|
|
141
141
|
function getDocsUrl(ruleName) {
|
|
@@ -1709,7 +1709,8 @@ function create$47(context) {
|
|
|
1709
1709
|
}
|
|
1710
1710
|
//#endregion
|
|
1711
1711
|
//#region src/rules/no-array-index-key/lib.ts
|
|
1712
|
-
const
|
|
1712
|
+
const KNOWN_COERCION_FUNCTIONS = /* @__PURE__ */ new Set(["Number", "String"]);
|
|
1713
|
+
const KNOWN_INDEX_PARAM_POSITIONS = /* @__PURE__ */ new Map([
|
|
1713
1714
|
["every", 1],
|
|
1714
1715
|
["filter", 1],
|
|
1715
1716
|
["find", 1],
|
|
@@ -1735,7 +1736,7 @@ function isArrayIndexReference(context, node) {
|
|
|
1735
1736
|
const callee = Extract.unwrap(call.callee);
|
|
1736
1737
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1737
1738
|
if (!Check.isIdentifier(callee.property)) return false;
|
|
1738
|
-
const indexPosition =
|
|
1739
|
+
const indexPosition = KNOWN_INDEX_PARAM_POSITIONS.get(callee.property.name);
|
|
1739
1740
|
if (indexPosition == null) return false;
|
|
1740
1741
|
const callbackPosition = core.isChildrenMap(context, callee) || core.isChildrenForEach(context, callee) ? 1 : 0;
|
|
1741
1742
|
if (call.arguments[callbackPosition] !== argument) return false;
|
|
@@ -1748,10 +1749,6 @@ function getIdentifiersFromBinaryExpression(side) {
|
|
|
1748
1749
|
if (side.type === AST_NODE_TYPES.BinaryExpression) return [...getIdentifiersFromBinaryExpression(side.left), ...getIdentifiersFromBinaryExpression(side.right)];
|
|
1749
1750
|
return [];
|
|
1750
1751
|
}
|
|
1751
|
-
//#endregion
|
|
1752
|
-
//#region src/rules/no-array-index-key/no-array-index-key.ts
|
|
1753
|
-
const RULE_NAME$46 = "no-array-index-key";
|
|
1754
|
-
const COERCION_FUNCTIONS = /* @__PURE__ */ new Set(["Number", "String"]);
|
|
1755
1752
|
var no_array_index_key_default = createRule({
|
|
1756
1753
|
meta: {
|
|
1757
1754
|
type: "suggestion",
|
|
@@ -1759,12 +1756,12 @@ var no_array_index_key_default = createRule({
|
|
|
1759
1756
|
messages: { default: "Do not use item index in the array as its key." },
|
|
1760
1757
|
schema: []
|
|
1761
1758
|
},
|
|
1762
|
-
name:
|
|
1759
|
+
name: "no-array-index-key",
|
|
1763
1760
|
create: create$46
|
|
1764
1761
|
});
|
|
1765
1762
|
function create$46(context) {
|
|
1766
1763
|
function isArrayIndex(node) {
|
|
1767
|
-
return Check.isIdentifier(node) && isArrayIndexReference(context, node);
|
|
1764
|
+
return node != null && Check.isIdentifier(node) && isArrayIndexReference(context, node);
|
|
1768
1765
|
}
|
|
1769
1766
|
function getPropsObject(node) {
|
|
1770
1767
|
const props = node.arguments[1];
|
|
@@ -1795,7 +1792,7 @@ function create$46(context) {
|
|
|
1795
1792
|
node: callee.object
|
|
1796
1793
|
}];
|
|
1797
1794
|
const argument = node.arguments.at(0);
|
|
1798
|
-
if (callee.type === AST_NODE_TYPES.Identifier &&
|
|
1795
|
+
if (callee.type === AST_NODE_TYPES.Identifier && KNOWN_COERCION_FUNCTIONS.has(callee.name) && isArrayIndex(argument)) return [{
|
|
1799
1796
|
messageId: "default",
|
|
1800
1797
|
node: argument
|
|
1801
1798
|
}];
|
|
@@ -2239,7 +2236,7 @@ function create$34(context) {
|
|
|
2239
2236
|
const hooks = hc.api.getAllHooks(node);
|
|
2240
2237
|
const funcs = [...comps, ...hooks];
|
|
2241
2238
|
for (const call of facts) {
|
|
2242
|
-
if (Traverse.
|
|
2239
|
+
if (!Traverse.hasParent(call, (n) => funcs.some((f) => f.node === n))) continue;
|
|
2243
2240
|
context.report({
|
|
2244
2241
|
messageId: "default",
|
|
2245
2242
|
node: call
|
|
@@ -2694,7 +2691,7 @@ function create$25(context) {
|
|
|
2694
2691
|
}
|
|
2695
2692
|
//#endregion
|
|
2696
2693
|
//#region src/rules/no-missing-key/lib.ts
|
|
2697
|
-
const
|
|
2694
|
+
const KNOWN_CALLBACK_POSITIONS = /* @__PURE__ */ new Map([
|
|
2698
2695
|
["flatMap", 0],
|
|
2699
2696
|
["from", 1],
|
|
2700
2697
|
["map", 0]
|
|
@@ -2704,7 +2701,7 @@ function getNestedReturnStatements$1(node) {
|
|
|
2704
2701
|
const boundary = Check.isFunction(node) ? node : Traverse.findParent(node, Check.isFunction);
|
|
2705
2702
|
simpleTraverse(node, { enter(node) {
|
|
2706
2703
|
if (node.type !== AST_NODE_TYPES.ReturnStatement) return;
|
|
2707
|
-
if (Traverse.
|
|
2704
|
+
if (Traverse.hasParent(node, Check.isFunction, (n) => n === boundary)) return;
|
|
2708
2705
|
statements.push(node);
|
|
2709
2706
|
} });
|
|
2710
2707
|
return statements;
|
|
@@ -2726,7 +2723,7 @@ function getIteratorCallback(node) {
|
|
|
2726
2723
|
const callee = Extract.unwrap(node.callee);
|
|
2727
2724
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
2728
2725
|
if (!Check.isIdentifier(callee.property)) return null;
|
|
2729
|
-
const position =
|
|
2726
|
+
const position = KNOWN_CALLBACK_POSITIONS.get(callee.property.name);
|
|
2730
2727
|
if (position == null) return null;
|
|
2731
2728
|
const callback = node.arguments[position];
|
|
2732
2729
|
if (callback == null || !Check.isFunction(callback)) return null;
|
|
@@ -2822,7 +2819,7 @@ function create$23(context) {
|
|
|
2822
2819
|
return {
|
|
2823
2820
|
CallExpression(node) {
|
|
2824
2821
|
if (!core.isCaptureOwnerStackCall(context, node)) return;
|
|
2825
|
-
if (Traverse.
|
|
2822
|
+
if (!Traverse.hasParent(node, (n) => isDevelopmentOnlyCheck(context, n))) context.report({
|
|
2826
2823
|
messageId: "missing-development-only-check",
|
|
2827
2824
|
node
|
|
2828
2825
|
});
|
|
@@ -2908,7 +2905,7 @@ function isInsideJSXAttributeValue(node) {
|
|
|
2908
2905
|
return node.parent.type === AST_NODE_TYPES.JSXAttribute || findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
2909
2906
|
}
|
|
2910
2907
|
function isInsideRenderMethod(node) {
|
|
2911
|
-
return Traverse.
|
|
2908
|
+
return Traverse.hasParent(node, (n) => core.isRenderMethodLike(n) && core.isClassComponent(n.parent.parent));
|
|
2912
2909
|
}
|
|
2913
2910
|
var no_nested_component_definitions_default = createRule({
|
|
2914
2911
|
meta: {
|
|
@@ -3005,7 +3002,7 @@ function create$21(context) {
|
|
|
3005
3002
|
...hc.api.getAllHooks(program),
|
|
3006
3003
|
...cc.api.getAllComponents(program)
|
|
3007
3004
|
];
|
|
3008
|
-
for (const lazy of lazyCalls) if (Traverse.
|
|
3005
|
+
for (const lazy of lazyCalls) if (Traverse.hasParent(lazy, (n) => significantParents.some((p) => p.node === n))) context.report({
|
|
3009
3006
|
messageId: "default",
|
|
3010
3007
|
node: lazy
|
|
3011
3008
|
});
|
|
@@ -6970,7 +6967,7 @@ const KNOWN_DYNAMIC_EXPRESSION_TYPES = /* @__PURE__ */ new Set([
|
|
|
6970
6967
|
]);
|
|
6971
6968
|
function createRenderBoundaryChecker(componentNodes) {
|
|
6972
6969
|
const components = new Set(componentNodes);
|
|
6973
|
-
return (node) => Traverse.
|
|
6970
|
+
return (node) => Traverse.hasParent(node, (n) => (Check.isFunction(n) || Check.isClass(n)) && components.has(n));
|
|
6974
6971
|
}
|
|
6975
6972
|
//#endregion
|
|
6976
6973
|
//#region src/rules/static-components/origins.ts
|
|
@@ -7170,7 +7167,7 @@ function getNestedReturnStatements(node) {
|
|
|
7170
7167
|
const boundary = Check.isFunction(node) ? node : Traverse.findParent(node, Check.isFunction);
|
|
7171
7168
|
simpleTraverse(node, { enter(node) {
|
|
7172
7169
|
if (node.type !== AST_NODE_TYPES.ReturnStatement) return;
|
|
7173
|
-
if (Traverse.
|
|
7170
|
+
if (Traverse.hasParent(node, Check.isFunction, (n) => n === boundary)) return;
|
|
7174
7171
|
statements.push(node);
|
|
7175
7172
|
} });
|
|
7176
7173
|
return statements;
|
|
@@ -7183,7 +7180,7 @@ function createFactCollector(isUseMemoCall) {
|
|
|
7183
7180
|
const writes = [];
|
|
7184
7181
|
function pushWrite(node, target) {
|
|
7185
7182
|
if (!Check.isIdentifier(target)) return;
|
|
7186
|
-
if (Traverse.
|
|
7183
|
+
if (Traverse.hasParent(node, Check.isFunction, (n) => n === callback)) return;
|
|
7187
7184
|
writes.push({
|
|
7188
7185
|
node,
|
|
7189
7186
|
target
|
|
@@ -7434,7 +7431,7 @@ function create(context) {
|
|
|
7434
7431
|
for (const expr of getNestedNewExpressions(useStateInput)) {
|
|
7435
7432
|
if (!hasProperty(expr.callee, "name")) continue;
|
|
7436
7433
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
7437
|
-
if (Traverse.
|
|
7434
|
+
if (Traverse.hasParent(expr, core.isUseCall(context))) continue;
|
|
7438
7435
|
context.report({
|
|
7439
7436
|
messageId: "invalid-initialization",
|
|
7440
7437
|
node: expr
|
|
@@ -7444,7 +7441,7 @@ function create(context) {
|
|
|
7444
7441
|
if (!hasProperty(expr.callee, "name")) continue;
|
|
7445
7442
|
if (core.isHookName(expr.callee.name)) continue;
|
|
7446
7443
|
if (LAZY_INIT_ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
7447
|
-
if (Traverse.
|
|
7444
|
+
if (Traverse.hasParent(expr, core.isUseCall(context))) continue;
|
|
7448
7445
|
context.report({
|
|
7449
7446
|
messageId: "invalid-initialization",
|
|
7450
7447
|
node: expr
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0",
|
|
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",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@eslint-react/ast": "5.
|
|
40
|
-
"@eslint-react/core": "5.
|
|
41
|
-
"@eslint-react/eslint": "5.
|
|
42
|
-
"@eslint-react/jsx": "5.
|
|
43
|
-
"@eslint-react/shared": "5.
|
|
44
|
-
"@eslint-react/var": "5.
|
|
39
|
+
"@eslint-react/ast": "5.25.0",
|
|
40
|
+
"@eslint-react/core": "5.25.0",
|
|
41
|
+
"@eslint-react/eslint": "5.25.0",
|
|
42
|
+
"@eslint-react/jsx": "5.25.0",
|
|
43
|
+
"@eslint-react/shared": "5.25.0",
|
|
44
|
+
"@eslint-react/var": "5.25.0",
|
|
45
45
|
"@typescript-eslint/scope-manager": "^8.71.1",
|
|
46
46
|
"@typescript-eslint/types": "^8.71.1",
|
|
47
47
|
"@typescript-eslint/typescript-estree": "^8.71.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"eslint": "^10.12.0",
|
|
63
63
|
"react": "^19.3.0",
|
|
64
64
|
"react-dom": "^19.3.0",
|
|
65
|
-
"tsdown": "^0.23.
|
|
65
|
+
"tsdown": "^0.23.1",
|
|
66
66
|
"tsl": "^1.0.30",
|
|
67
67
|
"tsl-dx": "^0.14.0",
|
|
68
68
|
"typescript": "6.0.3"
|