eslint-plugin-react-x 5.28.6 → 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 +20 -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",
|
|
@@ -3754,6 +3753,7 @@ const IMPURE_FUNCS = /* @__PURE__ */ new Map([
|
|
|
3754
3753
|
"clearTimeout",
|
|
3755
3754
|
"close",
|
|
3756
3755
|
"confirm",
|
|
3756
|
+
"Date",
|
|
3757
3757
|
"dispatchEvent",
|
|
3758
3758
|
"fetch",
|
|
3759
3759
|
"focus",
|
|
@@ -3887,6 +3887,7 @@ const IMPURE_FUNCS = /* @__PURE__ */ new Map([
|
|
|
3887
3887
|
"clearTimeout",
|
|
3888
3888
|
"close",
|
|
3889
3889
|
"confirm",
|
|
3890
|
+
"Date",
|
|
3890
3891
|
"dispatchEvent",
|
|
3891
3892
|
"fetch",
|
|
3892
3893
|
"focus",
|
|
@@ -4059,6 +4060,7 @@ function getDestructuredPropertyName(pattern, name) {
|
|
|
4059
4060
|
return null;
|
|
4060
4061
|
}
|
|
4061
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;
|
|
4062
4064
|
const chain = Extract.getMemberChain(node);
|
|
4063
4065
|
const rootId = chain.at(0);
|
|
4064
4066
|
if (rootId == null || !Check.isIdentifier(rootId)) return null;
|
|
@@ -4069,7 +4071,7 @@ function resolveBuiltinMember(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
|
4069
4071
|
let object = resolved.property ?? resolved.object;
|
|
4070
4072
|
const names = segments.map((segment) => segment.name);
|
|
4071
4073
|
if (isCatalogObject(object)) for (const name of names.slice(0, -1)) {
|
|
4072
|
-
if (!isCatalogObject(name))
|
|
4074
|
+
if (!isCatalogObject(name)) return null;
|
|
4073
4075
|
object = name;
|
|
4074
4076
|
}
|
|
4075
4077
|
return {
|
|
@@ -4181,7 +4183,7 @@ function create$7(context) {
|
|
|
4181
4183
|
if (!funcs.some((f) => f.node === func)) continue;
|
|
4182
4184
|
if (!isClientModule && func.async && comps.some((comp) => comp.node === func)) continue;
|
|
4183
4185
|
context.report({
|
|
4184
|
-
data: { name:
|
|
4186
|
+
data: { name: getText(context, node) },
|
|
4185
4187
|
messageId: "default",
|
|
4186
4188
|
node
|
|
4187
4189
|
});
|
|
@@ -6689,7 +6691,6 @@ function getRefSourceName(node) {
|
|
|
6689
6691
|
function inferViolations$2(context, facts) {
|
|
6690
6692
|
const { additionalEffectHooks } = getSettingsFromContext(context);
|
|
6691
6693
|
const resolver = createSetStateResolver$1(context);
|
|
6692
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
6693
6694
|
const isUseEffectCall = (node) => core.isUseEffectLikeCall(node, additionalEffectHooks);
|
|
6694
6695
|
const isUseStateOrThenCall = or(resolver.isUseStateCall, isThenCall);
|
|
6695
6696
|
const setStateCallsByFn = /* @__PURE__ */ new Map();
|
|
@@ -6714,7 +6715,7 @@ function inferViolations$2(context, facts) {
|
|
|
6714
6715
|
if (isArgumentUsingRefValue(context, args0)) continue;
|
|
6715
6716
|
if (isRefGatedContext(context, node)) continue;
|
|
6716
6717
|
violations.push({
|
|
6717
|
-
name: getText(Extract.unwrap(node.callee)),
|
|
6718
|
+
name: getText(context, Extract.unwrap(node.callee)),
|
|
6718
6719
|
node
|
|
6719
6720
|
});
|
|
6720
6721
|
continue;
|
|
@@ -6798,7 +6799,7 @@ function inferViolations$2(context, facts) {
|
|
|
6798
6799
|
for (const setStateCall of getSetStateCalls(unwrappedCallee)) {
|
|
6799
6800
|
if (isExemptSetStateCall(setStateCall, refParams)) continue;
|
|
6800
6801
|
violations.push({
|
|
6801
|
-
name: getCallName(setStateCall, getText),
|
|
6802
|
+
name: getCallName(setStateCall, getText(context)),
|
|
6802
6803
|
node: setStateCall
|
|
6803
6804
|
});
|
|
6804
6805
|
}
|
|
@@ -6806,7 +6807,7 @@ function inferViolations$2(context, facts) {
|
|
|
6806
6807
|
for (const id of facts.setupIdentifiers) for (const setStateCall of getSetStateCalls(id)) {
|
|
6807
6808
|
if (isExemptSetStateCall(setStateCall)) continue;
|
|
6808
6809
|
violations.push({
|
|
6809
|
-
name: getCallName(setStateCall, getText),
|
|
6810
|
+
name: getCallName(setStateCall, getText(context)),
|
|
6810
6811
|
node: setStateCall
|
|
6811
6812
|
});
|
|
6812
6813
|
}
|
|
@@ -6976,7 +6977,6 @@ function createSetStateResolver(context) {
|
|
|
6976
6977
|
//#region src/rules/set-state-in-render/effects.ts
|
|
6977
6978
|
function inferViolations$1(context, facts) {
|
|
6978
6979
|
const resolver = createSetStateResolver(context);
|
|
6979
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
6980
6980
|
const earlyReturnPositions = /* @__PURE__ */ new Map();
|
|
6981
6981
|
for (const { componentFunction, node } of facts.earlyReturns) getOrInsertComputed(earlyReturnPositions, componentFunction, () => []).push(node.range[0]);
|
|
6982
6982
|
const violations = [];
|
|
@@ -6987,7 +6987,7 @@ function inferViolations$1(context, facts) {
|
|
|
6987
6987
|
if (isInsideConditional(node, componentFunction)) continue;
|
|
6988
6988
|
if (earlyReturnPositions.get(componentFunction)?.some((pos) => pos < node.range[0]) === true) continue;
|
|
6989
6989
|
violations.push({
|
|
6990
|
-
name: getText(Extract.unwrap(node.callee)),
|
|
6990
|
+
name: getText(context, Extract.unwrap(node.callee)),
|
|
6991
6991
|
node
|
|
6992
6992
|
});
|
|
6993
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",
|