eslint-plugin-react-x 5.2.3-next.1 → 5.2.4-beta.0
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 +38 -35
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -143,7 +143,7 @@ const rules$7 = {
|
|
|
143
143
|
//#endregion
|
|
144
144
|
//#region package.json
|
|
145
145
|
var name$6 = "eslint-plugin-react-x";
|
|
146
|
-
var version = "5.2.
|
|
146
|
+
var version = "5.2.4-beta.0";
|
|
147
147
|
|
|
148
148
|
//#endregion
|
|
149
149
|
//#region src/rules/component-hook-factories/lib.ts
|
|
@@ -1325,7 +1325,7 @@ function create$46(context) {
|
|
|
1325
1325
|
const { object, property } = node.callee;
|
|
1326
1326
|
if (property.type !== AST_NODE_TYPES.Identifier) return;
|
|
1327
1327
|
if (!MUTATING_ARRAY_METHODS.has(property.name)) return;
|
|
1328
|
-
const rootId = Extract.
|
|
1328
|
+
const rootId = Extract.getRootIdentifier(object);
|
|
1329
1329
|
if (rootId == null) return;
|
|
1330
1330
|
if (rootId.name === "draft") return;
|
|
1331
1331
|
const enclosingFn = Traverse.findParent(node, Check.isFunction);
|
|
@@ -1346,7 +1346,7 @@ function create$46(context) {
|
|
|
1346
1346
|
},
|
|
1347
1347
|
AssignmentExpression(node) {
|
|
1348
1348
|
if (node.left.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
1349
|
-
const rootId = Extract.
|
|
1349
|
+
const rootId = Extract.getRootIdentifier(node.left);
|
|
1350
1350
|
if (rootId == null) return;
|
|
1351
1351
|
if (rootId.name === "draft") return;
|
|
1352
1352
|
const enclosingFn = Traverse.findParent(node, Check.isFunction);
|
|
@@ -1613,14 +1613,14 @@ function create$45(context) {
|
|
|
1613
1613
|
classStack.pop();
|
|
1614
1614
|
},
|
|
1615
1615
|
MemberExpression(node) {
|
|
1616
|
-
if (
|
|
1616
|
+
if (node.object.type !== AST_NODE_TYPES.ThisExpression) return;
|
|
1617
1617
|
const [currClass, isComponent = false] = classStack.at(-1) ?? [];
|
|
1618
1618
|
if (currClass == null || !isComponent) return;
|
|
1619
1619
|
const [currMethod, isStatic = false] = methodStack.at(-1) ?? [];
|
|
1620
1620
|
if (currMethod == null || isStatic) return;
|
|
1621
1621
|
const [setState, hasThisState = false] = setStateStack.at(-1) ?? [];
|
|
1622
1622
|
if (setState == null || hasThisState) return;
|
|
1623
|
-
if (Extract.
|
|
1623
|
+
if (Extract.getPropertyName(node.property) !== "state") return;
|
|
1624
1624
|
context.report({
|
|
1625
1625
|
messageId: "default",
|
|
1626
1626
|
node
|
|
@@ -1645,8 +1645,8 @@ function create$45(context) {
|
|
|
1645
1645
|
if (currMethod == null || isStatic) return;
|
|
1646
1646
|
const [setState, hasThisState = false] = setStateStack.at(-1) ?? [];
|
|
1647
1647
|
if (setState == null || hasThisState) return;
|
|
1648
|
-
if (node.init == null ||
|
|
1649
|
-
if (!node.id.properties.some((prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral$1(prop, prop.key) && Extract.
|
|
1648
|
+
if (node.init == null || node.init.type !== AST_NODE_TYPES.ThisExpression || node.id.type !== AST_NODE_TYPES.ObjectPattern) return;
|
|
1649
|
+
if (!node.id.properties.some((prop) => prop.type === AST_NODE_TYPES.Property && isKeyLiteral$1(prop, prop.key) && Extract.getPropertyName(prop.key) === "state")) return;
|
|
1650
1650
|
context.report({
|
|
1651
1651
|
messageId: "default",
|
|
1652
1652
|
node
|
|
@@ -2170,7 +2170,7 @@ function create$30(context) {
|
|
|
2170
2170
|
const aValue = a.value;
|
|
2171
2171
|
const bValue = b.value;
|
|
2172
2172
|
if (aValue == null || bValue == null) return false;
|
|
2173
|
-
return Compare.
|
|
2173
|
+
return Compare.isEqual(aValue, bValue);
|
|
2174
2174
|
}
|
|
2175
2175
|
return merge({
|
|
2176
2176
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -2194,7 +2194,7 @@ function create$30(context) {
|
|
|
2194
2194
|
if (!Check.isFunction(iter)) return;
|
|
2195
2195
|
const arg0 = call?.arguments[0];
|
|
2196
2196
|
if (call == null || arg0 == null) return;
|
|
2197
|
-
if (Extract.
|
|
2197
|
+
if (Extract.unwrap(arg0) !== iter) return;
|
|
2198
2198
|
keyedEntries.set(call, {
|
|
2199
2199
|
hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
|
|
2200
2200
|
keys: [node],
|
|
@@ -2508,7 +2508,7 @@ function create$25(context) {
|
|
|
2508
2508
|
}, ({ left, right }) => {
|
|
2509
2509
|
if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!") return getReportDescriptor(right);
|
|
2510
2510
|
const initialScope = context.sourceCode.getScope(left);
|
|
2511
|
-
if (Check.
|
|
2511
|
+
if (Check.isIdentifier("NaN")(left) || getStaticValue(left, initialScope)?.value === "NaN") return {
|
|
2512
2512
|
data: { value: context.sourceCode.getText(left) },
|
|
2513
2513
|
messageId: "default",
|
|
2514
2514
|
node: left
|
|
@@ -2765,8 +2765,8 @@ function isProcessEnvNodeEnvCompare(node, operator, value) {
|
|
|
2765
2765
|
if (node == null) return false;
|
|
2766
2766
|
if (node.type !== AST_NODE_TYPES.BinaryExpression) return false;
|
|
2767
2767
|
if (node.operator !== operator) return false;
|
|
2768
|
-
if (isProcessEnvNodeEnv(node.left) && Check.
|
|
2769
|
-
if (Check.
|
|
2768
|
+
if (isProcessEnvNodeEnv(node.left) && Check.isLiteral("string")(node.right)) return node.right.value === value;
|
|
2769
|
+
if (Check.isLiteral("string")(node.left) && isProcessEnvNodeEnv(node.right)) return node.left.value === value;
|
|
2770
2770
|
return false;
|
|
2771
2771
|
}
|
|
2772
2772
|
|
|
@@ -3207,7 +3207,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
3207
3207
|
function create$11(context) {
|
|
3208
3208
|
const { compilationMode, version } = getSettingsFromContext(context);
|
|
3209
3209
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3210
|
-
if (compilationMode === "annotation" && context.sourceCode.ast.body.some(
|
|
3210
|
+
if (compilationMode === "annotation" && context.sourceCode.ast.body.some(Check.isDirective("use memo"))) return {};
|
|
3211
3211
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
3212
3212
|
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3213
3213
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
@@ -3237,7 +3237,7 @@ function create$11(context) {
|
|
|
3237
3237
|
const suggestion = kind === "function" ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
3238
3238
|
context.report({
|
|
3239
3239
|
data: {
|
|
3240
|
-
kind: Extract.
|
|
3240
|
+
kind: Extract.getHumanReadableKind(constructionNode),
|
|
3241
3241
|
suggestion
|
|
3242
3242
|
},
|
|
3243
3243
|
messageId: "unstableContextValue",
|
|
@@ -3254,6 +3254,14 @@ function isContextName(name, isReact18OrBelow) {
|
|
|
3254
3254
|
return false;
|
|
3255
3255
|
}
|
|
3256
3256
|
|
|
3257
|
+
//#endregion
|
|
3258
|
+
//#region src/rules/no-unstable-default-props/lib.ts
|
|
3259
|
+
const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
|
|
3260
|
+
"VariableDeclarator",
|
|
3261
|
+
"[id.type='ObjectPattern']",
|
|
3262
|
+
"[init.type='Identifier']"
|
|
3263
|
+
].join("");
|
|
3264
|
+
|
|
3257
3265
|
//#endregion
|
|
3258
3266
|
//#region src/rules/no-unstable-default-props/no-unstable-default-props.ts
|
|
3259
3267
|
const RULE_NAME$10 = "no-unstable-default-props";
|
|
@@ -3288,13 +3296,8 @@ function extractIdentifier(node) {
|
|
|
3288
3296
|
function create$10(context, [options]) {
|
|
3289
3297
|
const { compilationMode } = getSettingsFromContext(context);
|
|
3290
3298
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3291
|
-
if (compilationMode === "annotation" && context.sourceCode.ast.body.some(
|
|
3299
|
+
if (compilationMode === "annotation" && context.sourceCode.ast.body.some(Check.isDirective("use memo"))) return {};
|
|
3292
3300
|
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3293
|
-
const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR = [
|
|
3294
|
-
"VariableDeclarator",
|
|
3295
|
-
"[id.type='ObjectPattern']",
|
|
3296
|
-
"[init.type='Identifier']"
|
|
3297
|
-
].join("");
|
|
3298
3301
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3299
3302
|
const { safeDefaultProps = [] } = options;
|
|
3300
3303
|
const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
|
|
@@ -3319,7 +3322,7 @@ function create$10(context, [options]) {
|
|
|
3319
3322
|
if (identifier != null && safePatterns.some((pattern) => pattern.test(identifier))) continue;
|
|
3320
3323
|
}
|
|
3321
3324
|
context.report({
|
|
3322
|
-
data: { kind: Extract.
|
|
3325
|
+
data: { kind: Extract.getHumanReadableKind(right) },
|
|
3323
3326
|
messageId: "default",
|
|
3324
3327
|
node: right
|
|
3325
3328
|
});
|
|
@@ -3390,7 +3393,7 @@ function create$9(context) {
|
|
|
3390
3393
|
const usages = propertyUsages.get(currentClass);
|
|
3391
3394
|
if (defs == null) return;
|
|
3392
3395
|
for (const def of defs) {
|
|
3393
|
-
const methodName = Extract.
|
|
3396
|
+
const methodName = Extract.getPropertyName(def);
|
|
3394
3397
|
if (methodName == null) continue;
|
|
3395
3398
|
if ((usages?.has(methodName) ?? false) || LIFECYCLE_METHODS.has(methodName)) continue;
|
|
3396
3399
|
context.report({
|
|
@@ -3423,12 +3426,12 @@ function create$9(context) {
|
|
|
3423
3426
|
const currentMethod = methodStack.at(-1);
|
|
3424
3427
|
if (currentClass == null || currentMethod == null) return;
|
|
3425
3428
|
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3426
|
-
if (
|
|
3429
|
+
if (node.object.type !== AST_NODE_TYPES.ThisExpression || !isKeyLiteral(node, node.property)) return;
|
|
3427
3430
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
3428
3431
|
propertyDefs.get(currentClass)?.add(node.property);
|
|
3429
3432
|
return;
|
|
3430
3433
|
}
|
|
3431
|
-
const propertyName = Extract.
|
|
3434
|
+
const propertyName = Extract.getPropertyName(node.property);
|
|
3432
3435
|
if (propertyName != null) propertyUsages.get(currentClass)?.add(propertyName);
|
|
3433
3436
|
},
|
|
3434
3437
|
MethodDefinition: methodEnter,
|
|
@@ -3440,9 +3443,9 @@ function create$9(context) {
|
|
|
3440
3443
|
const currentMethod = methodStack.at(-1);
|
|
3441
3444
|
if (currentClass == null || currentMethod == null) return;
|
|
3442
3445
|
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3443
|
-
if (node.init != null &&
|
|
3446
|
+
if (node.init != null && node.init.type === AST_NODE_TYPES.ThisExpression && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
3444
3447
|
for (const prop of node.id.properties) if (prop.type === AST_NODE_TYPES.Property && isKeyLiteral(prop, prop.key)) {
|
|
3445
|
-
const keyName = Extract.
|
|
3448
|
+
const keyName = Extract.getPropertyName(prop.key);
|
|
3446
3449
|
if (keyName != null) propertyUsages.get(currentClass)?.add(keyName);
|
|
3447
3450
|
}
|
|
3448
3451
|
}
|
|
@@ -3910,7 +3913,7 @@ function create$6(context) {
|
|
|
3910
3913
|
const nEntries = [];
|
|
3911
3914
|
return merge(hCollector.visitor, cCollector.visitor, {
|
|
3912
3915
|
CallExpression(node) {
|
|
3913
|
-
const expr = Extract.
|
|
3916
|
+
const expr = Extract.unwrap(node.callee);
|
|
3914
3917
|
switch (true) {
|
|
3915
3918
|
case expr.type === AST_NODE_TYPES.Identifier: {
|
|
3916
3919
|
if (!IMPURE_FUNCS.get("globalThis")?.has(expr.name)) return;
|
|
@@ -3937,7 +3940,7 @@ function create$6(context) {
|
|
|
3937
3940
|
}
|
|
3938
3941
|
},
|
|
3939
3942
|
NewExpression(node) {
|
|
3940
|
-
const expr = Extract.
|
|
3943
|
+
const expr = Extract.unwrap(node.callee);
|
|
3941
3944
|
if (expr.type !== AST_NODE_TYPES.Identifier) return;
|
|
3942
3945
|
if (!IMPURE_CTORS.has(expr.name)) return;
|
|
3943
3946
|
if (expr.name === "Date" && node.arguments.length > 0) return;
|
|
@@ -3998,7 +4001,7 @@ function create$5(context) {
|
|
|
3998
4001
|
type: AST_NODE_TYPES.BinaryExpression,
|
|
3999
4002
|
operator: P.union("===", "==", "!==", "!=")
|
|
4000
4003
|
}, parent)) return false;
|
|
4001
|
-
const otherSide = parent.left === node || Extract.
|
|
4004
|
+
const otherSide = parent.left === node || Extract.unwrap(parent.left) === node ? parent.right : parent.left;
|
|
4002
4005
|
if (otherSide.type !== AST_NODE_TYPES.Literal || otherSide.value != null) return false;
|
|
4003
4006
|
return parent.parent.type === AST_NODE_TYPES.IfStatement && parent.parent.test === parent;
|
|
4004
4007
|
}
|
|
@@ -4014,8 +4017,8 @@ function create$5(context) {
|
|
|
4014
4017
|
if (op !== "===" && op !== "==" && op !== "!==" && op !== "!=") return false;
|
|
4015
4018
|
const { left, right } = test;
|
|
4016
4019
|
const checkSides = (a, b) => {
|
|
4017
|
-
a = Check.isTypeExpression(a) ? Extract.
|
|
4018
|
-
return a.type === AST_NODE_TYPES.MemberExpression && a.object.type === AST_NODE_TYPES.Identifier && a.object.name === refName && b.type === AST_NODE_TYPES.Literal && b.value == null && Extract.
|
|
4020
|
+
a = Check.isTypeExpression(a) ? Extract.unwrap(a) : a;
|
|
4021
|
+
return a.type === AST_NODE_TYPES.MemberExpression && a.object.type === AST_NODE_TYPES.Identifier && a.object.name === refName && b.type === AST_NODE_TYPES.Literal && b.value == null && Extract.getPropertyName(a.property) === "current";
|
|
4019
4022
|
};
|
|
4020
4023
|
return checkSides(left, right) || checkSides(right, left);
|
|
4021
4024
|
}
|
|
@@ -4040,12 +4043,12 @@ function create$5(context) {
|
|
|
4040
4043
|
}
|
|
4041
4044
|
},
|
|
4042
4045
|
MemberExpression(node) {
|
|
4043
|
-
if (!Check.
|
|
4046
|
+
if (!Check.isIdentifier("current")(node.property)) return;
|
|
4044
4047
|
refAccesses.push({
|
|
4045
4048
|
isWrite: (() => {
|
|
4046
4049
|
let parent = node.parent;
|
|
4047
4050
|
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
4048
|
-
return match(parent).with({ type: AST_NODE_TYPES.AssignmentExpression }, (p) => p.left === node || Extract.
|
|
4051
|
+
return match(parent).with({ type: AST_NODE_TYPES.AssignmentExpression }, (p) => p.left === node || Extract.unwrap(p.left) === node).with({ type: AST_NODE_TYPES.UpdateExpression }, (p) => p.argument === node || Extract.unwrap(p.argument) === node).otherwise(() => false);
|
|
4049
4052
|
})(),
|
|
4050
4053
|
node
|
|
4051
4054
|
});
|
|
@@ -6390,8 +6393,8 @@ function create$4(context) {
|
|
|
6390
6393
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectCall(node.parent);
|
|
6391
6394
|
}
|
|
6392
6395
|
function getCallName(node) {
|
|
6393
|
-
if (node.type === AST_NODE_TYPES.CallExpression) return Extract.
|
|
6394
|
-
return Extract.
|
|
6396
|
+
if (node.type === AST_NODE_TYPES.CallExpression) return Extract.getFullyQualifiedName(node.callee, getText);
|
|
6397
|
+
return Extract.getFullyQualifiedName(node, getText);
|
|
6395
6398
|
}
|
|
6396
6399
|
function getCallKind(node) {
|
|
6397
6400
|
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.4-beta.0",
|
|
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",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-api-utils": "^2.5.0",
|
|
48
48
|
"ts-pattern": "^5.9.0",
|
|
49
|
-
"@eslint-react/ast": "5.2.
|
|
50
|
-
"@eslint-react/core": "5.2.
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/ast": "5.2.4-beta.0",
|
|
50
|
+
"@eslint-react/core": "5.2.4-beta.0",
|
|
51
|
+
"@eslint-react/jsx": "5.2.4-beta.0",
|
|
52
|
+
"@eslint-react/shared": "5.2.4-beta.0",
|
|
53
|
+
"@eslint-react/eslint": "5.2.4-beta.0",
|
|
54
|
+
"@eslint-react/var": "5.2.4-beta.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/react": "^19.2.14",
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"eslint": "^10.2.0",
|
|
60
60
|
"tsdown": "^0.21.8",
|
|
61
61
|
"tsl-dx": "^0.10.3",
|
|
62
|
-
"@local/
|
|
63
|
-
"@local/
|
|
62
|
+
"@local/eff": "3.0.0-beta.72",
|
|
63
|
+
"@local/configs": "0.0.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"eslint": "^10.2.0",
|