eslint-plugin-react-x 5.30.0-beta.4 → 5.30.0-beta.6

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 +38 -34
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import * as core from "@eslint-react/core";
5
5
  import { getConstrainedTypeAtLocation, getText, merge, report } from "@eslint-react/eslint";
6
6
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
7
7
  import { P, isMatching, match } from "ts-pattern";
8
- import { isAssignmentTargetEqual, isInitializedFromReact, resolveEnclosingAssignmentTarget, resolveObjectType, resolveOrigin } from "@eslint-react/var";
8
+ import { isAssignmentTargetEqual, isInitializedFromReact, resolveEnclosingAssignmentTarget, resolveObjectType, resolveOrigin, resolveOriginChain } from "@eslint-react/var";
9
9
  import { DefinitionType, ScopeType } from "@typescript-eslint/scope-manager";
10
10
  import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
11
- import { findParentAttribute, getCreateElementPropsObject, getElementFullType, hasAttribute, isAttribute, isInsideCreateElementProps } from "@eslint-react/jsx";
11
+ import { findParentAttribute, getElementFullType, getElementSelfType, hasAttribute, isInsideCreateElementProps, isPlainAttribute, parseCreateElementCall } from "@eslint-react/jsx";
12
12
  import { compare } from "compare-versions";
13
13
  import { unionConstituents } from "ts-api-utils";
14
14
  import "typescript";
@@ -130,7 +130,7 @@ const rules$6 = {
130
130
  };
131
131
  // package.json
132
132
  var name$6 = "eslint-plugin-react-x";
133
- var version = "5.30.0-beta.4";
133
+ var version = "5.30.0-beta.6";
134
134
  // src/utils/create-rule.ts
