eslint-plugin-react-x 5.30.0-rc.0 → 5.30.0-rc.2

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 +134 -13
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -16,14 +16,14 @@ import "typescript";
16
16
  import { delimiterCase, snakeCase, toLowerCase } from "string-ts";
17
17
  // \0rolldown/runtime.js
18
18
  var __defProp = Object.defineProperty;
19
- var __exportAll = (all, no_symbols) => {
20
- let target = {};
19
+ var __exportAll = (all, flags) => {
20
+ let target = Object.setPrototypeOf({}, null);
21
21
  for (var name in all) __defProp(target, name, {
22
22
  get: all[name],
23
23
  enumerable: true
24
24
  });
25
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
26
- return target;
25
+ if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
26
+ return flags & 2 ? target : Object.preventExtensions(target);
27
27
  };
28
28
  // src/configs/disable-conflict-eslint-plugin-react.ts
29
29
  var disable_conflict_eslint_plugin_react_exports = /* @__PURE__ */ __exportAll({
@@ -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-rc.0";
133
+ var version = "5.30.0-rc.2";
134
134
  // src/utils/create-rule.ts
135
135
  function getDocsUrl(ruleName) {
136
136
  return `https://eslint-react.xyz/docs/rules/${ruleName}`;
@@ -7136,12 +7136,28 @@ function createFactCollector$1() {
7136
7136
  return {
7137
7137
  facts,
7138
7138
  visitor: { JSXOpeningElement(node) {
7139
- if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) return;
7140
- const name = node.name.name;
7141
- if (!core.isFunctionComponentName(name)) return;
7139
+ const tag = node.name;
7140
+ if (tag.type === AST_NODE_TYPES.JSXNamespacedName) return;
7141
+ if (tag.type === AST_NODE_TYPES.JSXIdentifier) {
7142
+ if (!core.isFunctionComponentName(tag.name)) return;
7143
+ facts.componentUsages.push({
7144
+ name: tag.name,
7145
+ path: [],
7146
+ node: tag
7147
+ });
7148
+ return;
7149
+ }
7150
+ const path = [];
7151
+ let root = tag;
7152
+ while (root.type === AST_NODE_TYPES.JSXMemberExpression) {
7153
+ path.unshift(root.property.name);
7154
+ root = root.object;
7155
+ }
7156
+ if (root.type !== AST_NODE_TYPES.JSXIdentifier) return;
7142
7157
  facts.componentUsages.push({
7143
- name,
7144
- node: node.name
7158
+ name: root.name,
7159
+ path,
7160
+ node: tag
7145
7161
  });
7146
7162
  } }
7147
7163
  };
@@ -7159,8 +7175,63 @@ function createRenderBoundaryChecker(componentNodes) {
7159
7175
  return (node) => Traverse.hasParent(node, (n) => Check.isFunctionOrClass(n) && components.has(n));
7160
7176
  }
7161
7177
  // src/rules/static-components/origins.ts
7178
+ function getMemoizedValueExpressions(context, call) {
7179
+ const [factory] = call.arguments;
7180
+ if (factory == null || factory.type === AST_NODE_TYPES.SpreadElement) return null;
7181
+ if (core.isUseCallbackCall(context, call)) return [factory];
7182
+ if (!core.isUseMemoCall(context, call)) return null;
7183
+ const callback = Extract.unwrap(factory);
7184
+ if (!Check.isFunction(callback) || callback.async || callback.generator) return null;
7185
+ return Collect.getReturnExpressions(callback);
7186
+ }
7187
+ function resolveValueAtPath(context, node, path, isInsideRender, seen) {
7188
+ const expr = Extract.unwrap(node);
7189
+ if (path.length === 0) return expr;
7190
+ switch (expr.type) {
7191
+ case AST_NODE_TYPES.ObjectExpression: {
7192
+ const [head, ...rest] = path;
7193
+ for (const property of expr.properties) {
7194
+ if (property.type !== AST_NODE_TYPES.Property || property.computed) continue;
7195
+ if ((property.key.type === AST_NODE_TYPES.Identifier ? property.key.name : isString(property.key.value) ? property.key.value : null) !== head) continue;
7196
+ const { value } = property;
7197
+ if (value.type === AST_NODE_TYPES.ArrayPattern) continue;
7198
+ if (value.type === AST_NODE_TYPES.ObjectPattern) continue;
7199
+ if (value.type === AST_NODE_TYPES.AssignmentPattern) continue;
7200
+ if (value.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) continue;
7201
+ return resolveValueAtPath(context, value, rest, isInsideRender, seen);
7202
+ }
7203
+ return null;
7204
+ }
7205
+ case AST_NODE_TYPES.Identifier: {
7206
+ const variable = findVariable(context.sourceCode.getScope(expr), expr.name);
7207
+ if (variable == null || seen.has(variable)) return null;
7208
+ seen.add(variable);
7209
+ for (const def of variable.defs) {
7210
+ if (!isInsideRender(def.node)) continue;
7211
+ if (def.node.type !== AST_NODE_TYPES.VariableDeclarator || def.node.init == null) continue;
7212
+ const value = resolveValueAtPath(context, def.node.init, path, isInsideRender, seen);
7213
+ if (value != null) return value;
7214
+ }
7215
+ return null;
7216
+ }
7217
+ case AST_NODE_TYPES.MemberExpression:
7218
+ if (expr.computed || expr.property.type !== AST_NODE_TYPES.Identifier) return null;
7219
+ return resolveValueAtPath(context, expr.object, [expr.property.name, ...path], isInsideRender, seen);
7220
+ default: return null;
7221
+ }
7222
+ }
7162
7223
  function findDynamicCreationSite(context, node, isInsideRender, seen) {
7163
7224
  const expr = Extract.unwrap(node);
7225
+ if (expr.type === AST_NODE_TYPES.CallExpression) {
7226
+ const memoized = getMemoizedValueExpressions(context, expr);
7227
+ if (memoized != null) {
7228
+ for (const value of memoized) {
7229
+ const source = findDynamicCreationSite(context, value, isInsideRender, seen);
7230
+ if (source != null) return source;
7231
+ }
7232
+ return null;
7233
+ }
7234
+ }
7164
7235
  if (KNOWN_DYNAMIC_EXPRESSION_TYPES.has(expr.type)) return expr;
7165
7236
  switch (expr.type) {
7166
7237
  case AST_NODE_TYPES.ConditionalExpression: return findDynamicCreationSite(context, expr.consequent, isInsideRender, seen) ?? findDynamicCreationSite(context, expr.alternate, isInsideRender, seen);
@@ -7169,6 +7240,11 @@ function findDynamicCreationSite(context, node, isInsideRender, seen) {
7169
7240
  const last = expr.expressions.at(-1);
7170
7241
  return last == null ? null : findDynamicCreationSite(context, last, isInsideRender, seen);
7171
7242
  }
7243
+ case AST_NODE_TYPES.MemberExpression: {
7244
+ if (expr.computed || expr.property.type !== AST_NODE_TYPES.Identifier) return null;
7245
+ const value = resolveValueAtPath(context, expr.object, [expr.property.name], isInsideRender, seen);
7246
+ return value == null ? null : findDynamicCreationSite(context, value, isInsideRender, seen);
7247
+ }
7172
7248
  case AST_NODE_TYPES.Identifier:
7173
7249
  case AST_NODE_TYPES.JSXIdentifier: {
7174
7250
  const variable = findVariable(context.sourceCode.getScope(expr), expr.name);
@@ -7178,13 +7254,28 @@ function findDynamicCreationSite(context, node, isInsideRender, seen) {
7178
7254
  default: return null;
7179
7255
  }
7180
7256
  }
7181
- function findReassignmentCreationSite(context, variable, isInsideRender, seen) {
7257
+ function getReassignmentValues(variable) {
7258
+ const values = [];
7182
7259
  for (const ref of variable.references) {
7183
7260
  if (!ref.isWrite()) continue;
7184
7261
  const { identifier } = ref;
7185
7262
  if (identifier.parent.type !== AST_NODE_TYPES.AssignmentExpression) continue;
7186
7263
  if (identifier.parent.left !== identifier) continue;
7187
- const source = findDynamicCreationSite(context, identifier.parent.right, isInsideRender, seen);
7264
+ values.push(identifier.parent.right);
7265
+ }
7266
+ return values;
7267
+ }
7268
+ function findReassignmentCreationSite(context, variable, isInsideRender, seen) {
7269
+ for (const value of getReassignmentValues(variable)) {
7270
+ const source = findDynamicCreationSite(context, value, isInsideRender, seen);
7271
+ if (source != null) return source;
7272
+ }
7273
+ return null;
7274
+ }
7275
+ function findMemberReassignmentCreationSite(context, variable, path, isInsideRender, seen) {
7276
+ for (const value of getReassignmentValues(variable)) {
7277
+ const selected = resolveValueAtPath(context, value, path, isInsideRender, seen);
7278
+ const source = selected == null ? null : findDynamicCreationSite(context, selected, isInsideRender, seen);
7188
7279
  if (source != null) return source;
7189
7280
  }
7190
7281
  return null;
@@ -7221,6 +7312,36 @@ function resolveDynamicComponentOrigin(context, variable, isInsideRender, seen =
7221
7312
  isDynamic: false
7222
7313
  };
7223
7314
  }
7315
+ function resolveDynamicMemberOrigin(context, variable, path, isInsideRender, seen = /* @__PURE__ */ new Set()) {
7316
+ if (path.length === 0) return resolveDynamicComponentOrigin(context, variable, isInsideRender, seen);
7317
+ if (seen.has(variable)) return {
7318
+ creationNode: null,
7319
+ isDynamic: false
7320
+ };
7321
+ seen.add(variable);
7322
+ for (const def of variable.defs) {
7323
+ const defNode = def.node;
7324
+ if (!isInsideRender(defNode)) continue;
7325
+ if (defNode.type !== AST_NODE_TYPES.VariableDeclarator) continue;
7326
+ if (defNode.init != null) {
7327
+ const selected = resolveValueAtPath(context, defNode.init, path, isInsideRender, seen);
7328
+ const initSource = selected == null ? null : findDynamicCreationSite(context, selected, isInsideRender, seen);
7329
+ if (initSource != null) return {
7330
+ creationNode: initSource,
7331
+ isDynamic: true
7332
+ };
7333
+ }
7334
+ const reassignmentSource = findMemberReassignmentCreationSite(context, variable, path, isInsideRender, seen);
7335
+ if (reassignmentSource != null) return {
7336
+ creationNode: reassignmentSource,
7337
+ isDynamic: true
7338
+ };
7339
+ }
7340
+ return {
7341
+ creationNode: null,
7342
+ isDynamic: false
7343
+ };
7344
+ }
7224
7345
  // src/rules/static-components/effects.ts
7225
7346
  function inferCreatedComponents(context, componentUsages, isInsideRender) {
7226
7347
  const effects = [];
@@ -7228,7 +7349,7 @@ function inferCreatedComponents(context, componentUsages, isInsideRender) {
7228
7349
  const variable = findVariable(context.sourceCode.getScope(usage.node), usage.name);
7229
7350
  if (variable == null) continue;
7230
7351
  if (!variable.defs.some((def) => isInsideRender(def.node))) continue;
7231
- const { creationNode, isDynamic } = resolveDynamicComponentOrigin(context, variable, isInsideRender);
7352
+ const { creationNode, isDynamic } = usage.path.length === 0 ? resolveDynamicComponentOrigin(context, variable, isInsideRender) : resolveDynamicMemberOrigin(context, variable, usage.path, isInsideRender);
7232
7353
  if (!isDynamic) continue;
7233
7354
  effects.push({
7234
7355
  name: usage.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.30.0-rc.0",
3
+ "version": "5.30.0-rc.2",
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.30.0-rc.0",
40
- "@eslint-react/core": "5.30.0-rc.0",
41
- "@eslint-react/eslint": "5.30.0-rc.0",
42
- "@eslint-react/jsx": "5.30.0-rc.0",
43
- "@eslint-react/shared": "5.30.0-rc.0",
44
- "@eslint-react/var": "5.30.0-rc.0",
39
+ "@eslint-react/ast": "5.30.0-rc.2",
40
+ "@eslint-react/core": "5.30.0-rc.2",
41
+ "@eslint-react/eslint": "5.30.0-rc.2",
42
+ "@eslint-react/jsx": "5.30.0-rc.2",
43
+ "@eslint-react/shared": "5.30.0-rc.2",
44
+ "@eslint-react/var": "5.30.0-rc.2",
45
45
  "@typescript-eslint/scope-manager": "^8.72.1",
46
46
  "@typescript-eslint/types": "^8.72.1",
47
47
  "@typescript-eslint/utils": "^8.72.1",
@@ -63,7 +63,7 @@
63
63
  "eslint": "^10.14.0",
64
64
  "react": "^19.3.1",
65
65
  "react-dom": "^19.3.1",
66
- "tsdown": "^0.23.5",
66
+ "tsdown": "^0.23.7",
67
67
  "tsl": "^1.0.30",
68
68
  "tsl-dx": "^0.15.2",
69
69
  "typescript": "6.0.3"