eslint-plugin-react-x 5.18.5 → 5.18.7

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.
Files changed (2) hide show
  1. package/dist/index.js +72 -88
  2. 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.5";
148
+ var version = "5.18.7";
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.type !== AST_NODE_TYPES.Identifier) return null;
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.type !== AST_NODE_TYPES.Identifier || definition.node.init == null) return null;
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.type !== AST_NODE_TYPES.Identifier || seen.has(expression)) return null;
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.type === AST_NODE_TYPES.Identifier) {
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.type !== AST_NODE_TYPES.Identifier || seen.has(expr)) return null;
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.type !== AST_NODE_TYPES.Identifier) return variable;
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.type === AST_NODE_TYPES.Identifier) return isRefLikeName$1(node.name);
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.type === AST_NODE_TYPES.Identifier ? isRefLikeName$1(node.property.name) || hasRefLikeNameInChain(node.object) : hasRefLikeNameInChain(node.object);
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.type === AST_NODE_TYPES.Identifier ? node : Extract.getIdentifierAt(node, 0);
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.type === AST_NODE_TYPES.Identifier) return isRefLikeName$1(mutation.target.name);
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 (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== "state") return;
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 && prop.key.type === AST_NODE_TYPES.Identifier && prop.key.name === "state")) return;
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.type !== AST_NODE_TYPES.Identifier) return false;
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.type === AST_NODE_TYPES.Identifier) return [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,21 +1716,15 @@ 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.type === AST_NODE_TYPES.Identifier && isArrayIndexReference(context, node);
1721
+ return Check.isIdentifier(node) && isArrayIndexReference(context, node);
1731
1722
  }