135
135
  function getDocsUrl(ruleName) {
136
136
  return `https://eslint-react.xyz/docs/rules/${ruleName}`;
@@ -1160,14 +1160,13 @@ function resolveGlobalOrigin(context, node, seen = /* @__PURE__ */ new Set()) {
1160
1160
  if (initializer.type !== AST_NODE_TYPES.Identifier && initializer.type !== AST_NODE_TYPES.MemberExpression) return null;
1161
1161
  return resolveGlobalOrigin(context, initializer, seen);
1162
1162
  }
1163
- function resolveToFunction(context, node, seen = /* @__PURE__ */ new Set()) {
1163
+ function resolveToFunction(context, node) {
1164
1164
  const expression = Extract.unwrap(node);
1165
1165
  if (Check.isFunction(expression)) return expression;
1166
- if (!Check.isIdentifier(expression) || seen.has(expression)) return null;
1167
- seen.add(expression);
1168
- const resolved = resolveOrigin(context, expression);
1169
- if (resolved == null) return null;
1170
- return resolveToFunction(context, resolved, seen);
1166
+ if (!Check.isIdentifier(expression)) return null;
1167
+ const origin = resolveOriginChain(context, expression);
1168
+ const unwrapped = origin == null ? null : Extract.unwrap(origin);
1169
+ return unwrapped != null && Check.isFunction(unwrapped) ? unwrapped : null;
1171
1170
  }
1172
1171
  // src/rules/globals/effects.ts
1173
1172
  function inferGlobalMutations(context, facts) {
@@ -1408,13 +1407,13 @@ function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__P
1408
1407
  const source = findVariable(context.sourceCode.getScope(init), init);
1409
1408
  return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
1410
1409
  }
1411
- function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set()) {
1410
+ function resolveToFunctionNode(context, node) {
1412
1411
  const expr = Extract.unwrap(node);
1413
1412
  if (Check.isFunction(expr)) return expr;
1414
- if (!Check.isIdentifier(expr) || seen.has(expr)) return null;
1415
- seen.add(expr);
1416
- const resolved = resolveOrigin(context, expr);
1417
- return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
1413
+ if (!Check.isIdentifier(expr)) return null;
1414
+ const origin = resolveOriginChain(context, expr);
1415
+ const unwrapped = origin == null ? null : Extract.unwrap(origin);
1416
+ return unwrapped != null && Check.isFunction(unwrapped) ? unwrapped : null;
1418
1417
  }
1419
1418
  function isComponentPropsDefinition(def, components) {
1420
1419
  if (def.type !== DefinitionType.Parameter) return false;
@@ -1727,7 +1726,7 @@ function isArrayIndexReference(context, node) {
1727
1726
  if (call.arguments[callbackPosition] !== argument) return false;
1728
1727
  const param = callback.params[indexPosition];
1729
1728
  if (param == null) return false;
1730
- return param === def.name || param.type === AST_NODE_TYPES.AssignmentPattern && param.left === def.name;
1729
+ return (param.type === AST_NODE_TYPES.AssignmentPattern ? param.left : param) === def.name;
1731
1730
  }
1732
1731
  function getIdentifiersFromBinaryExpression(side) {
1733
1732
  if (Check.isIdentifier(side)) return [side];
@@ -1749,9 +1748,10 @@ function create$46(context) {
1749
1748
  return node != null && Check.isIdentifier(node) && isArrayIndexReference(context, node);
1750
1749
  }
1751
1750
  function getPropsObject(node) {
1752
- const props = node.arguments[1];
1753
- if (core.isCreateElementCall(context, node)) return getCreateElementPropsObject(context, node);
1751
+ const call = parseCreateElementCall(context, node);
1752
+ if (call != null) return call.propsObject;
1754
1753
  if (!core.isCloneElementCall(context, node)) return null;
1754
+ const props = node.arguments[1];
1755
1755
  return props?.type === AST_NODE_TYPES.ObjectExpression ? props : null;
1756
1756
  }
1757
1757
  function visitKeyExpression(node) {
@@ -2717,10 +2717,13 @@ function create$24(context) {
2717
2717
  case AST_NODE_TYPES.TSNonNullExpression:
2718
2718
  case AST_NODE_TYPES.TSSatisfiesExpression:
2719
2719
  case AST_NODE_TYPES.TSInstantiationExpression: return visitItemExpression(node.expression);
2720
- case AST_NODE_TYPES.JSXElement: return hasAttribute(context, node, "key") ? [] : [{
2721
- messageId: "default",
2722
- node
2723
- }];
2720
+ case AST_NODE_TYPES.JSXElement:
2721
+ if (hasAttribute(node, "key")) return [];
2722
+ if (node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute)) return [];
2723
+ return [{
2724
+ messageId: "default",
2725
+ node
2726
+ }];
2724
2727
  case AST_NODE_TYPES.JSXFragment: return [{
2725
2728
  messageId: "unexpected-fragment-syntax",
2726
2729
  node
@@ -3206,14 +3209,15 @@ function create$13(context) {
3206
3209
  const constructions = /* @__PURE__ */ new WeakMap();
3207
3210
  return merge(visitor, {
3208
3211
  JSXOpeningElement(node) {
3209
- const selfName = getElementFullType(node.parent).split(".").at(-1);
3210
- if (selfName == null) return;
3212
+ const selfName = getElementSelfType(node.parent);
3213
+ if (selfName === "") return;
3211
3214
  if (!isContextName(selfName, isReact18OrBelow)) return;
3212
3215
  const enclosingFunction = Traverse.findParent(node, Check.isFunction);
3213
3216
  if (enclosingFunction == null) return;
3214
3217
  if (compilationMode === "annotation" && core.isFunctionHasDirective(enclosingFunction, "use memo")) return;
3215
- const attribute = node.attributes.findLast(isAttribute("value"));
3216
- if (attribute?.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
3218
+ const attribute = node.attributes.findLast(isPlainAttribute("value"));
3219
+ if (attribute?.type !== AST_NODE_TYPES.JSXAttribute) return;
3220
+ if (attribute.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
3217
3221
  const valueExpression = attribute.value.expression;
3218
3222
  const construction = resolveObjectType(context, valueExpression);
3219
3223
  if (construction == null) return;
@@ -3298,7 +3302,7 @@ function create$12(context, [options]) {
3298
3302
  return declarators.get(component)?.filter((d) => d.init.name === name).flatMap((d) => d.id.properties) ?? [];
3299
3303
  }).otherwise(() => []);
3300
3304
  for (const prop of properties) {
3301
- if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) continue;
3305
+ if (prop.type !== AST_NODE_TYPES.Property || !Check.isObjectPatternElementDefault(prop.value)) continue;
3302
3306
  const { value } = prop;
3303
3307
  const { right } = value;
3304
3308
  const construction = resolveObjectType(context, value);
@@ -6401,11 +6405,8 @@ function isRefLikeName(name) {
6401
6405
  return name === "ref" || name.endsWith("Ref");
6402
6406
  }
6403
6407
  function getParameterId(param) {
6404
- switch (param.type) {
6405
- case AST_NODE_TYPES.Identifier: return param;
6406
- case AST_NODE_TYPES.AssignmentPattern: return param.left.type === AST_NODE_TYPES.Identifier ? param.left : null;
6407
- default: return null;
6408
- }
6408
+ const target = param.type === AST_NODE_TYPES.AssignmentPattern ? param.left : param;
6409
+ return target.type === AST_NODE_TYPES.Identifier ? target : null;
6409
6410
  }
6410
6411
  function getRefSourceName(node) {
6411
6412
  switch (node.type) {
@@ -7354,8 +7355,10 @@ const rule = {
7354
7355
  } else if (name === "useState" || name === "useReducer" || name === "useActionState") {
7355
7356
  const isActionState = name === "useActionState";
7356
7357
  if (id.type === "ArrayPattern" && (isActionState ? id.elements.length >= 2 : id.elements.length === 2) && isArray(resolved.identifiers)) {
7357
- const firstElement = id.elements[0]?.type === "AssignmentPattern" ? id.elements[0].left : id.elements[0];
7358
- const secondElement = id.elements[1]?.type === "AssignmentPattern" ? id.elements[1].left : id.elements[1];
7358
+ const firstNode = id.elements[0] ?? null;
7359
+ const secondNode = id.elements[1] ?? null;
7360
+ const firstElement = firstNode?.type === "AssignmentPattern" ? firstNode.left : firstNode;
7361
+ const secondElement = secondNode?.type === "AssignmentPattern" ? secondNode.left : secondNode;
7359
7362
  if (resolved.identifiers.some((identifier) => identifier === secondElement)) {
7360
7363
  if (name === "useState") {
7361
7364
  const references = resolved.references;
@@ -7375,7 +7378,8 @@ const rule = {
7375
7378
  }
7376
7379
  } else if (name === "useTransition") {
7377
7380
  if (id.type === "ArrayPattern" && id.elements.length === 2 && Array.isArray(resolved.identifiers)) {
7378
- const secondElement = id.elements[1]?.type === "AssignmentPattern" ? id.elements[1].left : id.elements[1];
7381
+ const secondNode = id.elements[1] ?? null;
7382
+ const secondElement = secondNode?.type === "AssignmentPattern" ? secondNode.left : secondNode;
7379
7383
  if (resolved.identifiers.some((identifier) => identifier === secondElement)) return true;
7380
7384
  }
7381
7385
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.30.0-beta.4",
3
+ "version": "5.30.0-beta.6",
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,15 +36,15 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@eslint-react/ast": "5.30.0-beta.4",
40
- "@eslint-react/core": "5.30.0-beta.4",
41
- "@eslint-react/eslint": "5.30.0-beta.4",
42
- "@eslint-react/jsx": "5.30.0-beta.4",
43
- "@eslint-react/shared": "5.30.0-beta.4",
44
- "@eslint-react/var": "5.30.0-beta.4",
45
- "@typescript-eslint/scope-manager": "^8.72.0",
46
- "@typescript-eslint/types": "^8.72.0",
47
- "@typescript-eslint/utils": "^8.72.0",
39
+ "@eslint-react/ast": "5.30.0-beta.6",
40
+ "@eslint-react/core": "5.30.0-beta.6",
41
+ "@eslint-react/eslint": "5.30.0-beta.6",
42
+ "@eslint-react/jsx": "5.30.0-beta.6",
43
+ "@eslint-react/shared": "5.30.0-beta.6",
44
+ "@eslint-react/var": "5.30.0-beta.6",
45
+ "@typescript-eslint/scope-manager": "^8.72.1",
46
+ "@typescript-eslint/types": "^8.72.1",
47
+ "@typescript-eslint/utils": "^8.72.1",
48
48
  "compare-versions": "^6.1.1",
49
49
  "string-ts": "^2.3.1",
50
50
  "ts-api-utils": "^2.5.0",