eslint-plugin-react-x 3.0.0-next.38 → 3.0.0-next.39

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 +15 -36
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_ESLINT_REACT_SETTINGS, IMPURE_CONSTRUCTORS, IMPURE_FUNCTIONS, WEBSITE_URL, coerceSettings, defineRuleListener, getConfigAdapters, getSettingsFromContext, report, toRegExp } from "@eslint-react/shared";
1
+ import { DEFAULT_ESLINT_REACT_SETTINGS, IMPURE_CTORS, IMPURE_FUNCS, WEBSITE_URL, coerceSettings, defineRuleListener, getConfigAdapters, getSettingsFromContext, report, toRegExp } from "@eslint-react/shared";
2
2
  import * as ast from "@eslint-react/ast";
3
3
  import * as core from "@eslint-react/core";
4
4
  import { ESLintUtils } from "@typescript-eslint/utils";
@@ -68,7 +68,7 @@ const rules$7 = {
68
68
  //#endregion
69
69
  //#region package.json
70
70
  var name$6 = "eslint-plugin-react-x";
71
- var version = "3.0.0-next.38";
71
+ var version = "3.0.0-next.39";
72
72
 
73
73
  //#endregion
74
74
  //#region src/utils/create-rule.ts
@@ -4186,30 +4186,6 @@ function create$7(context) {
4186
4186
  //#endregion
4187
4187
  //#region src/rules/purity/purity.ts
4188
4188
  const RULE_NAME$6 = "purity";
4189
- function isImpureMemberCall(node) {
4190
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return false;
4191
- const { object, property } = node.callee;
4192
- if (object.type !== AST_NODE_TYPES.Identifier) return false;
4193
- if (property.type !== AST_NODE_TYPES.Identifier) return false;
4194
- const methods = IMPURE_FUNCTIONS.get(object.name);
4195
- if (methods == null) return false;
4196
- return methods.has(property.name);
4197
- }
4198
- function isImpureNewExpression(node) {
4199
- if (node.callee.type !== AST_NODE_TYPES.Identifier) return false;
4200
- return IMPURE_CONSTRUCTORS.has(node.callee.name);
4201
- }
4202
- function getImpureCallName(node) {
4203
- if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return null;
4204
- const { object, property } = node.callee;
4205
- if (object.type !== AST_NODE_TYPES.Identifier) return null;
4206
- if (property.type !== AST_NODE_TYPES.Identifier) return null;
4207
- return `${object.name}.${property.name}()`;
4208
- }
4209
- function getImpureNewName(node) {
4210
- if (node.callee.type !== AST_NODE_TYPES.Identifier) return null;
4211
- return `new ${node.callee.name}()`;
4212
- }
4213
4189
  var purity_default = createRule({
4214
4190
  meta: {
4215
4191
  type: "problem",
@@ -4228,25 +4204,28 @@ function create$6(context) {
4228
4204
  const nExprs = [];
4229
4205
  return defineRuleListener(hCollector.visitor, cCollector.visitor, {
4230
4206
  CallExpression(node) {
4231
- if (!isImpureMemberCall(node)) return;
4232
- const name = getImpureCallName(node);
4233
- if (name == null) return;
4207
+ if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
4208
+ const expr = ast.getUnderlyingExpression(node.callee);
4209
+ if (expr.type !== AST_NODE_TYPES.MemberExpression) return;
4210
+ if (expr.object.type !== AST_NODE_TYPES.Identifier) return;
4211
+ if (expr.property.type !== AST_NODE_TYPES.Identifier) return;
4212
+ const objectName = expr.object.name;
4213
+ const propertyName = expr.property.name;
4214
+ if (!IMPURE_FUNCS.get(objectName)?.has(propertyName)) return;
4234
4215
  const func = ast.findParentNode(node, ast.isFunction);
4235
4216
  if (func == null) return;
4236
4217
  cExprs.push({
4237
- name,
4238
4218
  node,
4239
4219
  func
4240
4220
  });
4241
4221
  },
4242
4222
  NewExpression(node) {
4243
- if (!isImpureNewExpression(node)) return;
4244
- const name = getImpureNewName(node);
4245
- if (name == null) return;
4223
+ const expr = ast.getUnderlyingExpression(node.callee);
4224
+ if (expr.type !== AST_NODE_TYPES.Identifier) return;
4225
+ if (!IMPURE_CTORS.has(expr.name)) return;
4246
4226
  const func = ast.findParentNode(node, ast.isFunction);
4247
4227
  if (func == null) return;
4248
4228
  nExprs.push({
4249
- name,
4250
4229
  node,
4251
4230
  func
4252
4231
  });
@@ -4255,12 +4234,12 @@ function create$6(context) {
4255
4234
  const components = cCollector.ctx.getAllComponents(node);
4256
4235
  const hooks = hCollector.ctx.getAllHooks(node);
4257
4236
  const funcs = [...components, ...hooks];
4258
- for (const { name, node, func } of [...cExprs, ...nExprs]) {
4237
+ for (const { node, func } of [...cExprs, ...nExprs]) {
4259
4238
  if (!funcs.some((f) => f.node === func)) continue;
4260
4239
  context.report({
4261
4240
  messageId: "default",
4262
4241
  node,
4263
- data: { name }
4242
+ data: { name: context.sourceCode.getText(node) }
4264
4243
  });
4265
4244
  }
4266
4245
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "3.0.0-next.38",
3
+ "version": "3.0.0-next.39",
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",
@@ -45,11 +45,11 @@
45
45
  "string-ts": "^2.3.1",
46
46
  "ts-api-utils": "^2.4.0",
47
47
  "ts-pattern": "^5.9.0",
48
- "@eslint-react/ast": "3.0.0-next.38",
49
- "@eslint-react/eff": "3.0.0-next.38",
50
- "@eslint-react/shared": "3.0.0-next.38",
51
- "@eslint-react/core": "3.0.0-next.38",
52
- "@eslint-react/var": "3.0.0-next.38"
48
+ "@eslint-react/ast": "3.0.0-next.39",
49
+ "@eslint-react/core": "3.0.0-next.39",
50
+ "@eslint-react/eff": "3.0.0-next.39",
51
+ "@eslint-react/shared": "3.0.0-next.39",
52
+ "@eslint-react/var": "3.0.0-next.39"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^19.2.14",