eslint-plugin-react-x 5.28.7 → 5.28.8
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 +18 -20
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { DEFAULT_ESLINT_REACT_SETTINGS, getSettingsFromContext, toRegExp } from
|
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
3
|
import { Check, Compare, Extract, Traverse } from "@eslint-react/ast";
|
|
4
4
|
import * as core from "@eslint-react/core";
|
|
5
|
-
import { getConstrainedTypeAtLocation, merge, report } from "@eslint-react/eslint";
|
|
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
8
|
import { isAssignmentTargetEqual, isInitializedFromReact, resolveEnclosingAssignmentTarget, resolveObjectType, resolveOrigin } from "@eslint-react/var";
|
|
@@ -135,7 +135,7 @@ const rules$6 = {
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region package.json
|
|
137
137
|
var name$6 = "eslint-plugin-react-x";
|
|
138
|
-
var version = "5.28.
|
|
138
|
+
var version = "5.28.8";
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/utils/create-rule.ts
|
|
141
141
|
function getDocsUrl(ruleName) {
|
|
@@ -1202,7 +1202,7 @@ function inferGlobalMutations(context, facts) {
|
|
|
1202
1202
|
if (resolveGlobalOrigin(context, write.target.object) == null) continue;
|
|
1203
1203
|
pushEffect(write.enclosingFunction, {
|
|
1204
1204
|
kind: "property",
|
|
1205
|
-
name:
|
|
1205
|
+
name: getText(context, write.target),
|
|
1206
1206
|
method: null,
|
|
1207
1207
|
node: write.node
|
|
1208
1208
|
});
|
|
@@ -2403,18 +2403,17 @@ function buildFix(context, node) {
|
|
|
2403
2403
|
};
|
|
2404
2404
|
}
|
|
2405
2405
|
function buildFixForComponentProps(context, fixer, node, typeArguments) {
|
|
2406
|
-
const getText = (node) => context.sourceCode.getText(node);
|
|
2407
2406
|
const [arg0, arg1] = node.params;
|
|
2408
2407
|
const [typeArg0, typeArg1] = typeArguments;
|
|
2409
2408
|
if (arg0 == null) {
|
|
2410
2409
|
const openParen = context.sourceCode.getFirstToken(node, { filter: (t) => t.value === "(" });
|
|
2411
2410
|
if (openParen == null) return [];
|
|
2412
2411
|
if (typeArg0 == null || typeArg1 == null) return [];
|
|
2413
|
-
const typeArg0Text = getText(typeArg0);
|
|
2414
|
-
const typeArg1Text = getText(typeArg1);
|
|
2412
|
+
const typeArg0Text = getText(context, typeArg0);
|
|
2413
|
+
const typeArg1Text = getText(context, typeArg1);
|
|
2415
2414
|
return [fixer.insertTextAfter(openParen, `{ ref }: ${typeArg1Text} & { ref?: React.RefObject<${typeArg0Text} | null> }`)];
|
|
2416
2415
|
}
|
|
2417
|
-
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => null);
|
|
2416
|
+
const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText(context)).join(", ")).otherwise(() => null);
|
|
2418
2417
|
const fixedArg1Text = match(arg1).with(P.nullish, () => "ref").with({
|
|
2419
2418
|
type: AST_NODE_TYPES.Identifier,
|
|
2420
2419
|
name: "ref"
|
|
@@ -2429,8 +2428,8 @@ function buildFixForComponentProps(context, fixer, node, typeArguments) {
|
|
|
2429
2428
|
fixedArg0Text,
|
|
2430
2429
|
"}"
|
|
2431
2430
|
].join(" ")), ...arg1 == null ? [] : [fixer.remove(arg1), fixer.removeRange([arg0.range[1], arg1.range[0]])]];
|
|
2432
|
-
const typeArg0Text = getText(typeArg0);
|
|
2433
|
-
const typeArg1Text = getText(typeArg1);
|
|
2431
|
+
const typeArg0Text = getText(context, typeArg0);
|
|
2432
|
+
const typeArg1Text = getText(context, typeArg1);
|
|
2434
2433
|
return [fixer.replaceText(arg0, [
|
|
2435
2434
|
"{",
|
|
2436
2435
|
fixedArg1Text + ",",
|
|
@@ -2579,7 +2578,7 @@ function create$27(context) {
|
|
|
2579
2578
|
if (left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!") return visit(right, seen);
|
|
2580
2579
|
const initialScope = context.sourceCode.getScope(left);
|
|
2581
2580
|
if (Check.isIdentifier(left, "NaN") || getStaticValue(left, initialScope)?.value === "NaN") return {
|
|
2582
|
-
data: { value:
|
|
2581
|
+
data: { value: getText(context, left) },
|
|
2583
2582
|
messageId: "default",
|
|
2584
2583
|
node: left
|
|
2585
2584
|
};
|
|
@@ -2587,7 +2586,7 @@ function create$27(context) {
|
|
|
2587
2586
|
const leftTypeVariants = core.getTypeVariants(unionConstituents(leftType));
|
|
2588
2587
|
if (Array.from(leftTypeVariants.values()).every((t) => allowedTypeVariants.some((a) => a === t))) return visit(right, seen);
|
|
2589
2588
|
return {
|
|
2590
|
-
data: { value:
|
|
2589
|
+
data: { value: getText(context, left) },
|
|
2591
2590
|
messageId: "default",
|
|
2592
2591
|
node: left
|
|
2593
2592
|
};
|
|
@@ -3425,7 +3424,7 @@ function create$11(context) {
|
|
|
3425
3424
|
if (exported && isPublicMethod(def)) continue;
|
|
3426
3425
|
context.report({
|
|
3427
3426
|
data: {
|
|
3428
|
-
className: id != null ?
|
|
3427
|
+
className: id != null ? getText(context, id) : "Component",
|
|
3429
3428
|
methodName
|
|
3430
3429
|
},
|
|
3431
3430
|
messageId: "default",
|
|
@@ -4061,6 +4060,7 @@ function getDestructuredPropertyName(pattern, name) {
|
|
|
4061
4060
|
return null;
|
|
4062
4061
|
}
|
|
4063
4062
|
function resolveBuiltinMember(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
4063
|
+
for (let current = node; current.type === AST_NODE_TYPES.MemberExpression; current = Extract.unwrap(current.object)) if (current.computed) return null;
|
|
4064
4064
|
const chain = Extract.getMemberChain(node);
|
|
4065
4065
|
const rootId = chain.at(0);
|
|
4066
4066
|
if (rootId == null || !Check.isIdentifier(rootId)) return null;
|
|
@@ -4071,7 +4071,7 @@ function resolveBuiltinMember(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
|
4071
4071
|
let object = resolved.property ?? resolved.object;
|
|
4072
4072
|
const names = segments.map((segment) => segment.name);
|
|
4073
4073
|
if (isCatalogObject(object)) for (const name of names.slice(0, -1)) {
|
|
4074
|
-
if (!isCatalogObject(name))
|
|
4074
|
+
if (!isCatalogObject(name)) return null;
|
|
4075
4075
|
object = name;
|
|
4076
4076
|
}
|
|
4077
4077
|
return {
|
|
@@ -4183,7 +4183,7 @@ function create$7(context) {
|
|
|
4183
4183
|
if (!funcs.some((f) => f.node === func)) continue;
|
|
4184
4184
|
if (!isClientModule && func.async && comps.some((comp) => comp.node === func)) continue;
|
|
4185
4185
|
context.report({
|
|
4186
|
-
data: { name:
|
|
4186
|
+
data: { name: getText(context, node) },
|
|
4187
4187
|
messageId: "default",
|
|
4188
4188
|
node
|
|
4189
4189
|
});
|
|
@@ -6691,7 +6691,6 @@ function getRefSourceName(node) {
|
|
|
6691
6691
|
function inferViolations$2(context, facts) {
|
|
6692
6692
|
const { additionalEffectHooks } = getSettingsFromContext(context);
|
|
6693
6693
|
const resolver = createSetStateResolver$1(context);
|
|
6694
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
6695
6694
|
const isUseEffectCall = (node) => core.isUseEffectLikeCall(node, additionalEffectHooks);
|
|
6696
6695
|
const isUseStateOrThenCall = or(resolver.isUseStateCall, isThenCall);
|
|
6697
6696
|
const setStateCallsByFn = /* @__PURE__ */ new Map();
|
|
@@ -6716,7 +6715,7 @@ function inferViolations$2(context, facts) {
|
|
|
6716
6715
|
if (isArgumentUsingRefValue(context, args0)) continue;
|
|
6717
6716
|
if (isRefGatedContext(context, node)) continue;
|
|
6718
6717
|
violations.push({
|
|
6719
|
-
name: getText(Extract.unwrap(node.callee)),
|
|
6718
|
+
name: getText(context, Extract.unwrap(node.callee)),
|
|
6720
6719
|
node
|
|
6721
6720
|
});
|
|
6722
6721
|
continue;
|
|
@@ -6800,7 +6799,7 @@ function inferViolations$2(context, facts) {
|
|
|
6800
6799
|
for (const setStateCall of getSetStateCalls(unwrappedCallee)) {
|
|
6801
6800
|
if (isExemptSetStateCall(setStateCall, refParams)) continue;
|
|
6802
6801
|
violations.push({
|
|
6803
|
-
name: getCallName(setStateCall, getText),
|
|
6802
|
+
name: getCallName(setStateCall, getText(context)),
|
|
6804
6803
|
node: setStateCall
|
|
6805
6804
|
});
|
|
6806
6805
|
}
|
|
@@ -6808,7 +6807,7 @@ function inferViolations$2(context, facts) {
|
|
|
6808
6807
|
for (const id of facts.setupIdentifiers) for (const setStateCall of getSetStateCalls(id)) {
|
|
6809
6808
|
if (isExemptSetStateCall(setStateCall)) continue;
|
|
6810
6809
|
violations.push({
|
|
6811
|
-
name: getCallName(setStateCall, getText),
|
|
6810
|
+
name: getCallName(setStateCall, getText(context)),
|
|
6812
6811
|
node: setStateCall
|
|
6813
6812
|
});
|
|
6814
6813
|
}
|
|
@@ -6978,7 +6977,6 @@ function createSetStateResolver(context) {
|
|
|
6978
6977
|
//#region src/rules/set-state-in-render/effects.ts
|
|
6979
6978
|
function inferViolations$1(context, facts) {
|
|
6980
6979
|
const resolver = createSetStateResolver(context);
|
|
6981
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
6982
6980
|
const earlyReturnPositions = /* @__PURE__ */ new Map();
|
|
6983
6981
|
for (const { componentFunction, node } of facts.earlyReturns) getOrInsertComputed(earlyReturnPositions, componentFunction, () => []).push(node.range[0]);
|
|
6984
6982
|
const violations = [];
|
|
@@ -6989,7 +6987,7 @@ function inferViolations$1(context, facts) {
|
|
|
6989
6987
|
if (isInsideConditional(node, componentFunction)) continue;
|
|
6990
6988
|
if (earlyReturnPositions.get(componentFunction)?.some((pos) => pos < node.range[0]) === true) continue;
|
|
6991
6989
|
violations.push({
|
|
6992
|
-
name: getText(Extract.unwrap(node.callee)),
|
|
6990
|
+
name: getText(context, Extract.unwrap(node.callee)),
|
|
6993
6991
|
node
|
|
6994
6992
|
});
|
|
6995
6993
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.28.
|
|
3
|
+
"version": "5.28.8",
|
|
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.28.
|
|
40
|
-
"@eslint-react/core": "5.28.
|
|
41
|
-
"@eslint-react/eslint": "5.28.
|
|
42
|
-
"@eslint-react/jsx": "5.28.
|
|
43
|
-
"@eslint-react/shared": "5.28.
|
|
44
|
-
"@eslint-react/var": "5.28.
|
|
39
|
+
"@eslint-react/ast": "5.28.8",
|
|
40
|
+
"@eslint-react/core": "5.28.8",
|
|
41
|
+
"@eslint-react/eslint": "5.28.8",
|
|
42
|
+
"@eslint-react/jsx": "5.28.8",
|
|
43
|
+
"@eslint-react/shared": "5.28.8",
|
|
44
|
+
"@eslint-react/var": "5.28.8",
|
|
45
45
|
"@typescript-eslint/scope-manager": "^8.72.0",
|
|
46
46
|
"@typescript-eslint/types": "^8.72.0",
|
|
47
47
|
"@typescript-eslint/typescript-estree": "^8.72.0",
|