eslint-plugin-react-x 5.24.6 → 5.24.7
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 -19
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -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.24.
|
|
138
|
+
var version = "5.24.7";
|
|
139
139
|
//#endregion
|
|
140
140
|
//#region src/utils/create-rule.ts
|
|
141
141
|
function getDocsUrl(ruleName) {
|
|
@@ -1335,15 +1335,16 @@ function resolveToFunctionNode(context, node, seen = /* @__PURE__ */ new Set())
|
|
|
1335
1335
|
const resolved = resolveOrigin(context, expr);
|
|
1336
1336
|
return resolved == null ? null : resolveToFunctionNode(context, resolved, seen);
|
|
1337
1337
|
}
|
|
1338
|
-
function resolveVariableOrigin(context, variable, seen = /* @__PURE__ */ new Set()) {
|
|
1338
|
+
function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__PURE__ */ new Set()) {
|
|
1339
1339
|
if (seen.has(variable)) return variable;
|
|
1340
1340
|
seen.add(variable);
|
|
1341
1341
|
const def = variable.defs.length === 1 ? variable.defs[0] : null;
|
|
1342
1342
|
if (def?.type !== DefinitionType.Variable || def.node.init == null) return variable;
|
|
1343
|
+
if (mode === "binding" && def.node.id.type === AST_NODE_TYPES.Identifier) return variable;
|
|
1343
1344
|
const init = Extract.unwrap(def.node.init);
|
|
1344
1345
|
if (!Check.isIdentifier(init)) return variable;
|
|
1345
1346
|
const source = findVariable(context.sourceCode.getScope(init), init);
|
|
1346
|
-
return source == null ? variable : resolveVariableOrigin(context, source, seen);
|
|
1347
|
+
return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
|
|
1347
1348
|
}
|
|
1348
1349
|
function isRefLikeName$1(name) {
|
|
1349
1350
|
return name === "ref" || name.endsWith("Ref");
|
|
@@ -1467,10 +1468,10 @@ function createFactCollector$5() {
|
|
|
1467
1468
|
}
|
|
1468
1469
|
//#endregion
|
|
1469
1470
|
//#region src/rules/immutability/origins.ts
|
|
1470
|
-
function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__ */ new Set()) {
|
|
1471
|
+
function classifyFrozenOrigin(context, variable, components, mode = "alias", seen = /* @__PURE__ */ new Set()) {
|
|
1471
1472
|
if (seen.has(variable)) return null;
|
|
1472
1473
|
seen.add(variable);
|
|
1473
|
-
const origin = resolveVariableOrigin(context, variable);
|
|
1474
|
+
const origin = resolveVariableOrigin(context, variable, mode);
|
|
1474
1475
|
const def = origin.defs.length === 1 ? origin.defs[0] : null;
|
|
1475
1476
|
if (def == null) return null;
|
|
1476
1477
|
if (isComponentPropsDefinition(def, components)) return {
|
|
@@ -1485,7 +1486,7 @@ function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__
|
|
|
1485
1486
|
if (root == null || !Check.isIdentifier(root)) return null;
|
|
1486
1487
|
const source = findVariable(context.sourceCode.getScope(root), root);
|
|
1487
1488
|
if (source == null) return null;
|
|
1488
|
-
const inner = classifyFrozenOrigin(context, source, components, seen);
|
|
1489
|
+
const inner = classifyFrozenOrigin(context, source, components, mode, seen);
|
|
1489
1490
|
return inner == null ? null : {
|
|
1490
1491
|
kind: "iterator",
|
|
1491
1492
|
name: origin.name,
|
|
@@ -1515,7 +1516,7 @@ function classifyFrozenOrigin(context, variable, components, seen = /* @__PURE__
|
|
|
1515
1516
|
if (!Check.isIdentifier(argument)) continue;
|
|
1516
1517
|
const source = findVariable(context.sourceCode.getScope(argument), argument);
|
|
1517
1518
|
if (source == null) continue;
|
|
1518
|
-
const inner = classifyFrozenOrigin(context, source, components, seen);
|
|
1519
|
+
const inner = classifyFrozenOrigin(context, source, components, mode, seen);
|
|
1519
1520
|
if (inner != null) return {
|
|
1520
1521
|
kind: "shallow-copy",
|
|
1521
1522
|
name: origin.name,
|
|
@@ -1570,7 +1571,7 @@ function inferDirectMutations(context, mutations, components) {
|
|
|
1570
1571
|
if (isRefMutation(context, mutation)) continue;
|
|
1571
1572
|
const variable = findVariable(context.sourceCode.getScope(mutation.root), mutation.root);
|
|
1572
1573
|
if (variable == null) continue;
|
|
1573
|
-
const origin = classifyFrozenOrigin(context, variable, components);
|
|
1574
|
+
const origin = classifyFrozenOrigin(context, variable, components, mutation.kind === "binding" ? "binding" : "alias");
|
|
1574
1575
|
if (origin == null) continue;
|
|
1575
1576
|
if (mutation.kind === "binding") {
|
|
1576
1577
|
switch (origin.kind) {
|
|
@@ -6765,9 +6766,9 @@ function create$5(context) {
|
|
|
6765
6766
|
//#endregion
|
|
6766
6767
|
//#region src/rules/set-state-in-render/helpers.ts
|
|
6767
6768
|
const isComponentOrHookName = or(core.isFunctionComponentName, core.isHookName);
|
|
6768
|
-
function isComponentOrHookLikeFunction(node) {
|
|
6769
|
+
function isComponentOrHookLikeFunction(context, node) {
|
|
6769
6770
|
const id = core.getFunctionId(node);
|
|
6770
|
-
if (id == null) return
|
|
6771
|
+
if (id == null) return core.isFunctionComponentWrapperCallback(context, node);
|
|
6771
6772
|
if (Check.isIdentifier(id)) return isComponentOrHookName(id.name);
|
|
6772
6773
|
if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isComponentOrHookName(id.property.name);
|
|
6773
6774
|
return false;
|
|
@@ -6788,18 +6789,19 @@ function isInsideConditional(node, stopAt) {
|
|
|
6788
6789
|
}
|
|
6789
6790
|
//#endregion
|
|
6790
6791
|
//#region src/rules/set-state-in-render/collect.ts
|
|
6791
|
-
function createFactCollector$2(
|
|
6792
|
+
function createFactCollector$2(context) {
|
|
6793
|
+
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
6792
6794
|
const facts = {
|
|
6793
6795
|
calls: [],
|
|
6794
6796
|
earlyReturns: []
|
|
6795
6797
|
};
|
|
6796
6798
|
const functionEntries = [];
|
|
6797
|
-
const
|
|
6799
|
+
const componentFnStack = [];
|
|
6798
6800
|
function isUseStateCall(node) {
|
|
6799
6801
|
return core.isUseStateLikeCall(node, additionalStateHooks);
|
|
6800
6802
|
}
|
|
6801
6803
|
function getFunctionKind(node) {
|
|
6802
|
-
if (isComponentOrHookLikeFunction(node)) return "component";
|
|
6804
|
+
if (isComponentOrHookLikeFunction(context, node)) return "component";
|
|
6803
6805
|
const parent = Traverse.findParent(node, not(Check.isTypeExpression)) ?? node.parent;
|
|
6804
6806
|
if (parent.type === AST_NODE_TYPES.CallExpression && parent.callee !== node) return "callback";
|
|
6805
6807
|
return "other";
|
|
@@ -6813,10 +6815,10 @@ function createFactCollector$2(additionalStateHooks) {
|
|
|
6813
6815
|
kind,
|
|
6814
6816
|
node
|
|
6815
6817
|
});
|
|
6816
|
-
if (kind === "component")
|
|
6818
|
+
if (kind === "component") componentFnStack.push(node);
|
|
6817
6819
|
},
|
|
6818
6820
|
":function:exit"(node) {
|
|
6819
|
-
if (functionEntries.at(-1)?.kind === "component" &&
|
|
6821
|
+
if (functionEntries.at(-1)?.kind === "component" && componentFnStack.at(-1) === node) componentFnStack.pop();
|
|
6820
6822
|
functionEntries.pop();
|
|
6821
6823
|
},
|
|
6822
6824
|
CallExpression(node) {
|
|
@@ -6824,14 +6826,14 @@ function createFactCollector$2(additionalStateHooks) {
|
|
|
6824
6826
|
if (entry == null) return;
|
|
6825
6827
|
if (isUseStateCall(node)) return;
|
|
6826
6828
|
facts.calls.push({
|
|
6827
|
-
componentFunction:
|
|
6829
|
+
componentFunction: componentFnStack.at(-1) ?? null,
|
|
6828
6830
|
enclosingFunction: entry.node,
|
|
6829
6831
|
enclosingFunctionKind: entry.kind,
|
|
6830
6832
|
node
|
|
6831
6833
|
});
|
|
6832
6834
|
},
|
|
6833
6835
|
ReturnStatement(node) {
|
|
6834
|
-
const componentFn =
|
|
6836
|
+
const componentFn = componentFnStack.at(-1);
|
|
6835
6837
|
if (componentFn == null) return;
|
|
6836
6838
|
const entry = functionEntries.at(-1);
|
|
6837
6839
|
if (entry == null || entry.node !== componentFn) return;
|
|
@@ -6930,8 +6932,7 @@ var set_state_in_render_default = createRule({
|
|
|
6930
6932
|
create: create$4
|
|
6931
6933
|
});
|
|
6932
6934
|
function create$4(context) {
|
|
6933
|
-
const
|
|
6934
|
-
const facts = createFactCollector$2(additionalStateHooks);
|
|
6935
|
+
const facts = createFactCollector$2(context);
|
|
6935
6936
|
return merge(facts.visitor, { "Program:exit"() {
|
|
6936
6937
|
for (const violation of inferViolations$1(context, facts.facts)) context.report({
|
|
6937
6938
|
data: { name: violation.name },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.7",
|
|
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,16 +36,16 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@eslint-react/ast": "5.24.
|
|
40
|
-
"@eslint-react/core": "5.24.
|
|
41
|
-
"@eslint-react/eslint": "5.24.
|
|
42
|
-
"@eslint-react/jsx": "5.24.
|
|
43
|
-
"@eslint-react/shared": "5.24.
|
|
44
|
-
"@eslint-react/var": "5.24.
|
|
45
|
-
"@typescript-eslint/scope-manager": "^8.71.
|
|
46
|
-
"@typescript-eslint/types": "^8.71.
|
|
47
|
-
"@typescript-eslint/typescript-estree": "^8.71.
|
|
48
|
-
"@typescript-eslint/utils": "^8.71.
|
|
39
|
+
"@eslint-react/ast": "5.24.7",
|
|
40
|
+
"@eslint-react/core": "5.24.7",
|
|
41
|
+
"@eslint-react/eslint": "5.24.7",
|
|
42
|
+
"@eslint-react/jsx": "5.24.7",
|
|
43
|
+
"@eslint-react/shared": "5.24.7",
|
|
44
|
+
"@eslint-react/var": "5.24.7",
|
|
45
|
+
"@typescript-eslint/scope-manager": "^8.71.1",
|
|
46
|
+
"@typescript-eslint/types": "^8.71.1",
|
|
47
|
+
"@typescript-eslint/typescript-estree": "^8.71.1",
|
|
48
|
+
"@typescript-eslint/utils": "^8.71.1",
|
|
49
49
|
"compare-versions": "^6.1.1",
|
|
50
50
|
"string-ts": "^2.3.1",
|
|
51
51
|
"ts-api-utils": "^2.5.0",
|