eslint-plugin-react-x 5.18.6 → 5.18.8
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 +80 -74
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ const rules$6 = {
|
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region package.json
|
|
147
147
|
var name$6 = "eslint-plugin-react-x";
|
|
148
|
-
var version = "5.18.
|
|
148
|
+
var version = "5.18.8";
|
|
149
149
|
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/utils/create-rule.ts
|
|
@@ -1163,12 +1163,12 @@ function resolveGlobalOrigin(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
|
1163
1163
|
if (seen.has(expression)) return null;
|
|
1164
1164
|
seen.add(expression);
|
|
1165
1165
|
if (expression.type === AST_NODE_TYPES.MemberExpression) return resolveGlobalOrigin(context, expression.object, seen);
|
|
1166
|
-
if (expression
|
|
1166
|
+
if (!Check.isIdentifier(expression)) return null;
|
|
1167
1167
|
if (isGlobalVariable(context, expression)) return expression;
|
|
1168
1168
|
const variable = findVariable(context.sourceCode.getScope(expression), expression);
|
|
1169
1169
|
const definition = variable?.defs.length === 1 ? variable.defs[0] : null;
|
|
1170
1170
|
if (definition?.type !== DefinitionType.Variable) return null;
|
|
1171
|
-
if (definition.node.id
|
|
1171
|
+
if (!Check.isIdentifier(definition.node.id) || definition.node.init == null) return null;
|
|
1172
1172
|
if (definition.node.parent.kind !== "const") return null;
|
|
1173
1173
|
const initializer = Extract.unwrap(definition.node.init);
|
|
1174
1174
|
if (initializer.type !== AST_NODE_TYPES.Identifier && initializer.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
@@ -1197,7 +1197,7 @@ function getAssignmentTargets(node) {
|
|
|
1197
1197
|
function resolveToFunction(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
1198
1198
|
const expression = Extract.unwrap(node);
|
|
1199
1199
|
if (Check.isFunction(expression)) return expression;
|
|
1200
|
-
if (expression
|
|
1200
|
+
if (!Check.isIdentifier(expression) || seen.has(expression)) return null;
|
|
1201
1201
|
seen.add(expression);
|
|
1202
1202
|
const resolved = resolve(context, expression);
|
|
1203
1203
|
if (resolved == null) return null;
|
|
@@ -1242,7 +1242,7 @@ function create$49(context) {
|
|
|
1242
1242
|
directEffects.set(enclosing, effects);
|
|
1243
1243
|
}
|
|
1244
1244
|
function recordWrite(node, target) {
|
|
1245
|
-
if (target
|
|
1245
|
+
if (Check.isIdentifier(target)) {
|
|
1246
1246
|
if (!isGlobalVariable(context, target)) return;
|
|
1247
1247
|
recordEffect(node, "mutatingGlobal", { name: target.name });
|
|
1248
1248
|
return;
|
|
@@ -1341,7 +1341,7 @@ const NAVIGATION_HOOKS = /* @__PURE__ */ new Set([
|
|
|
1341
1341
|
function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
1342
1342
|
const expr = Extract.unwrap(node);
|
|
1343
1343
|
if (Check.isFunction(expr)) return expr;
|
|
1344
|
-
if (expr
|
|
1344
|
+
if (!Check.isIdentifier(expr) || seen.has(expr)) return null;
|
|
1345
1345
|
seen.add(expr);
|
|
1346
1346
|
const resolved = resolve(context, expr);
|
|
1347
1347
|
return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
|
|
@@ -1352,7 +1352,7 @@ function resolveVariableOrigin(context, variable, seen = /* @__PURE__ */ new Set
|
|
|
1352
1352
|
const def = variable.defs.length === 1 ? variable.defs[0] : null;
|
|
1353
1353
|
if (def?.type !== DefinitionType.Variable || def.node.init == null) return variable;
|
|
1354
1354
|
const init = Extract.unwrap(def.node.init);
|
|
1355
|
-
if (init
|
|
1355
|
+
if (!Check.isIdentifier(init)) return variable;
|
|
1356
1356
|
const source = findVariable(context.sourceCode.getScope(init), init);
|
|
1357
1357
|
return source == null ? variable : resolveVariableOrigin(context, source, seen);
|
|
1358
1358
|
}
|
|
@@ -1360,12 +1360,12 @@ function isRefLikeName$1(name) {
|
|
|
1360
1360
|
return name === "ref" || name.endsWith("Ref");
|
|
1361
1361
|
}
|
|
1362
1362
|
function hasRefLikeNameInChain(node) {
|
|
1363
|
-
if (node
|
|
1363
|
+
if (Check.isIdentifier(node)) return isRefLikeName$1(node.name);
|
|
1364
1364
|
if (node.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1365
|
-
return node.property
|
|
1365
|
+
return Check.isIdentifier(node.property) ? isRefLikeName$1(node.property.name) || hasRefLikeNameInChain(node.object) : hasRefLikeNameInChain(node.object);
|
|
1366
1366
|
}
|
|
1367
1367
|
function isInitializedFromCall(context, node, isCall) {
|
|
1368
|
-
const root = node
|
|
1368
|
+
const root = Check.isIdentifier(node) ? node : Extract.getIdentifierAt(node, 0);
|
|
1369
1369
|
if (root == null) return false;
|
|
1370
1370
|
const variable = findVariable(context.sourceCode.getScope(root), root);
|
|
1371
1371
|
if (variable == null) return false;
|
|
@@ -1480,7 +1480,7 @@ function isGlobalOrModuleVariable(variable) {
|
|
|
1480
1480
|
return variable.defs.length === 0 || variable.scope.type === ScopeType.global || variable.scope.type === ScopeType.module;
|
|
1481
1481
|
}
|
|
1482
1482
|
function isRefMutation(context, mutation) {
|
|
1483
|
-
if (mutation.target
|
|
1483
|
+
if (Check.isIdentifier(mutation.target)) return isRefLikeName$1(mutation.target.name);
|
|
1484
1484
|
return isRefLikeChain(context, mutation.target);
|
|
1485
1485
|
}
|
|
1486
1486
|
function inferMutableFunctions(context, mutations) {
|
|
@@ -1604,7 +1604,7 @@ function create$47(context) {
|
|
|
1604
1604
|
if (currMethod == null || isStatic) return;
|
|
1605
1605
|
const [setState, hasThisState = false] = setStateStack.at(-1) ?? [];
|
|
1606
1606
|
if (setState == null || hasThisState) return;
|
|
1607
|
-
if (
|
|
1607
|
+
if (!Check.isIdentifier(node.property, "state")) return;
|
|
1608
1608
|
context.report({
|
|
1609
1609
|
messageId: "default",
|
|
1610
1610
|
node
|
|
@@ -1630,7 +1630,7 @@ function create$47(context) {
|
|
|
1630
1630
|
const [setState, hasThisState = false] = setStateStack.at(-1) ?? [];
|
|
1631
1631
|
if (setState == null || hasThisState) return;
|
|
1632
1632
|
if (node.init == null || node.init.type !== AST_NODE_TYPES.ThisExpression || node.id.type !== AST_NODE_TYPES.ObjectPattern) return;
|
|
1633
|
-
if (!node.id.properties.some((prop) => prop.type === AST_NODE_TYPES.Property && !prop.computed &&
|
|
1633
|
+
if (!node.id.properties.some((prop) => prop.type === AST_NODE_TYPES.Property && !prop.computed && Check.isIdentifier(prop.key, "state"))) return;
|
|
1634
1634
|
context.report({
|
|
1635
1635
|
messageId: "default",
|
|
1636
1636
|
node
|
|
@@ -1679,7 +1679,7 @@ function isArrayIndexReference(context, node) {
|
|
|
1679
1679
|
if (call.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
1680
1680
|
const callee = Extract.unwrap(call.callee);
|
|
1681
1681
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
1682
|
-
if (callee.property
|
|
1682
|
+
if (!Check.isIdentifier(callee.property)) return false;
|
|
1683
1683
|
const indexPosition = INDEX_PARAM_POSITIONS$1.get(callee.property.name);
|
|
1684
1684
|
if (indexPosition == null) return false;
|
|
1685
1685
|
const callbackPosition = core.isChildrenMap(context, callee) || core.isChildrenForEach(context, callee) ? 1 : 0;
|
|
@@ -1695,7 +1695,7 @@ function isArrayIndexReference(context, node) {
|
|
|
1695
1695
|
* @returns The identifiers found in the expression.
|
|
1696
1696
|
*/
|
|
1697
1697
|
function getIdentifiersFromBinaryExpression(side) {
|
|
1698
|
-
if (side
|
|
1698
|
+
if (Check.isIdentifier(side)) return [side];
|
|
1699
1699
|
if (side.type === AST_NODE_TYPES.BinaryExpression) return [...getIdentifiersFromBinaryExpression(side.left), ...getIdentifiersFromBinaryExpression(side.right)];
|
|
1700
1700
|
return [];
|
|
1701
1701
|
}
|
|
@@ -1716,18 +1716,9 @@ var no_array_index_key_default = createRule({
|
|
|
1716
1716
|
create: create$46,
|
|
1717
1717
|
defaultOptions: []
|
|
1718
1718
|
});
|
|
1719
|
-
/**
|
|
1720
|
-
* Gets the value of an object property named 'key' (e.g. in `createElement('div', { key: ... })`).
|
|
1721
|
-
* @param property The object literal member to inspect.
|
|
1722
|
-
* @returns The value of the 'key' property, or `null` if the member is not one.
|
|
1723
|
-
*/
|
|
1724
|
-
function getKeyPropValue(property) {
|
|
1725
|
-
if (property.type !== AST_NODE_TYPES.Property || property.computed) return null;
|
|
1726
|
-
return property.key.type === AST_NODE_TYPES.Identifier && property.key.name === "key" || property.key.type === AST_NODE_TYPES.Literal && property.key.value === "key" ? property.value : null;
|
|
1727
|
-
}
|
|
1728
1719
|
function create$46(context) {
|
|
1729
1720
|
function isArrayIndex(node) {
|
|
1730
|
-
return node
|
|
1721
|
+
return Check.isIdentifier(node) && isArrayIndexReference(context, node);
|
|
1731
1722
|
}
|
|
1732
1723
|
function getPropsObject(node) {
|
|
1733
1724
|
const props = node.arguments[1];
|
|
@@ -1778,8 +1769,10 @@ function create$46(context) {
|
|
|
1778
1769
|
const propsObject = getPropsObject(node);
|
|
1779
1770
|
if (propsObject == null) return;
|
|
1780
1771
|
for (const property of propsObject.properties) {
|
|
1781
|
-
|
|
1782
|
-
if (
|
|
1772
|
+
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
1773
|
+
if (property.computed) continue;
|
|
1774
|
+
if (Extract.getPropertyName(property, "max") !== "key") continue;
|
|
1775
|
+
const value = property.value;
|
|
1783
1776
|
for (const desc of visitKeyExpression(value)) context.report(desc);
|
|
1784
1777
|
}
|
|
1785
1778
|
},
|
|
@@ -2148,7 +2141,7 @@ function create$34(context) {
|
|
|
2148
2141
|
//#region src/rules/no-direct-mutation-state/no-direct-mutation-state.ts
|
|
2149
2142
|
const RULE_NAME$33 = "no-direct-mutation-state";
|
|
2150
2143
|
function isConstructorFunction(node) {
|
|
2151
|
-
return Check.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && Check.isPropertyOrMethod(node.parent) && node.parent.key
|
|
2144
|
+
return Check.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && Check.isPropertyOrMethod(node.parent) && Check.isIdentifier(node.parent.key) && node.parent.key.name === "constructor";
|
|
2152
2145
|
}
|
|
2153
2146
|
var no_direct_mutation_state_default = createRule({
|
|
2154
2147
|
meta: {
|
|
@@ -2216,7 +2209,7 @@ function create$32(context) {
|
|
|
2216
2209
|
const call = Traverse.findParent(jsxElement, (n) => {
|
|
2217
2210
|
if (n.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
2218
2211
|
const callee = Extract.unwrap(n.callee);
|
|
2219
|
-
return callee.type === AST_NODE_TYPES.MemberExpression && callee.property
|
|
2212
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.property) && callee.property.name === "map";
|
|
2220
2213
|
});
|
|
2221
2214
|
const iter = Traverse.findParent(jsxElement, Check.isFunction, (n) => n === call);
|
|
2222
2215
|
if (!Check.isFunction(iter)) return;
|
|
@@ -2295,7 +2288,7 @@ function couldFix(context, node) {
|
|
|
2295
2288
|
const callee = Extract.unwrap(node.callee);
|
|
2296
2289
|
switch (callee.type) {
|
|
2297
2290
|
case AST_NODE_TYPES.Identifier: return isInitializedFromReact(callee.name, initialScope, importSource);
|
|
2298
|
-
case AST_NODE_TYPES.MemberExpression: return callee.object
|
|
2291
|
+
case AST_NODE_TYPES.MemberExpression: return Check.isIdentifier(callee.object) && isInitializedFromReact(callee.object.name, initialScope, importSource);
|
|
2299
2292
|
default: return false;
|
|
2300
2293
|
}
|
|
2301
2294
|
}
|
|
@@ -3261,7 +3254,7 @@ var no_missing_key_default = createRule({
|
|
|
3261
3254
|
function getIteratorCallback(node) {
|
|
3262
3255
|
const callee = Extract.unwrap(node.callee);
|
|
3263
3256
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
3264
|
-
if (callee.property
|
|
3257
|
+
if (!Check.isIdentifier(callee.property)) return null;
|
|
3265
3258
|
const position = INDEX_PARAM_POSITIONS.get(callee.property.name);
|
|
3266
3259
|
if (position == null) return null;
|
|
3267
3260
|
const callback = node.arguments[position];
|
|
@@ -3484,7 +3477,7 @@ function getWrapperCallBoundName(context, node) {
|
|
|
3484
3477
|
parent = parent.parent;
|
|
3485
3478
|
}
|
|
3486
3479
|
}
|
|
3487
|
-
if (parent.type !== AST_NODE_TYPES.VariableDeclarator || parent.id
|
|
3480
|
+
if (parent.type !== AST_NODE_TYPES.VariableDeclarator || !Check.isIdentifier(parent.id)) return null;
|
|
3488
3481
|
return parent.id.name;
|
|
3489
3482
|
}
|
|
3490
3483
|
/**
|
|
@@ -3729,7 +3722,7 @@ function containsUseComments(context, node) {
|
|
|
3729
3722
|
return context.sourceCode.getCommentsInside(node).some(({ value }) => /use\([\s\S]*?\)/u.test(value) || /use[A-Z0-9]\w*\([\s\S]*?\)/u.test(value));
|
|
3730
3723
|
}
|
|
3731
3724
|
function isTestMock(node) {
|
|
3732
|
-
return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object
|
|
3725
|
+
return node != null && node.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(node.object) && Check.isIdentifier(node.property) && node.property.name === "mock";
|
|
3733
3726
|
}
|
|
3734
3727
|
function isTestMockCallback(node) {
|
|
3735
3728
|
return node != null && Check.isFunction(node) && node.parent.type === AST_NODE_TYPES.CallExpression && isTestMock(node.parent.callee) && node.parent.arguments[1] === node;
|
|
@@ -3969,14 +3962,14 @@ var no_unstable_default_props_default = createRule({
|
|
|
3969
3962
|
function extractIdentifier(node) {
|
|
3970
3963
|
if (node.type === AST_NODE_TYPES.NewExpression) {
|
|
3971
3964
|
const callee = Extract.unwrap(node.callee);
|
|
3972
|
-
if (callee
|
|
3965
|
+
if (Check.isIdentifier(callee)) return callee.name;
|
|
3973
3966
|
}
|
|
3974
3967
|
if (node.type === AST_NODE_TYPES.CallExpression) {
|
|
3975
3968
|
const callee = Extract.unwrap(node.callee);
|
|
3976
|
-
if (callee
|
|
3969
|
+
if (Check.isIdentifier(callee)) return callee.name;
|
|
3977
3970
|
if (callee.type === AST_NODE_TYPES.MemberExpression) {
|
|
3978
3971
|
const { object } = callee;
|
|
3979
|
-
if (object
|
|
3972
|
+
if (Check.isIdentifier(object)) return object.name;
|
|
3980
3973
|
}
|
|
3981
3974
|
}
|
|
3982
3975
|
return null;
|
|
@@ -4644,7 +4637,7 @@ function resolveBuiltinObjectName(context, node, seen = /* @__PURE__ */ new Set(
|
|
|
4644
4637
|
if (def.type === DefinitionType.ImplicitGlobalVariable) return node.name;
|
|
4645
4638
|
if (def.type === DefinitionType.Variable && def.node.init != null) {
|
|
4646
4639
|
const init = Extract.unwrap(def.node.init);
|
|
4647
|
-
if (init
|
|
4640
|
+
if (Check.isIdentifier(init)) return resolveBuiltinObjectName(context, init, seen);
|
|
4648
4641
|
if (init.type === AST_NODE_TYPES.MemberExpression) {
|
|
4649
4642
|
const rootId = Extract.getIdentifierAt(init, 0);
|
|
4650
4643
|
if (rootId != null) return resolveBuiltinObjectName(context, rootId, seen);
|
|
@@ -4676,7 +4669,7 @@ function create$7(context) {
|
|
|
4676
4669
|
CallExpression(node) {
|
|
4677
4670
|
const expr = Extract.unwrap(node.callee);
|
|
4678
4671
|
switch (true) {
|
|
4679
|
-
case expr
|
|
4672
|
+
case Check.isIdentifier(expr): {
|
|
4680
4673
|
const builtinName = resolveBuiltinObjectName(context, expr);
|
|
4681
4674
|
if (builtinName == null) return;
|
|
4682
4675
|
const globalThisImpure = IMPURE_FUNCS.get("globalThis");
|
|
@@ -4689,7 +4682,7 @@ function create$7(context) {
|
|
|
4689
4682
|
});
|
|
4690
4683
|
break;
|
|
4691
4684
|
}
|
|
4692
|
-
case expr.type === AST_NODE_TYPES.MemberExpression && expr.property
|
|
4685
|
+
case expr.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(expr.property): {
|
|
4693
4686
|
const rootId = Extract.getIdentifierAt(expr.object, 0);
|
|
4694
4687
|
if (rootId == null) return;
|
|
4695
4688
|
const objectName = resolveBuiltinObjectName(context, rootId);
|
|
@@ -4709,7 +4702,7 @@ function create$7(context) {
|
|
|
4709
4702
|
},
|
|
4710
4703
|
NewExpression(node) {
|
|
4711
4704
|
const expr = Extract.unwrap(node.callee);
|
|
4712
|
-
if (expr
|
|
4705
|
+
if (!Check.isIdentifier(expr)) return;
|
|
4713
4706
|
const builtinName = resolveBuiltinObjectName(context, expr);
|
|
4714
4707
|
if (builtinName == null) return;
|
|
4715
4708
|
if (!IMPURE_CTORS.has(builtinName)) return;
|
|
@@ -4764,7 +4757,7 @@ function createBindingResolver(context) {
|
|
|
4764
4757
|
}
|
|
4765
4758
|
function getBindingValue(node) {
|
|
4766
4759
|
const value = Extract.unwrap(node);
|
|
4767
|
-
if (value
|
|
4760
|
+
if (Check.isIdentifier(value)) {
|
|
4768
4761
|
const variable = getVariable(value);
|
|
4769
4762
|
return variable == null ? { kind: "unknown" } : {
|
|
4770
4763
|
kind: "variable",
|
|
@@ -4776,7 +4769,7 @@ function createBindingResolver(context) {
|
|
|
4776
4769
|
node: value
|
|
4777
4770
|
};
|
|
4778
4771
|
if (value.type === AST_NODE_TYPES.CallExpression && (core.isUseRefLikeCall(value, additionalRefHooks) || core.isCreateRefCall(context, value))) return { kind: "ref" };
|
|
4779
|
-
if (value.type === AST_NODE_TYPES.MemberExpression && value.property
|
|
4772
|
+
if (value.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(value.property)) {
|
|
4780
4773
|
if (isRefLikeName(value.property.name)) return { kind: "ref" };
|
|
4781
4774
|
}
|
|
4782
4775
|
return { kind: "unknown" };
|
|
@@ -4844,14 +4837,14 @@ function createBindingResolver(context) {
|
|
|
4844
4837
|
function resolveCallable(node, position) {
|
|
4845
4838
|
const callee = Extract.unwrap(node);
|
|
4846
4839
|
if (isFunctionExpressionLike(callee)) return callee;
|
|
4847
|
-
if (callee
|
|
4840
|
+
if (Check.isIdentifier(callee)) {
|
|
4848
4841
|
const variable = getVariable(callee);
|
|
4849
4842
|
return variable == null ? null : resolveFunction(variable, position);
|
|
4850
4843
|
}
|
|
4851
|
-
if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.property
|
|
4844
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression || !Check.isIdentifier(callee.property)) return null;
|
|
4852
4845
|
const object = Extract.unwrap(callee.object);
|
|
4853
4846
|
const property = callee.property.name;
|
|
4854
|
-
if (object
|
|
4847
|
+
if (!Check.isIdentifier(object)) return null;
|
|
4855
4848
|
const variable = getVariable(object);
|
|
4856
4849
|
if (variable == null) return null;
|
|
4857
4850
|
const event = getLatestValue(memberBindings.get(variable)?.get(property), position);
|
|
@@ -4862,13 +4855,13 @@ function createBindingResolver(context) {
|
|
|
4862
4855
|
}
|
|
4863
4856
|
function getRefTarget(node) {
|
|
4864
4857
|
const object = Extract.unwrap(node.object);
|
|
4865
|
-
if (object
|
|
4858
|
+
if (Check.isIdentifier(object)) {
|
|
4866
4859
|
const variable = getVariable(object);
|
|
4867
4860
|
if (variable == null) return null;
|
|
4868
4861
|
const identity = resolveRef(variable, node.range[0]);
|
|
4869
4862
|
return identity == null ? null : { identity };
|
|
4870
4863
|
}
|
|
4871
|
-
if (object.type === AST_NODE_TYPES.MemberExpression && object.property
|
|
4864
|
+
if (object.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(object.property)) {
|
|
4872
4865
|
if (isRefLikeName(object.property.name)) return { identity: null };
|
|
4873
4866
|
}
|
|
4874
4867
|
return null;
|
|
@@ -4876,12 +4869,12 @@ function createBindingResolver(context) {
|
|
|
4876
4869
|
function getNullBranch(test, identity) {
|
|
4877
4870
|
return getNullCheckBranch(test, (candidate) => {
|
|
4878
4871
|
if (candidate.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
4879
|
-
if (
|
|
4872
|
+
if (!Check.isIdentifier(candidate.property, "current")) return false;
|
|
4880
4873
|
return getRefTarget(candidate)?.identity === identity;
|
|
4881
4874
|
}, (candidate) => {
|
|
4882
4875
|
if (candidate.type === AST_NODE_TYPES.Literal) return candidate.value == null;
|
|
4883
4876
|
if (candidate.type === AST_NODE_TYPES.UnaryExpression && candidate.operator === "void") return true;
|
|
4884
|
-
if (
|
|
4877
|
+
if (!Check.isIdentifier(candidate, "undefined")) return false;
|
|
4885
4878
|
const variable = getVariable(candidate);
|
|
4886
4879
|
return variable == null || variable.defs.length === 0;
|
|
4887
4880
|
});
|
|
@@ -5067,13 +5060,13 @@ function create$6(context) {
|
|
|
5067
5060
|
AssignmentExpression(node) {
|
|
5068
5061
|
if (node.operator !== "=") return;
|
|
5069
5062
|
const left = Extract.unwrap(node.left);
|
|
5070
|
-
if (left
|
|
5063
|
+
if (Check.isIdentifier(left)) {
|
|
5071
5064
|
addIdentifierBinding(left, node.right, node.range[0]);
|
|
5072
5065
|
return;
|
|
5073
5066
|
}
|
|
5074
|
-
if (left.type !== AST_NODE_TYPES.MemberExpression || left.property
|
|
5067
|
+
if (left.type !== AST_NODE_TYPES.MemberExpression || !Check.isIdentifier(left.property)) return;
|
|
5075
5068
|
const object = Extract.unwrap(left.object);
|
|
5076
|
-
if (object
|
|
5069
|
+
if (Check.isIdentifier(object)) addMemberBinding(object, left.property.name, node.right, node.range[0]);
|
|
5077
5070
|
},
|
|
5078
5071
|
CallExpression(node) {
|
|
5079
5072
|
calls.push(node);
|
|
@@ -5084,11 +5077,11 @@ function create$6(context) {
|
|
|
5084
5077
|
JSXAttribute(node) {
|
|
5085
5078
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier || node.name.name !== "ref" || node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
5086
5079
|
const expression = Extract.unwrap(node.value.expression);
|
|
5087
|
-
if (expression
|
|
5080
|
+
if (!Check.isIdentifier(expression)) return;
|
|
5088
5081
|
addJsxRef(expression);
|
|
5089
5082
|
},
|
|
5090
5083
|
MemberExpression(node) {
|
|
5091
|
-
if (
|
|
5084
|
+
if (!Check.isIdentifier(node.property, "current")) return;
|
|
5092
5085
|
refAccesses.push(getRefAccess(node));
|
|
5093
5086
|
},
|
|
5094
5087
|
"Program:exit"(program) {
|
|
@@ -5167,7 +5160,7 @@ function create$6(context) {
|
|
|
5167
5160
|
for (const argument of callArguments) {
|
|
5168
5161
|
if (argument.type === AST_NODE_TYPES.SpreadElement) continue;
|
|
5169
5162
|
const value = Extract.unwrap(argument);
|
|
5170
|
-
if (value
|
|
5163
|
+
if (!Check.isIdentifier(value)) continue;
|
|
5171
5164
|
const variable = getVariable(value);
|
|
5172
5165
|
if (variable == null || resolveRef(variable, value.range[0]) == null) continue;
|
|
5173
5166
|
context.report({
|
|
@@ -5178,7 +5171,7 @@ function create$6(context) {
|
|
|
5178
5171
|
}
|
|
5179
5172
|
},
|
|
5180
5173
|
VariableDeclarator(node) {
|
|
5181
|
-
if (node.id
|
|
5174
|
+
if (!Check.isIdentifier(node.id) || node.init == null) return;
|
|
5182
5175
|
addIdentifierBinding(node.id, node.init, node.range[0]);
|
|
5183
5176
|
}
|
|
5184
5177
|
});
|
|
@@ -7327,7 +7320,7 @@ function last(array) {
|
|
|
7327
7320
|
*/
|
|
7328
7321
|
function getNestedIdentifiers(node) {
|
|
7329
7322
|
const identifiers = [];
|
|
7330
|
-
if (node
|
|
7323
|
+
if (Check.isIdentifier(node)) identifiers.push(node);
|
|
7331
7324
|
if ("arguments" in node) {
|
|
7332
7325
|
const chunk = node.arguments.flatMap(getNestedIdentifiers);
|
|
7333
7326
|
identifiers.push(...chunk);
|
|
@@ -7404,7 +7397,7 @@ function getNestedIdentifiers(node) {
|
|
|
7404
7397
|
}
|
|
7405
7398
|
function isHookDecl(node) {
|
|
7406
7399
|
if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
|
|
7407
|
-
if (node.id
|
|
7400
|
+
if (!Check.isIdentifier(node.id)) return false;
|
|
7408
7401
|
const init = node.init;
|
|
7409
7402
|
if (init == null || init.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
7410
7403
|
const name = Extract.getCalleeName(init);
|
|
@@ -7419,7 +7412,7 @@ function isInitializedFromRef(context, name, initialScope, seen = /* @__PURE__ *
|
|
|
7419
7412
|
const init = node.init;
|
|
7420
7413
|
if (init == null) continue;
|
|
7421
7414
|
switch (true) {
|
|
7422
|
-
case init.type === AST_NODE_TYPES.MemberExpression && init.object
|
|
7415
|
+
case init.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(init.object) && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return true;
|
|
7423
7416
|
case init.type === AST_NODE_TYPES.CallExpression && core.isUseRefLikeCall(init, additionalRefHooks): return true;
|
|
7424
7417
|
case init.type === AST_NODE_TYPES.CallExpression: return getNestedIdentifiers(init).some((id) => isInitializedFromRef(context, id.name, context.sourceCode.getScope(id), seen));
|
|
7425
7418
|
}
|
|
@@ -7458,7 +7451,7 @@ function isRefInExpression(context, node) {
|
|
|
7458
7451
|
* @returns The actual CallExpression node
|
|
7459
7452
|
*/
|
|
7460
7453
|
function getSetStateCallExpression(node) {
|
|
7461
|
-
return node
|
|
7454
|
+
return Check.isIdentifier(node) && node.parent.type === AST_NODE_TYPES.CallExpression ? node.parent : node;
|
|
7462
7455
|
}
|
|
7463
7456
|
|
|
7464
7457
|
//#endregion
|
|
@@ -7529,7 +7522,7 @@ function create$5(context) {
|
|
|
7529
7522
|
if (!isUseStateCall(initNode)) return false;
|
|
7530
7523
|
const variableNodeParent = initNode.parent;
|
|
7531
7524
|
if (!("id" in variableNodeParent) || variableNodeParent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
|
|
7532
|
-
return variableNodeParent.id.elements.findIndex((e) => e
|
|
7525
|
+
return variableNodeParent.id.elements.findIndex((e) => e != null && Check.isIdentifier(e, id.name)) === at;
|
|
7533
7526
|
}
|
|
7534
7527
|
function isSetStateCall(node) {
|
|
7535
7528
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -7646,6 +7639,8 @@ function create$5(context) {
|
|
|
7646
7639
|
},
|
|
7647
7640
|
"Program:exit"() {
|
|
7648
7641
|
const getSetStateCalls = (context, id) => {
|
|
7642
|
+
const variable = findVariable(context.sourceCode.getScope(id), id);
|
|
7643
|
+
if (variable != null && variable.defs.some((def) => def.type === DefinitionType.Parameter)) return [];
|
|
7649
7644
|
const node = resolve(context, id);
|
|
7650
7645
|
switch (node?.type) {
|
|
7651
7646
|
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
@@ -7665,7 +7660,7 @@ function create$5(context) {
|
|
|
7665
7660
|
}
|
|
7666
7661
|
for (const { callee } of trackedFnCalls) {
|
|
7667
7662
|
const unwrappedCallee = Extract.unwrap(callee);
|
|
7668
|
-
if (unwrappedCallee
|
|
7663
|
+
if (!Check.isIdentifier(unwrappedCallee)) continue;
|
|
7669
7664
|
const setStateCalls = getSetStateCalls(context, unwrappedCallee);
|
|
7670
7665
|
for (const setStateCall of setStateCalls) {
|
|
7671
7666
|
if (isRefGatedContext(context, getSetStateCallExpression(setStateCall))) continue;
|
|
@@ -7718,8 +7713,8 @@ function isInsideEventHandler(node, stopAt) {
|
|
|
7718
7713
|
function isComponentOrHookLikeFunction(node) {
|
|
7719
7714
|
const id = core.getFunctionId(node);
|
|
7720
7715
|
if (id == null) return false;
|
|
7721
|
-
if (id
|
|
7722
|
-
if (id.type === AST_NODE_TYPES.MemberExpression && id.property
|
|
7716
|
+
if (Check.isIdentifier(id)) return core.isFunctionComponentName(id.name) || core.isHookName(id.name);
|
|
7717
|
+
if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return core.isFunctionComponentName(id.property.name) || core.isHookName(id.property.name);
|
|
7723
7718
|
return false;
|
|
7724
7719
|
}
|
|
7725
7720
|
|
|
@@ -7752,7 +7747,7 @@ function create$4(context) {
|
|
|
7752
7747
|
if (!isUseStateCall(initNode)) return false;
|
|
7753
7748
|
const initNodeParent = initNode.parent;
|
|
7754
7749
|
if (!("id" in initNodeParent) || initNodeParent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
|
|
7755
|
-
return initNodeParent.id.elements.findIndex((e) => e
|
|
7750
|
+
return initNodeParent.id.elements.findIndex((e) => e != null && Check.isIdentifier(e, topLevelId.name)) === at;
|
|
7756
7751
|
}
|
|
7757
7752
|
function isSetStateCall(node) {
|
|
7758
7753
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -7989,7 +7984,7 @@ function isEvalCall(node) {
|
|
|
7989
7984
|
case AST_NODE_TYPES.Identifier: return callee.name === "eval";
|
|
7990
7985
|
case AST_NODE_TYPES.MemberExpression:
|
|
7991
7986
|
if (!Check.isIdentifier(Extract.unwrap(callee.object), "globalThis")) return false;
|
|
7992
|
-
return !callee.computed &&
|
|
7987
|
+
return !callee.computed && Check.isIdentifier(callee.property, "eval");
|
|
7993
7988
|
default: return false;
|
|
7994
7989
|
}
|
|
7995
7990
|
}
|
|
@@ -8110,7 +8105,7 @@ function create$1(context) {
|
|
|
8110
8105
|
simpleTraverse(callback.body, { enter(node) {
|
|
8111
8106
|
if (node.type !== AST_NODE_TYPES.AssignmentExpression) return;
|
|
8112
8107
|
const left = Extract.unwrap(node.left);
|
|
8113
|
-
if (left
|
|
8108
|
+
if (!Check.isIdentifier(left)) return;
|
|
8114
8109
|
if (Traverse.findParent(node, Check.isFunction, (n) => n === callback) != null) return;
|
|
8115
8110
|
const scope = context.sourceCode.getScope(left);
|
|
8116
8111
|
const variable = findVariable(scope, left);
|
|
@@ -8142,7 +8137,7 @@ function create$1(context) {
|
|
|
8142
8137
|
if (firstParam == null) return;
|
|
8143
8138
|
context.report({
|
|
8144
8139
|
messageId: "noParameters",
|
|
8145
|
-
node: firstParam
|
|
8140
|
+
node: Check.isIdentifier(firstParam) ? firstParam : callback
|
|
8146
8141
|
});
|
|
8147
8142
|
}
|
|
8148
8143
|
if (callback.async || callback.generator) context.report({
|
|
@@ -8582,6 +8577,17 @@ const settings = { ...settings$1 };
|
|
|
8582
8577
|
|
|
8583
8578
|
//#endregion
|
|
8584
8579
|
//#region src/index.ts
|
|
8580
|
+
function createConfig(base) {
|
|
8581
|
+
return {
|
|
8582
|
+
...base,
|
|
8583
|
+
plugins: {
|
|
8584
|
+
...base.plugins,
|
|
8585
|
+
get ["react-x"]() {
|
|
8586
|
+
return finalPlugin;
|
|
8587
|
+
}
|
|
8588
|
+
}
|
|
8589
|
+
};
|
|
8590
|
+
}
|
|
8585
8591
|
const finalPlugin = {
|
|
8586
8592
|
...plugin,
|
|
8587
8593
|
configs: {
|
|
@@ -8604,27 +8610,27 @@ const finalPlugin = {
|
|
|
8604
8610
|
/**
|
|
8605
8611
|
* Enforce rules that are recommended by ESLint React for general purpose React + React DOM projects
|
|
8606
8612
|
*/
|
|
8607
|
-
["recommended"]: recommended_exports,
|
|
8613
|
+
["recommended"]: createConfig(recommended_exports),
|
|
8608
8614
|
/**
|
|
8609
8615
|
* Same as the `recommended-typescript` preset but enables additional rules that require type information
|
|
8610
8616
|
*/
|
|
8611
|
-
["recommended-type-checked"]: recommended_type_checked_exports,
|
|
8617
|
+
["recommended-type-checked"]: createConfig(recommended_type_checked_exports),
|
|
8612
8618
|
/**
|
|
8613
8619
|
* Same as the `recommended` preset but disables rules that can be enforced by TypeScript
|
|
8614
8620
|
*/
|
|
8615
|
-
["recommended-typescript"]: recommended_typescript_exports,
|
|
8621
|
+
["recommended-typescript"]: createConfig(recommended_typescript_exports),
|
|
8616
8622
|
/**
|
|
8617
8623
|
* More strict version of the `recommended` preset
|
|
8618
8624
|
*/
|
|
8619
|
-
["strict"]: strict_exports,
|
|
8625
|
+
["strict"]: createConfig(strict_exports),
|
|
8620
8626
|
/**
|
|
8621
8627
|
* Same as the `strict-typescript` preset but enables additional rules that require type information
|
|
8622
8628
|
*/
|
|
8623
|
-
["strict-type-checked"]: strict_type_checked_exports,
|
|
8629
|
+
["strict-type-checked"]: createConfig(strict_type_checked_exports),
|
|
8624
8630
|
/**
|
|
8625
8631
|
* Same as the `strict` preset but disables rules that can be enforced by TypeScript
|
|
8626
8632
|
*/
|
|
8627
|
-
["strict-typescript"]: strict_typescript_exports
|
|
8633
|
+
["strict-typescript"]: createConfig(strict_typescript_exports)
|
|
8628
8634
|
}
|
|
8629
8635
|
};
|
|
8630
8636
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.18.
|
|
3
|
+
"version": "5.18.8",
|
|
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,35 +36,35 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
39
|
+
"@eslint-react/ast": "5.18.8",
|
|
40
|
+
"@eslint-react/core": "5.18.8",
|
|
41
|
+
"@eslint-react/eslint": "5.18.8",
|
|
42
|
+
"@eslint-react/jsx": "5.18.8",
|
|
43
|
+
"@eslint-react/shared": "5.18.8",
|
|
44
|
+
"@eslint-react/var": "5.18.8",
|
|
45
|
+
"@typescript-eslint/scope-manager": "^8.69.0",
|
|
46
|
+
"@typescript-eslint/type-utils": "^8.69.0",
|
|
47
|
+
"@typescript-eslint/types": "^8.69.0",
|
|
48
|
+
"@typescript-eslint/typescript-estree": "^8.69.0",
|
|
49
|
+
"@typescript-eslint/utils": "^8.69.0",
|
|
44
50
|
"compare-versions": "^6.1.1",
|
|
45
51
|
"string-ts": "^2.3.1",
|
|
46
52
|
"ts-api-utils": "^2.5.0",
|
|
47
|
-
"ts-pattern": "^5.9.0"
|
|
48
|
-
"@eslint-react/ast": "5.18.6",
|
|
49
|
-
"@eslint-react/jsx": "5.18.6",
|
|
50
|
-
"@eslint-react/shared": "5.18.6",
|
|
51
|
-
"@eslint-react/eslint": "5.18.6",
|
|
52
|
-
"@eslint-react/var": "5.18.6",
|
|
53
|
-
"@eslint-react/core": "5.18.6"
|
|
53
|
+
"ts-pattern": "^5.9.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
+
"@local/configs": "0.0.0",
|
|
57
|
+
"@local/eff": "0.0.0",
|
|
56
58
|
"@types/react": "^19.2.18",
|
|
57
|
-
"@types/react-dom": "^19.2.
|
|
59
|
+
"@types/react-dom": "^19.2.5",
|
|
58
60
|
"dedent": "^1.7.2",
|
|
59
|
-
"eslint": "^10.
|
|
61
|
+
"eslint": "^10.9.1",
|
|
60
62
|
"react": "^19.2.8",
|
|
61
63
|
"react-dom": "^19.2.8",
|
|
62
64
|
"tsdown": "^0.22.14",
|
|
63
65
|
"tsl": "^1.0.30",
|
|
64
66
|
"tsl-dx": "^0.13.3",
|
|
65
|
-
"typescript": "6.0.3"
|
|
66
|
-
"@local/configs": "0.0.0",
|
|
67
|
-
"@local/eff": "0.0.0"
|
|
67
|
+
"typescript": "6.0.3"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"eslint": "*",
|