eslint-plugin-react-x 5.30.0-beta.15 → 5.30.0-beta.17
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 +41 -26
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ 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, resolveOriginChain } from "@eslint-react/var";
|
|
8
|
+
import { isAssignmentTargetEqual, isInitializedFromReact, resolveAssignmentTargets, 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
11
|
import { findParentAttribute, getElementFullType, getElementSelfType, hasAttribute, isInsideCreateElementProps, isPlainAttribute, parseCreateElementCall } from "@eslint-react/jsx";
|
|
@@ -129,7 +129,7 @@ const rules$6 = {
|
|
|
129
129
|
};
|
|
130
130
|
// package.json
|
|
131
131
|
var name$6 = "eslint-plugin-react-x";
|
|
132
|
-
var version = "5.30.0-beta.
|
|
132
|
+
var version = "5.30.0-beta.17";
|
|
133
133
|
// src/utils/create-rule.ts
|
|
134
134
|
function getDocsUrl(ruleName) {
|
|
135
135
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
@@ -1095,7 +1095,7 @@ function createFactCollector$6() {
|
|
|
1095
1095
|
facts,
|
|
1096
1096
|
visitor: {
|
|
1097
1097
|
AssignmentExpression(node) {
|
|
1098
|
-
for (const target of
|
|
1098
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1099
1099
|
},
|
|
1100
1100
|
CallExpression(node) {
|
|
1101
1101
|
const caller = getEnclosingFunction(node);
|
|
@@ -1117,11 +1117,11 @@ function createFactCollector$6() {
|
|
|
1117
1117
|
},
|
|
1118
1118
|
ForInStatement(node) {
|
|
1119
1119
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1120
|
-
for (const target of
|
|
1120
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1121
1121
|
},
|
|
1122
1122
|
ForOfStatement(node) {
|
|
1123
1123
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1124
|
-
for (const target of
|
|
1124
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1125
1125
|
},
|
|
1126
1126
|
UnaryExpression(node) {
|
|
1127
1127
|
if (node.operator !== "delete") return;
|
|
@@ -1303,9 +1303,13 @@ function isRefLikeName$2(name) {
|
|
|
1303
1303
|
return name === "ref" || name.endsWith("Ref");
|
|
1304
1304
|
}
|
|
1305
1305
|
function hasRefLikeNameInChain(node) {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1306
|
+
let current = Extract.unwrap(node);
|
|
1307
|
+
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
1308
|
+
const property = Extract.unwrap(current.property);
|
|
1309
|
+
if (Check.isIdentifier(property) && isRefLikeName$2(property.name)) return true;
|
|
1310
|
+
current = Extract.unwrap(current.object);
|
|
1311
|
+
}
|
|
1312
|
+
return Check.isIdentifier(current) && isRefLikeName$2(current.name);
|
|
1309
1313
|
}
|
|
1310
1314
|
// src/rules/immutability/collect.ts
|
|
1311
1315
|
function createFactCollector$5() {
|
|
@@ -1325,8 +1329,9 @@ function createFactCollector$5() {
|
|
|
1325
1329
|
});
|
|
1326
1330
|
}
|
|
1327
1331
|
function pushMemberMutation(node, target) {
|
|
1328
|
-
|
|
1329
|
-
|
|
1332
|
+
let root = Extract.unwrap(target);
|
|
1333
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1334
|
+
if (!Check.isIdentifier(root)) return;
|
|
1330
1335
|
pushMutation("value", node, target, root);
|
|
1331
1336
|
}
|
|
1332
1337
|
function pushTargetMutation(node, target) {
|
|
@@ -1340,7 +1345,7 @@ function createFactCollector$5() {
|
|
|
1340
1345
|
facts,
|
|
1341
1346
|
visitor: {
|
|
1342
1347
|
AssignmentExpression(node) {
|
|
1343
|
-
for (const target of
|
|
1348
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1344
1349
|
},
|
|
1345
1350
|
CallExpression(node) {
|
|
1346
1351
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -1359,11 +1364,11 @@ function createFactCollector$5() {
|
|
|
1359
1364
|
},
|
|
1360
1365
|
ForInStatement(node) {
|
|
1361
1366
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1362
|
-
for (const target of
|
|
1367
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1363
1368
|
},
|
|
1364
1369
|
ForOfStatement(node) {
|
|
1365
1370
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1366
|
-
for (const target of
|
|
1371
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1367
1372
|
},
|
|
1368
1373
|
JSXAttribute(node) {
|
|
1369
1374
|
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
@@ -1429,8 +1434,9 @@ function getStateHookName(context, init) {
|
|
|
1429
1434
|
return null;
|
|
1430
1435
|
}
|
|
1431
1436
|
function isInitializedFromCall(context, node, isCall) {
|
|
1432
|
-
|
|
1433
|
-
|
|
1437
|
+
let root = Extract.unwrap(node);
|
|
1438
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1439
|
+
if (!Check.isIdentifier(root)) return false;
|
|
1434
1440
|
const variable = findVariable(context.sourceCode.getScope(root), root);
|
|
1435
1441
|
if (variable == null) return false;
|
|
1436
1442
|
const origin = resolveVariableOrigin(context, variable);
|
|
@@ -1460,8 +1466,9 @@ function classifyFrozenOrigin(context, variable, components, mode = "alias", see
|
|
|
1460
1466
|
if (def.node.init == null) {
|
|
1461
1467
|
const loop = def.node.parent.parent;
|
|
1462
1468
|
if (loop.type !== AST_NODE_TYPES.ForOfStatement || loop.left !== def.node.parent) return null;
|
|
1463
|
-
|
|
1464
|
-
|
|
1469
|
+
let root = Extract.unwrap(loop.right);
|
|
1470
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1471
|
+
if (!Check.isIdentifier(root)) return null;
|
|
1465
1472
|
const source = findVariable(context.sourceCode.getScope(root), root);
|
|
1466
1473
|
if (source == null) return null;
|
|
1467
1474
|
const inner = classifyFrozenOrigin(context, source, components, mode, seen);
|
|
@@ -1792,7 +1799,8 @@ function create$46(context) {
|
|
|
1792
1799
|
for (const property of propsObject.properties) {
|
|
1793
1800
|
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
1794
1801
|
if (property.computed) continue;
|
|
1795
|
-
|
|
1802
|
+
const key = Extract.unwrap(property.key);
|
|
1803
|
+
if (Check.isIdentifier(key) ? key.name !== "key" : key.value !== "key") continue;
|
|
1796
1804
|
const value = property.value;
|
|
1797
1805
|
for (const desc of visitKeyExpression(value)) context.report(desc);
|
|
1798
1806
|
}
|
|
@@ -4069,16 +4077,23 @@ function getDestructuredPropertyName(pattern, name) {
|
|
|
4069
4077
|
for (const property of pattern.properties) {
|
|
4070
4078
|
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
4071
4079
|
if ((property.value.type === AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value) !== name) continue;
|
|
4072
|
-
|
|
4080
|
+
const key = Extract.unwrap(property.key);
|
|
4081
|
+
if (!property.computed && Check.isIdentifier(key)) return key.name;
|
|
4082
|
+
if (key.type === AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
4083
|
+
if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
|
|
4084
|
+
return null;
|
|
4073
4085
|
}
|
|
4074
4086
|
return null;
|
|
4075
4087
|
}
|
|
4076
4088
|
function resolveBuiltinMember(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
4077
|
-
|
|
4078
|
-
const
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4089
|
+
let rootId = Extract.unwrap(node);
|
|
4090
|
+
const segments = [];
|
|
4091
|
+
for (let current = rootId; current.type === AST_NODE_TYPES.MemberExpression; current = Extract.unwrap(current.object)) {
|
|
4092
|
+
if (current.computed) return null;
|
|
4093
|
+
segments.unshift(Extract.unwrap(current.property));
|
|
4094
|
+
rootId = Extract.unwrap(current.object);
|
|
4095
|
+
}
|
|
4096
|
+
if (!Check.isIdentifier(rootId)) return null;
|
|
4082
4097
|
if (segments.length === 0 || !segments.every((segment) => Check.isIdentifier(segment))) return null;
|
|
4083
4098
|
const resolved = resolveBuiltinObjectName(context, rootId, seen);
|
|
4084
4099
|
if (resolved == null) return null;
|
|
@@ -7269,12 +7284,12 @@ function createFactCollector(isUseMemoCall) {
|
|
|
7269
7284
|
Traverse.simpleTraverse(callback.body, { enter(node) {
|
|
7270
7285
|
switch (node.type) {
|
|
7271
7286
|
case AST_NODE_TYPES.AssignmentExpression:
|
|
7272
|
-
for (const target of
|
|
7287
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
7273
7288
|
return;
|
|
7274
7289
|
case AST_NODE_TYPES.ForInStatement:
|
|
7275
7290
|
case AST_NODE_TYPES.ForOfStatement:
|
|
7276
7291
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
7277
|
-
for (const target of
|
|
7292
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
7278
7293
|
return;
|
|
7279
7294
|
}
|
|
7280
7295
|
} });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.30.0-beta.
|
|
3
|
+
"version": "5.30.0-beta.17",
|
|
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-beta.
|
|
40
|
-
"@eslint-react/core": "5.30.0-beta.
|
|
41
|
-
"@eslint-react/eslint": "5.30.0-beta.
|
|
42
|
-
"@eslint-react/jsx": "5.30.0-beta.
|
|
43
|
-
"@eslint-react/shared": "5.30.0-beta.
|
|
44
|
-
"@eslint-react/var": "5.30.0-beta.
|
|
39
|
+
"@eslint-react/ast": "5.30.0-beta.17",
|
|
40
|
+
"@eslint-react/core": "5.30.0-beta.17",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.17",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.17",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.17",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.17",
|
|
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",
|