eslint-plugin-react-x 5.30.0-beta.5 → 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.
- package/dist/index.js +39 -32
- package/package.json +7 -7
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,
|
|
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,
|
|
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.
|
|
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
|
|
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)
|
|
1167
|
-
|
|
1168
|
-
const
|
|
1169
|
-
|
|
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
|
|
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)
|
|
1415
|
-
|
|
1416
|
-
const
|
|
1417
|
-
return
|
|
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
|
|
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
|
|
1753
|
-
if (
|
|
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:
|
|
2721
|
-
|
|
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 =
|
|
3210
|
-
if (selfName
|
|
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(
|
|
3216
|
-
if (attribute?.
|
|
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;
|
|
@@ -3440,7 +3444,7 @@ function collectUsedPropKeysOfParameter(context, usedPropKeys, parameter) {
|
|
|
3440
3444
|
switch (parameter.type) {
|
|
3441
3445
|
case AST_NODE_TYPES.Identifier: return collectUsedPropKeysOfIdentifier(context, usedPropKeys, parameter);
|
|
3442
3446
|
case AST_NODE_TYPES.ObjectPattern: return collectUsedPropKeysOfObjectPattern(context, usedPropKeys, parameter);
|
|
3443
|
-
case AST_NODE_TYPES.AssignmentPattern: return collectUsedPropKeysOfParameter(context, usedPropKeys,
|
|
3447
|
+
case AST_NODE_TYPES.AssignmentPattern: return collectUsedPropKeysOfParameter(context, usedPropKeys, parameter.left);
|
|
3444
3448
|
default: return false;
|
|
3445
3449
|
}
|
|
3446
3450
|
}
|
|
@@ -4021,7 +4025,7 @@ function hasUseClientDirective(program) {
|
|
|
4021
4025
|
function getDestructuredPropertyName(pattern, name) {
|
|
4022
4026
|
for (const property of pattern.properties) {
|
|
4023
4027
|
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
4024
|
-
if (
|
|
4028
|
+
if ((property.value.type === AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value) !== name) continue;
|
|
4025
4029
|
return Extract.getPropertyName(property, "max");
|
|
4026
4030
|
}
|
|
4027
4031
|
return null;
|
|
@@ -6401,7 +6405,7 @@ function isRefLikeName(name) {
|
|
|
6401
6405
|
return name === "ref" || name.endsWith("Ref");
|
|
6402
6406
|
}
|
|
6403
6407
|
function getParameterId(param) {
|
|
6404
|
-
const target =
|
|
6408
|
+
const target = param.type === AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
6405
6409
|
return target.type === AST_NODE_TYPES.Identifier ? target : null;
|
|
6406
6410
|
}
|
|
6407
6411
|
function getRefSourceName(node) {
|
|
@@ -7187,7 +7191,7 @@ function isConfiguredStableHookValue(variable, configs) {
|
|
|
7187
7191
|
if (id.type !== AST_NODE_TYPES.ArrayPattern) return false;
|
|
7188
7192
|
const index = id.elements.findIndex((element) => {
|
|
7189
7193
|
if (element == null) return false;
|
|
7190
|
-
const binding =
|
|
7194
|
+
const binding = element.type === AST_NODE_TYPES.AssignmentPattern ? element.left : element;
|
|
7191
7195
|
return variable.identifiers.some((identifier) => identifier === binding);
|
|
7192
7196
|
});
|
|
7193
7197
|
return index !== -1 && stableResult.has(index);
|
|
@@ -7351,8 +7355,10 @@ const rule = {
|
|
|
7351
7355
|
} else if (name === "useState" || name === "useReducer" || name === "useActionState") {
|
|
7352
7356
|
const isActionState = name === "useActionState";
|
|
7353
7357
|
if (id.type === "ArrayPattern" && (isActionState ? id.elements.length >= 2 : id.elements.length === 2) && isArray(resolved.identifiers)) {
|
|
7354
|
-
const
|
|
7355
|
-
const
|
|
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;
|
|
7356
7362
|
if (resolved.identifiers.some((identifier) => identifier === secondElement)) {
|
|
7357
7363
|
if (name === "useState") {
|
|
7358
7364
|
const references = resolved.references;
|
|
@@ -7372,7 +7378,8 @@ const rule = {
|
|
|
7372
7378
|
}
|
|
7373
7379
|
} else if (name === "useTransition") {
|
|
7374
7380
|
if (id.type === "ArrayPattern" && id.elements.length === 2 && Array.isArray(resolved.identifiers)) {
|
|
7375
|
-
const
|
|
7381
|
+
const secondNode = id.elements[1] ?? null;
|
|
7382
|
+
const secondElement = secondNode?.type === "AssignmentPattern" ? secondNode.left : secondNode;
|
|
7376
7383
|
if (resolved.identifiers.some((identifier) => identifier === secondElement)) return true;
|
|
7377
7384
|
}
|
|
7378
7385
|
}
|
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.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,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.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
45
|
"@typescript-eslint/scope-manager": "^8.72.1",
|
|
46
46
|
"@typescript-eslint/types": "^8.72.1",
|
|
47
47
|
"@typescript-eslint/utils": "^8.72.1",
|