1732
- function isCreateOrCloneElementCall(node) {
1733
- return core.isCreateElementCall(context, node) || core.isCloneElementCall(context, node);
1723
+ function getPropsObject(node) {
1724
+ const props = node.arguments[1];
1725
+ if (core.isCreateElementCall(context, node)) return core.getCreateElementPropsObject(context, node);
1726
+ if (!core.isCloneElementCall(context, node)) return null;
1727
+ return props?.type === AST_NODE_TYPES.ObjectExpression ? props : null;
1734
1728
  }
1735
1729
  /**
1736
1730
  * Checks an expression used as a 'key' value, recursing into the branches
@@ -1772,12 +1766,13 @@ function create$46(context) {
1772
1766
  }
1773
1767
  return {
1774
1768
  CallExpression(node) {
1775
- if (!isCreateOrCloneElementCall(node)) return;
1776
- const [, props] = node.arguments;
1777
- if (props?.type !== AST_NODE_TYPES.ObjectExpression) return;
1778
- for (const property of props.properties) {
1779
- const value = getKeyPropValue(property);
1780
- if (value == null) continue;
1769
+ const propsObject = getPropsObject(node);
1770
+ if (propsObject == null) return;
1771
+ for (const property of propsObject.properties) {
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;
1781
1776
  for (const desc of visitKeyExpression(value)) context.report(desc);
1782
1777
  }
1783
1778
  },
@@ -2146,7 +2141,7 @@ function create$34(context) {
2146
2141
  //#region src/rules/no-direct-mutation-state/no-direct-mutation-state.ts
2147
2142
  const RULE_NAME$33 = "no-direct-mutation-state";
2148
2143
  function isConstructorFunction(node) {
2149
- return Check.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && Check.isPropertyOrMethod(node.parent) && node.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.key.name === "constructor";
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";
2150
2145
  }
2151
2146
  var no_direct_mutation_state_default = createRule({
2152
2147
  meta: {
@@ -2214,7 +2209,7 @@ function create$32(context) {
2214
2209
  const call = Traverse.findParent(jsxElement, (n) => {
2215
2210
  if (n.type !== AST_NODE_TYPES.CallExpression) return false;
2216
2211
  const callee = Extract.unwrap(n.callee);
2217
- return callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "map";
2212
+ return callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.property) && callee.property.name === "map";
2218
2213
  });
2219
2214
  const iter = Traverse.findParent(jsxElement, Check.isFunction, (n) => n === call);
2220
2215
  if (!Check.isFunction(iter)) return;
@@ -2293,7 +2288,7 @@ function couldFix(context, node) {
2293
2288
  const callee = Extract.unwrap(node.callee);
2294
2289
  switch (callee.type) {
2295
2290
  case AST_NODE_TYPES.Identifier: return isInitializedFromReact(callee.name, initialScope, importSource);
2296
- case AST_NODE_TYPES.MemberExpression: return callee.object.type === AST_NODE_TYPES.Identifier && isInitializedFromReact(callee.object.name, initialScope, importSource);
2291
+ case AST_NODE_TYPES.MemberExpression: return Check.isIdentifier(callee.object) && isInitializedFromReact(callee.object.name, initialScope, importSource);
2297
2292
  default: return false;
2298
2293
  }
2299
2294
  }
@@ -3259,7 +3254,7 @@ var no_missing_key_default = createRule({
3259
3254
  function getIteratorCallback(node) {
3260
3255
  const callee = Extract.unwrap(node.callee);
3261
3256
  if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
3262
- if (callee.property.type !== AST_NODE_TYPES.Identifier) return null;
3257
+ if (!Check.isIdentifier(callee.property)) return null;
3263
3258
  const position = INDEX_PARAM_POSITIONS.get(callee.property.name);
3264
3259
  if (position == null) return null;
3265
3260
  const callback = node.arguments[position];
@@ -3482,23 +3477,10 @@ function getWrapperCallBoundName(context, node) {
3482
3477
  parent = parent.parent;
3483
3478
  }
3484
3479
  }
3485
- if (parent.type !== AST_NODE_TYPES.VariableDeclarator || parent.id.type !== AST_NODE_TYPES.Identifier) return null;
3480
+ if (parent.type !== AST_NODE_TYPES.VariableDeclarator || !Check.isIdentifier(parent.id)) return null;
3486
3481
  return parent.id.name;
3487
3482
  }
3488
3483
  /**
3489
- * Check if the node is inside `createElement`'s props argument
3490
- * @param context The rule context
3491
- * @param node The AST node to check
3492
- * @returns `true` if the node is inside `createElement`'s props
3493
- */
3494
- function isInsideCreateElementProps(context, node) {
3495
- const call = Traverse.findParent(node, core.isCreateElementCall(context));
3496
- if (call == null) return false;
3497
- const prop = Traverse.findParent(node, Check.is(AST_NODE_TYPES.ObjectExpression));
3498
- if (prop == null) return false;
3499
- return prop === call.arguments[1];
3500
- }
3501
- /**
3502
3484
  * Check if the node is inside a JSX attribute value
3503
3485
  * @param node The AST node to check
3504
3486
  * @returns `true` if the node is inside a JSX attribute value
@@ -3560,7 +3542,7 @@ function create$22(context) {
3560
3542
  });
3561
3543
  continue;
3562
3544
  }
3563
- if (isInsideCreateElementProps(context, component)) {
3545
+ if (core.isInsideCreateElementProps(context, component)) {
3564
3546
  context.report({
3565
3547
  data: {
3566
3548
  name,
@@ -3740,7 +3722,7 @@ function containsUseComments(context, node) {
3740
3722
  return context.sourceCode.getCommentsInside(node).some(({ value }) => /use\([\s\S]*?\)/u.test(value) || /use[A-Z0-9]\w*\([\s\S]*?\)/u.test(value));
3741
3723
  }
3742
3724
  function isTestMock(node) {
3743
- return node != null && node.type === AST_NODE_TYPES.MemberExpression && node.object.type === AST_NODE_TYPES.Identifier && node.property.type === AST_NODE_TYPES.Identifier && node.property.name === "mock";
3725
+ return node != null && node.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(node.object) && Check.isIdentifier(node.property) && node.property.name === "mock";
3744
3726
  }
3745
3727
  function isTestMockCallback(node) {
3746
3728
  return node != null && Check.isFunction(node) && node.parent.type === AST_NODE_TYPES.CallExpression && isTestMock(node.parent.callee) && node.parent.arguments[1] === node;
@@ -3980,14 +3962,14 @@ var no_unstable_default_props_default = createRule({
3980
3962
  function extractIdentifier(node) {
3981
3963
  if (node.type === AST_NODE_TYPES.NewExpression) {
3982
3964
  const callee = Extract.unwrap(node.callee);
3983
- if (callee.type === AST_NODE_TYPES.Identifier) return callee.name;
3965
+ if (Check.isIdentifier(callee)) return callee.name;
3984
3966
  }
3985
3967
  if (node.type === AST_NODE_TYPES.CallExpression) {
3986
3968
  const callee = Extract.unwrap(node.callee);
3987
- if (callee.type === AST_NODE_TYPES.Identifier) return callee.name;
3969
+ if (Check.isIdentifier(callee)) return callee.name;
3988
3970
  if (callee.type === AST_NODE_TYPES.MemberExpression) {
3989
3971
  const { object } = callee;
3990
- if (object.type === AST_NODE_TYPES.Identifier) return object.name;
3972
+ if (Check.isIdentifier(object)) return object.name;
3991
3973
  }
3992
3974
  }
3993
3975
  return null;
@@ -4655,7 +4637,7 @@ function resolveBuiltinObjectName(context, node, seen = /* @__PURE__ */ new Set(
4655
4637
  if (def.type === DefinitionType.ImplicitGlobalVariable) return node.name;
4656
4638
  if (def.type === DefinitionType.Variable && def.node.init != null) {
4657
4639
  const init = Extract.unwrap(def.node.init);
4658
- if (init.type === AST_NODE_TYPES.Identifier) return resolveBuiltinObjectName(context, init, seen);
4640
+ if (Check.isIdentifier(init)) return resolveBuiltinObjectName(context, init, seen);
4659
4641
  if (init.type === AST_NODE_TYPES.MemberExpression) {
4660
4642
  const rootId = Extract.getIdentifierAt(init, 0);
4661
4643
  if (rootId != null) return resolveBuiltinObjectName(context, rootId, seen);
@@ -4687,7 +4669,7 @@ function create$7(context) {
4687
4669
  CallExpression(node) {
4688
4670
  const expr = Extract.unwrap(node.callee);
4689
4671
  switch (true) {
4690
- case expr.type === AST_NODE_TYPES.Identifier: {
4672
+ case Check.isIdentifier(expr): {
4691
4673
  const builtinName = resolveBuiltinObjectName(context, expr);
4692
4674
  if (builtinName == null) return;
4693
4675
  const globalThisImpure = IMPURE_FUNCS.get("globalThis");
@@ -4700,7 +4682,7 @@ function create$7(context) {
4700
4682
  });
4701
4683
  break;
4702
4684
  }
4703
- case expr.type === AST_NODE_TYPES.MemberExpression && expr.property.type === AST_NODE_TYPES.Identifier: {
4685
+ case expr.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(expr.property): {
4704
4686
  const rootId = Extract.getIdentifierAt(expr.object, 0);
4705
4687
  if (rootId == null) return;
4706
4688
  const objectName = resolveBuiltinObjectName(context, rootId);
@@ -4720,7 +4702,7 @@ function create$7(context) {
4720
4702
  },
4721
4703
  NewExpression(node) {
4722
4704
  const expr = Extract.unwrap(node.callee);
4723
- if (expr.type !== AST_NODE_TYPES.Identifier) return;
4705
+ if (!Check.isIdentifier(expr)) return;
4724
4706
  const builtinName = resolveBuiltinObjectName(context, expr);
4725
4707
  if (builtinName == null) return;
4726
4708
  if (!IMPURE_CTORS.has(builtinName)) return;
@@ -4775,7 +4757,7 @@ function createBindingResolver(context) {
4775
4757
  }
4776
4758
  function getBindingValue(node) {
4777
4759
  const value = Extract.unwrap(node);
4778
- if (value.type === AST_NODE_TYPES.Identifier) {
4760
+ if (Check.isIdentifier(value)) {
4779
4761
  const variable = getVariable(value);
4780
4762
  return variable == null ? { kind: "unknown" } : {
4781
4763
  kind: "variable",
@@ -4787,7 +4769,7 @@ function createBindingResolver(context) {
4787
4769
  node: value
4788
4770
  };
4789
4771
  if (value.type === AST_NODE_TYPES.CallExpression && (core.isUseRefLikeCall(value, additionalRefHooks) || core.isCreateRefCall(context, value))) return { kind: "ref" };
4790
- if (value.type === AST_NODE_TYPES.MemberExpression && value.property.type === AST_NODE_TYPES.Identifier) {
4772
+ if (value.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(value.property)) {
4791
4773
  if (isRefLikeName(value.property.name)) return { kind: "ref" };
4792
4774
  }
4793
4775
  return { kind: "unknown" };
@@ -4855,14 +4837,14 @@ function createBindingResolver(context) {
4855
4837
  function resolveCallable(node, position) {
4856
4838
  const callee = Extract.unwrap(node);
4857
4839
  if (isFunctionExpressionLike(callee)) return callee;
4858
- if (callee.type === AST_NODE_TYPES.Identifier) {
4840
+ if (Check.isIdentifier(callee)) {
4859
4841
  const variable = getVariable(callee);
4860
4842
  return variable == null ? null : resolveFunction(variable, position);
4861
4843
  }
4862
- if (callee.type !== AST_NODE_TYPES.MemberExpression || callee.property.type !== AST_NODE_TYPES.Identifier) return null;
4844
+ if (callee.type !== AST_NODE_TYPES.MemberExpression || !Check.isIdentifier(callee.property)) return null;
4863
4845
  const object = Extract.unwrap(callee.object);
4864
4846
  const property = callee.property.name;
4865
- if (object.type !== AST_NODE_TYPES.Identifier) return null;
4847
+ if (!Check.isIdentifier(object)) return null;
4866
4848
  const variable = getVariable(object);
4867
4849
  if (variable == null) return null;
4868
4850
  const event = getLatestValue(memberBindings.get(variable)?.get(property), position);
@@ -4873,13 +4855,13 @@ function createBindingResolver(context) {
4873
4855
  }
4874
4856
  function getRefTarget(node) {
4875
4857
  const object = Extract.unwrap(node.object);
4876
- if (object.type === AST_NODE_TYPES.Identifier) {
4858
+ if (Check.isIdentifier(object)) {
4877
4859
  const variable = getVariable(object);
4878
4860
  if (variable == null) return null;
4879
4861
  const identity = resolveRef(variable, node.range[0]);
4880
4862
  return identity == null ? null : { identity };
4881
4863
  }
4882
- if (object.type === AST_NODE_TYPES.MemberExpression && object.property.type === AST_NODE_TYPES.Identifier) {
4864
+ if (object.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(object.property)) {
4883
4865
  if (isRefLikeName(object.property.name)) return { identity: null };
4884
4866
  }
4885
4867
  return null;
@@ -4887,12 +4869,12 @@ function createBindingResolver(context) {
4887
4869
  function getNullBranch(test, identity) {
4888
4870
  return getNullCheckBranch(test, (candidate) => {
4889
4871
  if (candidate.type !== AST_NODE_TYPES.MemberExpression) return false;
4890
- if (candidate.property.type !== AST_NODE_TYPES.Identifier || candidate.property.name !== "current") return false;
4872
+ if (!Check.isIdentifier(candidate.property, "current")) return false;
4891
4873
  return getRefTarget(candidate)?.identity === identity;
4892
4874
  }, (candidate) => {
4893
4875
  if (candidate.type === AST_NODE_TYPES.Literal) return candidate.value == null;
4894
4876
  if (candidate.type === AST_NODE_TYPES.UnaryExpression && candidate.operator === "void") return true;
4895
- if (candidate.type !== AST_NODE_TYPES.Identifier || candidate.name !== "undefined") return false;
4877
+ if (!Check.isIdentifier(candidate, "undefined")) return false;
4896
4878
  const variable = getVariable(candidate);
4897
4879
  return variable == null || variable.defs.length === 0;
4898
4880
  });
@@ -5078,13 +5060,13 @@ function create$6(context) {
5078
5060
  AssignmentExpression(node) {
5079
5061
  if (node.operator !== "=") return;
5080
5062
  const left = Extract.unwrap(node.left);
5081
- if (left.type === AST_NODE_TYPES.Identifier) {
5063
+ if (Check.isIdentifier(left)) {
5082
5064
  addIdentifierBinding(left, node.right, node.range[0]);
5083
5065
  return;
5084
5066
  }
5085
- if (left.type !== AST_NODE_TYPES.MemberExpression || left.property.type !== AST_NODE_TYPES.Identifier) return;
5067
+ if (left.type !== AST_NODE_TYPES.MemberExpression || !Check.isIdentifier(left.property)) return;
5086
5068
  const object = Extract.unwrap(left.object);
5087
- if (object.type === AST_NODE_TYPES.Identifier) addMemberBinding(object, left.property.name, node.right, node.range[0]);
5069
+ if (Check.isIdentifier(object)) addMemberBinding(object, left.property.name, node.right, node.range[0]);
5088
5070
  },
5089
5071
  CallExpression(node) {
5090
5072
  calls.push(node);
@@ -5095,11 +5077,11 @@ function create$6(context) {
5095
5077
  JSXAttribute(node) {
5096
5078
  if (node.name.type !== AST_NODE_TYPES.JSXIdentifier || node.name.name !== "ref" || node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
5097
5079
  const expression = Extract.unwrap(node.value.expression);
5098
- if (expression.type !== AST_NODE_TYPES.Identifier) return;
5080
+ if (!Check.isIdentifier(expression)) return;
5099
5081
  addJsxRef(expression);
5100
5082
  },
5101
5083
  MemberExpression(node) {
5102
- if (node.property.type !== AST_NODE_TYPES.Identifier || node.property.name !== "current") return;
5084
+ if (!Check.isIdentifier(node.property, "current")) return;
5103
5085
  refAccesses.push(getRefAccess(node));
5104
5086
  },
5105
5087
  "Program:exit"(program) {
@@ -5178,7 +5160,7 @@ function create$6(context) {
5178
5160
  for (const argument of callArguments) {
5179
5161
  if (argument.type === AST_NODE_TYPES.SpreadElement) continue;
5180
5162
  const value = Extract.unwrap(argument);
5181
- if (value.type !== AST_NODE_TYPES.Identifier) continue;
5163
+ if (!Check.isIdentifier(value)) continue;
5182
5164
  const variable = getVariable(value);
5183
5165
  if (variable == null || resolveRef(variable, value.range[0]) == null) continue;
5184
5166
  context.report({
@@ -5189,7 +5171,7 @@ function create$6(context) {
5189
5171
  }
5190
5172
  },
5191
5173
  VariableDeclarator(node) {
5192
- if (node.id.type !== AST_NODE_TYPES.Identifier || node.init == null) return;
5174
+ if (!Check.isIdentifier(node.id) || node.init == null) return;
5193
5175
  addIdentifierBinding(node.id, node.init, node.range[0]);
5194
5176
  }
5195
5177
  });
@@ -7338,7 +7320,7 @@ function last(array) {
7338
7320
  */
7339
7321
  function getNestedIdentifiers(node) {
7340
7322
  const identifiers = [];
7341
- if (node.type === AST_NODE_TYPES.Identifier) identifiers.push(node);
7323
+ if (Check.isIdentifier(node)) identifiers.push(node);
7342
7324
  if ("arguments" in node) {
7343
7325
  const chunk = node.arguments.flatMap(getNestedIdentifiers);
7344
7326
  identifiers.push(...chunk);
@@ -7415,7 +7397,7 @@ function getNestedIdentifiers(node) {
7415
7397
  }
7416
7398
  function isHookDecl(node) {
7417
7399
  if (node.type !== AST_NODE_TYPES.VariableDeclarator) return false;
7418
- if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
7400
+ if (!Check.isIdentifier(node.id)) return false;
7419
7401
  const init = node.init;
7420
7402
  if (init == null || init.type !== AST_NODE_TYPES.CallExpression) return false;
7421
7403
  const name = Extract.getCalleeName(init);
@@ -7430,7 +7412,7 @@ function isInitializedFromRef(context, name, initialScope, seen = /* @__PURE__ *
7430
7412
  const init = node.init;
7431
7413
  if (init == null) continue;
7432
7414
  switch (true) {
7433
- case init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return true;
7415
+ case init.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(init.object) && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return true;
7434
7416
  case init.type === AST_NODE_TYPES.CallExpression && core.isUseRefLikeCall(init, additionalRefHooks): return true;
7435
7417
  case init.type === AST_NODE_TYPES.CallExpression: return getNestedIdentifiers(init).some((id) => isInitializedFromRef(context, id.name, context.sourceCode.getScope(id), seen));
7436
7418
  }
@@ -7469,7 +7451,7 @@ function isRefInExpression(context, node) {
7469
7451
  * @returns The actual CallExpression node
7470
7452
  */
7471
7453
  function getSetStateCallExpression(node) {
7472
- return node.type === AST_NODE_TYPES.Identifier && node.parent.type === AST_NODE_TYPES.CallExpression ? node.parent : node;
7454
+ return Check.isIdentifier(node) && node.parent.type === AST_NODE_TYPES.CallExpression ? node.parent : node;
7473
7455
  }
7474
7456
 
7475
7457
  //#endregion
@@ -7540,7 +7522,7 @@ function create$5(context) {
7540
7522
  if (!isUseStateCall(initNode)) return false;
7541
7523
  const variableNodeParent = initNode.parent;
7542
7524
  if (!("id" in variableNodeParent) || variableNodeParent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
7543
- return variableNodeParent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === id.name) === at;
7525
+ return variableNodeParent.id.elements.findIndex((e) => e != null && Check.isIdentifier(e, id.name)) === at;
7544
7526
  }
7545
7527
  function isSetStateCall(node) {
7546
7528
  const callee = Extract.unwrap(node.callee);
@@ -7657,6 +7639,8 @@ function create$5(context) {
7657
7639
  },
7658
7640
  "Program:exit"() {
7659
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 [];
7660
7644
  const node = resolve(context, id);
7661
7645
  switch (node?.type) {
7662
7646
  case AST_NODE_TYPES.ArrowFunctionExpression:
@@ -7676,7 +7660,7 @@ function create$5(context) {
7676
7660
  }
7677
7661
  for (const { callee } of trackedFnCalls) {
7678
7662
  const unwrappedCallee = Extract.unwrap(callee);
7679
- if (unwrappedCallee.type !== AST_NODE_TYPES.Identifier) continue;
7663
+ if (!Check.isIdentifier(unwrappedCallee)) continue;
7680
7664
  const setStateCalls = getSetStateCalls(context, unwrappedCallee);
7681
7665
  for (const setStateCall of setStateCalls) {
7682
7666
  if (isRefGatedContext(context, getSetStateCallExpression(setStateCall))) continue;
@@ -7729,8 +7713,8 @@ function isInsideEventHandler(node, stopAt) {
7729
7713
  function isComponentOrHookLikeFunction(node) {
7730
7714
  const id = core.getFunctionId(node);
7731
7715
  if (id == null) return false;
7732
- if (id.type === AST_NODE_TYPES.Identifier) return core.isFunctionComponentName(id.name) || core.isHookName(id.name);
7733
- if (id.type === AST_NODE_TYPES.MemberExpression && id.property.type === AST_NODE_TYPES.Identifier) return core.isFunctionComponentName(id.property.name) || core.isHookName(id.property.name);
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);
7734
7718
  return false;
7735
7719
  }
7736
7720
 
@@ -7763,7 +7747,7 @@ function create$4(context) {
7763
7747
  if (!isUseStateCall(initNode)) return false;
7764
7748
  const initNodeParent = initNode.parent;
7765
7749
  if (!("id" in initNodeParent) || initNodeParent.id?.type !== AST_NODE_TYPES.ArrayPattern) return true;
7766
- return initNodeParent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === topLevelId.name) === at;
7750
+ return initNodeParent.id.elements.findIndex((e) => e != null && Check.isIdentifier(e, topLevelId.name)) === at;
7767
7751
  }
7768
7752
  function isSetStateCall(node) {
7769
7753
  const callee = Extract.unwrap(node.callee);
@@ -8000,7 +7984,7 @@ function isEvalCall(node) {
8000
7984
  case AST_NODE_TYPES.Identifier: return callee.name === "eval";
8001
7985
  case AST_NODE_TYPES.MemberExpression:
8002
7986
  if (!Check.isIdentifier(Extract.unwrap(callee.object), "globalThis")) return false;
8003
- return !callee.computed && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "eval";
7987
+ return !callee.computed && Check.isIdentifier(callee.property, "eval");
8004
7988
  default: return false;
8005
7989
  }
8006
7990
  }
@@ -8121,7 +8105,7 @@ function create$1(context) {
8121
8105
  simpleTraverse(callback.body, { enter(node) {
8122
8106
  if (node.type !== AST_NODE_TYPES.AssignmentExpression) return;
8123
8107
  const left = Extract.unwrap(node.left);
8124
- if (left.type !== AST_NODE_TYPES.Identifier) return;
8108
+ if (!Check.isIdentifier(left)) return;
8125
8109
  if (Traverse.findParent(node, Check.isFunction, (n) => n === callback) != null) return;
8126
8110
  const scope = context.sourceCode.getScope(left);
8127
8111
  const variable = findVariable(scope, left);
@@ -8153,7 +8137,7 @@ function create$1(context) {
8153
8137
  if (firstParam == null) return;
8154
8138
  context.report({
8155
8139
  messageId: "noParameters",
8156
- node: firstParam.type === AST_NODE_TYPES.Identifier ? firstParam : callback
8140
+ node: Check.isIdentifier(firstParam) ? firstParam : callback
8157
8141
  });
8158
8142
  }
8159
8143
  if (callback.async || callback.generator) context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.18.5",
3
+ "version": "5.18.7",
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
- "@typescript-eslint/scope-manager": "^8.67.0",
40
- "@typescript-eslint/type-utils": "^8.67.0",
41
- "@typescript-eslint/types": "^8.67.0",
42
- "@typescript-eslint/typescript-estree": "^8.67.0",
43
- "@typescript-eslint/utils": "^8.67.0",
39
+ "@eslint-react/ast": "5.18.7",
40
+ "@eslint-react/core": "5.18.7",
41
+ "@eslint-react/eslint": "5.18.7",
42
+ "@eslint-react/jsx": "5.18.7",
43
+ "@eslint-react/shared": "5.18.7",
44
+ "@eslint-react/var": "5.18.7",
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.5",
49
- "@eslint-react/eslint": "5.18.5",
50
- "@eslint-react/shared": "5.18.5",
51
- "@eslint-react/jsx": "5.18.5",
52
- "@eslint-react/var": "5.18.5",
53
- "@eslint-react/core": "5.18.5"
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.4",
59
+ "@types/react-dom": "^19.2.5",
58
60
  "dedent": "^1.7.2",
59
- "eslint": "^10.8.1",
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": "*",