eslint-plugin-react-x 5.30.0-beta.2 → 5.30.0-beta.20
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 +336 -221
- package/package.json +14 -14
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS, getSettingsFromContext, toRegExp } from "@eslint-react/shared";
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
|
-
import { Check, Collect, Compare, Extract, Traverse } from "@eslint-react/ast";
|
|
3
|
+
import { Analyze, Check, Collect, Compare, Extract, Traverse } from "@eslint-react/ast";
|
|
4
4
|
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, resolveEnclosingAssignmentTarget, resolveObjectType, resolveOrigin } from "@eslint-react/var";
|
|
8
|
+
import { isAssignmentTargetEqual, isInitializedFromReact, resolveAssignmentTargets, 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";
|
|
@@ -129,7 +129,7 @@ const rules$6 = {
|
|
|
129
129
|
};
|
|
130
130
|
// package.json
|
|
131
131
|
var name$6 = "eslint-plugin-react-x";
|
|
132
|
-
var version = "5.30.0-beta.
|
|
132
|
+
var version = "5.30.0-beta.20";
|
|
133
133
|
// src/utils/create-rule.ts
|
|
134
134
|
function getDocsUrl(ruleName) {
|
|
135
135
|
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
@@ -1095,7 +1095,7 @@ function createFactCollector$6() {
|
|
|
1095
1095
|
facts,
|
|
1096
1096
|
visitor: {
|
|
1097
1097
|
AssignmentExpression(node) {
|
|
1098
|
-
for (const target of
|
|
1098
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1099
1099
|
},
|
|
1100
1100
|
CallExpression(node) {
|
|
1101
1101
|
const caller = getEnclosingFunction(node);
|
|
@@ -1117,11 +1117,11 @@ function createFactCollector$6() {
|
|
|
1117
1117
|
},
|
|
1118
1118
|
ForInStatement(node) {
|
|
1119
1119
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1120
|
-
for (const target of
|
|
1120
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1121
1121
|
},
|
|
1122
1122
|
ForOfStatement(node) {
|
|
1123
1123
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1124
|
-
for (const target of
|
|
1124
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
1125
1125
|
},
|
|
1126
1126
|
UnaryExpression(node) {
|
|
1127
1127
|
if (node.operator !== "delete") return;
|
|
@@ -1159,14 +1159,13 @@ function resolveGlobalOrigin(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
|
1159
1159
|
if (initializer.type !== AST_NODE_TYPES.Identifier && initializer.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
1160
1160
|
return resolveGlobalOrigin(context, initializer, seen);
|
|
1161
1161
|
}
|
|
1162
|
-
function resolveToFunction(context, node
|
|
1162
|
+
function resolveToFunction(context, node) {
|
|
1163
1163
|
const expression = Extract.unwrap(node);
|
|
1164
1164
|
if (Check.isFunction(expression)) return expression;
|
|
1165
|
-
if (!Check.isIdentifier(expression)
|
|
1166
|
-
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
return resolveToFunction(context, resolved, seen);
|
|
1165
|
+
if (!Check.isIdentifier(expression)) return null;
|
|
1166
|
+
const origin = resolveOriginChain(context, expression);
|
|
1167
|
+
const unwrapped = origin == null ? null : Extract.unwrap(origin);
|
|
1168
|
+
return unwrapped != null && Check.isFunction(unwrapped) ? unwrapped : null;
|
|
1170
1169
|
}
|
|
1171
1170
|
// src/rules/globals/effects.ts
|
|
1172
1171
|
function inferGlobalMutations(context, facts) {
|
|
@@ -1254,10 +1253,10 @@ function create$49(context) {
|
|
|
1254
1253
|
const comps = core.getFunctionComponentCollector(context);
|
|
1255
1254
|
const facts = createFactCollector$6();
|
|
1256
1255
|
return merge(hooks.visitor, comps.visitor, facts.visitor, { "Program:exit"(program) {
|
|
1257
|
-
const
|
|
1256
|
+
const funcs = [...comps.api.getAllComponents(program), ...hooks.api.getAllHooks(program)].map(({ node }) => node);
|
|
1258
1257
|
const directEffects = inferGlobalMutations(context, facts.facts);
|
|
1259
1258
|
const callGraph = inferCallGraph$1(context, facts.facts.callEdges);
|
|
1260
|
-
for (const effect of collectReachableEffects(
|
|
1259
|
+
for (const effect of collectReachableEffects(funcs, directEffects, callGraph)) {
|
|
1261
1260
|
const data = effect.method == null ? { name: effect.name } : {
|
|
1262
1261
|
name: effect.name,
|
|
1263
1262
|
method: effect.method
|
|
@@ -1304,9 +1303,13 @@ function isRefLikeName$2(name) {
|
|
|
1304
1303
|
return name === "ref" || name.endsWith("Ref");
|
|
1305
1304
|
}
|
|
1306
1305
|
function hasRefLikeNameInChain(node) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1306
|
+
let current = Extract.unwrap(node);
|
|
1307
|
+
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
1308
|
+
const property = Extract.unwrap(current.property);
|
|
1309
|
+
if (Check.isIdentifier(property) && isRefLikeName$2(property.name)) return true;
|
|
1310
|
+
current = Extract.unwrap(current.object);
|
|
1311
|
+
}
|
|
1312
|
+
return Check.isIdentifier(current) && isRefLikeName$2(current.name);
|
|
1310
1313
|
}
|
|
1311
1314
|
// src/rules/immutability/collect.ts
|
|
1312
1315
|
function createFactCollector$5() {
|
|
@@ -1326,8 +1329,9 @@ function createFactCollector$5() {
|
|
|
1326
1329
|
});
|
|
1327
1330
|
}
|
|
1328
1331
|
function pushMemberMutation(node, target) {
|
|
1329
|
-
|
|
1330
|
-
|
|
1332
|
+
let root = Extract.unwrap(target);
|
|
1333
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1334
|
+
if (!Check.isIdentifier(root)) return;
|
|
1331
1335
|
pushMutation("value", node, target, root);
|
|
1332
1336
|
}
|
|
1333
1337
|
function pushTargetMutation(node, target) {
|
|
@@ -1341,7 +1345,7 @@ function createFactCollector$5() {
|
|
|
1341
1345
|
facts,
|
|
1342
1346
|
visitor: {
|
|
1343
1347
|
AssignmentExpression(node) {
|
|
1344
|
-
for (const target of
|
|
1348
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1345
1349
|
},
|
|
1346
1350
|
CallExpression(node) {
|
|
1347
1351
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -1360,11 +1364,11 @@ function createFactCollector$5() {
|
|
|
1360
1364
|
},
|
|
1361
1365
|
ForInStatement(node) {
|
|
1362
1366
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1363
|
-
for (const target of
|
|
1367
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1364
1368
|
},
|
|
1365
1369
|
ForOfStatement(node) {
|
|
1366
1370
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
1367
|
-
for (const target of
|
|
1371
|
+
for (const target of resolveAssignmentTargets(node.left)) pushTargetMutation(node, target);
|
|
1368
1372
|
},
|
|
1369
1373
|
JSXAttribute(node) {
|
|
1370
1374
|
if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
@@ -1407,13 +1411,13 @@ function resolveVariableOrigin(context, variable, mode = "alias", seen = /* @__P
|
|
|
1407
1411
|
const source = findVariable(context.sourceCode.getScope(init), init);
|
|
1408
1412
|
return source == null ? variable : resolveVariableOrigin(context, source, mode, seen);
|
|
1409
1413
|
}
|
|
1410
|
-
function resolveToFunctionNode(context, node
|
|
1414
|
+
function resolveToFunctionNode(context, node) {
|
|
1411
1415
|
const expr = Extract.unwrap(node);
|
|
1412
1416
|
if (Check.isFunction(expr)) return expr;
|
|
1413
|
-
if (!Check.isIdentifier(expr)
|
|
1414
|
-
|
|
1415
|
-
const
|
|
1416
|
-
return
|
|
1417
|
+
if (!Check.isIdentifier(expr)) return null;
|
|
1418
|
+
const origin = resolveOriginChain(context, expr);
|
|
1419
|
+
const unwrapped = origin == null ? null : Extract.unwrap(origin);
|
|
1420
|
+
return unwrapped != null && Check.isFunction(unwrapped) ? unwrapped : null;
|
|
1417
1421
|
}
|
|
1418
1422
|
function isComponentPropsDefinition(def, components) {
|
|
1419
1423
|
if (def.type !== DefinitionType.Parameter) return false;
|
|
@@ -1430,8 +1434,9 @@ function getStateHookName(context, init) {
|
|
|
1430
1434
|
return null;
|
|
1431
1435
|
}
|
|
1432
1436
|
function isInitializedFromCall(context, node, isCall) {
|
|
1433
|
-
|
|
1434
|
-
|
|
1437
|
+
let root = Extract.unwrap(node);
|
|
1438
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1439
|
+
if (!Check.isIdentifier(root)) return false;
|
|
1435
1440
|
const variable = findVariable(context.sourceCode.getScope(root), root);
|
|
1436
1441
|
if (variable == null) return false;
|
|
1437
1442
|
const origin = resolveVariableOrigin(context, variable);
|
|
@@ -1461,8 +1466,9 @@ function classifyFrozenOrigin(context, variable, components, mode = "alias", see
|
|
|
1461
1466
|
if (def.node.init == null) {
|
|
1462
1467
|
const loop = def.node.parent.parent;
|
|
1463
1468
|
if (loop.type !== AST_NODE_TYPES.ForOfStatement || loop.left !== def.node.parent) return null;
|
|
1464
|
-
|
|
1465
|
-
|
|
1469
|
+
let root = Extract.unwrap(loop.right);
|
|
1470
|
+
while (root.type === AST_NODE_TYPES.MemberExpression) root = Extract.unwrap(root.object);
|
|
1471
|
+
if (!Check.isIdentifier(root)) return null;
|
|
1466
1472
|
const source = findVariable(context.sourceCode.getScope(root), root);
|
|
1467
1473
|
if (source == null) return null;
|
|
1468
1474
|
const inner = classifyFrozenOrigin(context, source, components, mode, seen);
|
|
@@ -1726,7 +1732,7 @@ function isArrayIndexReference(context, node) {
|
|
|
1726
1732
|
if (call.arguments[callbackPosition] !== argument) return false;
|
|
1727
1733
|
const param = callback.params[indexPosition];
|
|
1728
1734
|
if (param == null) return false;
|
|
1729
|
-
return param
|
|
1735
|
+
return (param.type === AST_NODE_TYPES.AssignmentPattern ? param.left : param) === def.name;
|
|
1730
1736
|
}
|
|
1731
1737
|
function getIdentifiersFromBinaryExpression(side) {
|
|
1732
1738
|
if (Check.isIdentifier(side)) return [side];
|
|
@@ -1748,9 +1754,10 @@ function create$46(context) {
|
|
|
1748
1754
|
return node != null && Check.isIdentifier(node) && isArrayIndexReference(context, node);
|
|
1749
1755
|
}
|
|
1750
1756
|
function getPropsObject(node) {
|
|
1751
|
-
const
|
|
1752
|
-
if (
|
|
1757
|
+
const call = parseCreateElementCall(context, node);
|
|
1758
|
+
if (call != null) return call.propsObject;
|
|
1753
1759
|
if (!core.isCloneElementCall(context, node)) return null;
|
|
1760
|
+
const props = node.arguments[1];
|
|
1754
1761
|
return props?.type === AST_NODE_TYPES.ObjectExpression ? props : null;
|
|
1755
1762
|
}
|
|
1756
1763
|
function visitKeyExpression(node) {
|
|
@@ -1792,7 +1799,8 @@ function create$46(context) {
|
|
|
1792
1799
|
for (const property of propsObject.properties) {
|
|
1793
1800
|
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
1794
1801
|
if (property.computed) continue;
|
|
1795
|
-
|
|
1802
|
+
const key = Extract.unwrap(property.key);
|
|
1803
|
+
if (Check.isIdentifier(key) ? key.name !== "key" : key.value !== "key") continue;
|
|
1796
1804
|
const value = property.value;
|
|
1797
1805
|
for (const desc of visitKeyExpression(value)) context.report(desc);
|
|
1798
1806
|
}
|
|
@@ -1814,6 +1822,7 @@ var no_children_count_default = createRule({
|
|
|
1814
1822
|
create: create$45
|
|
1815
1823
|
});
|
|
1816
1824
|
function create$45(context) {
|
|
1825
|
+
if (!context.sourceCode.text.includes("Children")) return {};
|
|
1817
1826
|
return { MemberExpression(node) {
|
|
1818
1827
|
if (core.isChildrenCount(context, node)) context.report({
|
|
1819
1828
|
messageId: "default",
|
|
@@ -1832,6 +1841,7 @@ var no_children_for_each_default = createRule({
|
|
|
1832
1841
|
create: create$44
|
|
1833
1842
|
});
|
|
1834
1843
|
function create$44(context) {
|
|
1844
|
+
if (!context.sourceCode.text.includes("Children")) return {};
|
|
1835
1845
|
return { MemberExpression(node) {
|
|
1836
1846
|
if (core.isChildrenForEach(context, node)) context.report({
|
|
1837
1847
|
messageId: "default",
|
|
@@ -1850,6 +1860,7 @@ var no_children_map_default = createRule({
|
|
|
1850
1860
|
create: create$43
|
|
1851
1861
|
});
|
|
1852
1862
|
function create$43(context) {
|
|
1863
|
+
if (!context.sourceCode.text.includes("Children")) return {};
|
|
1853
1864
|
return { MemberExpression(node) {
|
|
1854
1865
|
if (core.isChildrenMap(context, node)) context.report({
|
|
1855
1866
|
messageId: "default",
|
|
@@ -1868,6 +1879,7 @@ var no_children_only_default = createRule({
|
|
|
1868
1879
|
create: create$42
|
|
1869
1880
|
});
|
|
1870
1881
|
function create$42(context) {
|
|
1882
|
+
if (!context.sourceCode.text.includes("Children")) return {};
|
|
1871
1883
|
return { MemberExpression(node) {
|
|
1872
1884
|
if (core.isChildrenOnly(context, node)) context.report({
|
|
1873
1885
|
messageId: "default",
|
|
@@ -1886,6 +1898,7 @@ var no_children_to_array_default = createRule({
|
|
|
1886
1898
|
create: create$41
|
|
1887
1899
|
});
|
|
1888
1900
|
function create$41(context) {
|
|
1901
|
+
if (!context.sourceCode.text.includes("Children")) return {};
|
|
1889
1902
|
return { MemberExpression(node) {
|
|
1890
1903
|
if (core.isChildrenToArray(context, node)) context.report({
|
|
1891
1904
|
messageId: "default",
|
|
@@ -1996,7 +2009,7 @@ function memoize(f) {
|
|
|
1996
2009
|
function not(predicate) {
|
|
1997
2010
|
return (data) => !predicate(data);
|
|
1998
2011
|
}
|
|
1999
|
-
|
|
2012
|
+
dual(2, (a, b) => (data) => a(data) && b(data));
|
|
2000
2013
|
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
2001
2014
|
dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
2002
2015
|
dual(2, (a, b) => (data) => a(data) === b(data));
|
|
@@ -2069,6 +2082,7 @@ var no_clone_element_default = createRule({
|
|
|
2069
2082
|
create: create$39
|
|
2070
2083
|
});
|
|
2071
2084
|
function create$39(context) {
|
|
2085
|
+
if (!context.sourceCode.text.includes("cloneElement")) return {};
|
|
2072
2086
|
return { CallExpression(node) {
|
|
2073
2087
|
if (core.isCloneElementCall(context, node)) context.report({
|
|
2074
2088
|
messageId: "default",
|
|
@@ -2246,6 +2260,20 @@ var no_direct_mutation_state_default = createRule({
|
|
|
2246
2260
|
name: "no-direct-mutation-state",
|
|
2247
2261
|
create: create$33
|
|
2248
2262
|
});
|
|
2263
|
+
function create$33(context) {
|
|
2264
|
+
if (!context.sourceCode.text.includes("Component")) return {};
|
|
2265
|
+
return { AssignmentExpression(node) {
|
|
2266
|
+
if (!isAssignmentToThisState(node)) return;
|
|
2267
|
+
const fact = Traverse.findParent(node, Check.isClass);
|
|
2268
|
+
if (fact == null || !core.isClassComponent(fact)) return;
|
|
2269
|
+
const constructor = Traverse.findParent(node, isConstructorFunction);
|
|
2270
|
+
if (Traverse.findParent(node, Check.isFunctionOrClass) === constructor) return;
|
|
2271
|
+
context.report({
|
|
2272
|
+
messageId: "default",
|
|
2273
|
+
node
|
|
2274
|
+
});
|
|
2275
|
+
} };
|
|
2276
|
+
}
|
|
2249
2277
|
function isConstructorFunction(node) {
|
|
2250
2278
|
return Check.isOneOf([AST_NODE_TYPES.FunctionDeclaration, AST_NODE_TYPES.FunctionExpression])(node) && Check.isPropertyOrMethod(node.parent) && Check.isIdentifier(node.parent.key, "constructor");
|
|
2251
2279
|
}
|
|
@@ -2260,17 +2288,6 @@ function isAssignmentToThisState(node) {
|
|
|
2260
2288
|
}
|
|
2261
2289
|
return false;
|
|
2262
2290
|
}
|
|
2263
|
-
function create$33(context) {
|
|
2264
|
-
return { AssignmentExpression(node) {
|
|
2265
|
-
if (!isAssignmentToThisState(node)) return;
|
|
2266
|
-
const fact = Traverse.findParent(node, Check.isClass);
|
|
2267
|
-
if (fact == null) return;
|
|
2268
|
-
if (core.isClassComponent(fact) && context.sourceCode.getScope(node).block !== Traverse.findParent(node, isConstructorFunction)) context.report({
|
|
2269
|
-
messageId: "default",
|
|
2270
|
-
node
|
|
2271
|
-
});
|
|
2272
|
-
} };
|
|
2273
|
-
}
|
|
2274
2291
|
var no_duplicate_key_default = createRule({
|
|
2275
2292
|
meta: {
|
|
2276
2293
|
type: "problem",
|
|
@@ -2282,13 +2299,20 @@ var no_duplicate_key_default = createRule({
|
|
|
2282
2299
|
create: create$32
|
|
2283
2300
|
});
|
|
2284
2301
|
function create$32(context) {
|
|
2285
|
-
if (
|
|
2286
|
-
const
|
|
2287
|
-
function
|
|
2288
|
-
const
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2302
|
+
if (!/\bkey\b/u.test(context.sourceCode.text)) return {};
|
|
2303
|
+
const keyGroups = /* @__PURE__ */ new Map();
|
|
2304
|
+
function recordSiblingKey(root, key) {
|
|
2305
|
+
const prevKeys = keyGroups.get(root)?.keys ?? [];
|
|
2306
|
+
keyGroups.set(root, {
|
|
2307
|
+
hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, key)),
|
|
2308
|
+
keys: [...prevKeys, key]
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
function recordMapCallbackKey(call, key) {
|
|
2312
|
+
keyGroups.set(call, {
|
|
2313
|
+
hasDuplicate: key.value?.type === AST_NODE_TYPES.Literal,
|
|
2314
|
+
keys: [key]
|
|
2315
|
+
});
|
|
2292
2316
|
}
|
|
2293
2317
|
return {
|
|
2294
2318
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -2296,16 +2320,9 @@ function create$32(context) {
|
|
|
2296
2320
|
switch (jsxElement.parent.type) {
|
|
2297
2321
|
case AST_NODE_TYPES.ArrayExpression:
|
|
2298
2322
|
case AST_NODE_TYPES.JSXElement:
|
|
2299
|
-
case AST_NODE_TYPES.JSXFragment:
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
keyedEntries.set(root, {
|
|
2303
|
-
hasDuplicate: prevKeys.some((prevKey) => isKeyValueEqual(prevKey, node)),
|
|
2304
|
-
keys: [...prevKeys, node],
|
|
2305
|
-
root: jsxElement.parent
|
|
2306
|
-
});
|
|
2307
|
-
break;
|
|
2308
|
-
}
|
|
2323
|
+
case AST_NODE_TYPES.JSXFragment:
|
|
2324
|
+
recordSiblingKey(jsxElement.parent, node);
|
|
2325
|
+
return;
|
|
2309
2326
|
default: {
|
|
2310
2327
|
const call = Traverse.findParent(jsxElement, (n) => {
|
|
2311
2328
|
if (n.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
@@ -2314,21 +2331,15 @@ function create$32(context) {
|
|
|
2314
2331
|
return Check.isIdentifier(callee.property, "map");
|
|
2315
2332
|
});
|
|
2316
2333
|
if (call == null) return;
|
|
2317
|
-
const
|
|
2318
|
-
if (
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
if (Extract.unwrap(arg0) !== iter) return;
|
|
2322
|
-
keyedEntries.set(call, {
|
|
2323
|
-
hasDuplicate: node.value?.type === AST_NODE_TYPES.Literal,
|
|
2324
|
-
keys: [node],
|
|
2325
|
-
root: call
|
|
2326
|
-
});
|
|
2334
|
+
const callback = call.arguments[0];
|
|
2335
|
+
if (callback == null) return;
|
|
2336
|
+
if (Traverse.findParent(jsxElement, Check.isFunction, (n) => n === call) !== Extract.unwrap(callback)) return;
|
|
2337
|
+
recordMapCallbackKey(call, node);
|
|
2327
2338
|
}
|
|
2328
2339
|
}
|
|
2329
2340
|
},
|
|
2330
2341
|
"Program:exit"() {
|
|
2331
|
-
for (const { hasDuplicate, keys } of
|
|
2342
|
+
for (const { hasDuplicate, keys } of keyGroups.values()) {
|
|
2332
2343
|
if (!hasDuplicate) continue;
|
|
2333
2344
|
for (const key of keys) context.report({
|
|
2334
2345
|
messageId: "default",
|
|
@@ -2338,6 +2349,12 @@ function create$32(context) {
|
|
|
2338
2349
|
}
|
|
2339
2350
|
};
|
|
2340
2351
|
}
|
|
2352
|
+
function isKeyValueEqual(a, b) {
|
|
2353
|
+
const aValue = a.value;
|
|
2354
|
+
const bValue = b.value;
|
|
2355
|
+
if (aValue == null || bValue == null) return false;
|
|
2356
|
+
return Compare.isEqual(aValue, bValue);
|
|
2357
|
+
}
|
|
2341
2358
|
var no_forward_ref_default = createRule({
|
|
2342
2359
|
meta: {
|
|
2343
2360
|
type: "suggestion",
|
|
@@ -2465,6 +2482,7 @@ var no_implicit_children_default = createRule({
|
|
|
2465
2482
|
create: create$30
|
|
2466
2483
|
});
|
|
2467
2484
|
function create$30(context) {
|
|
2485
|
+
if (!context.sourceCode.text.includes("...")) return {};
|
|
2468
2486
|
return createImplicitPropListener(context, {
|
|
2469
2487
|
name: "children",
|
|
2470
2488
|
isAllowedProp: (fqn) => fqn.endsWith("attributes.children") || fqn.endsWith("propswithchildren.children"),
|
|
@@ -2488,6 +2506,7 @@ var no_implicit_key_default = createRule({
|
|
|
2488
2506
|
create: create$29
|
|
2489
2507
|
});
|
|
2490
2508
|
function create$29(context) {
|
|
2509
|
+
if (!context.sourceCode.text.includes("...")) return {};
|
|
2491
2510
|
return createImplicitPropListener(context, {
|
|
2492
2511
|
name: "key",
|
|
2493
2512
|
isAllowedProp: (fqn) => fqn.endsWith("react.attributes.key"),
|
|
@@ -2514,6 +2533,7 @@ var no_implicit_ref_default = createRule({
|
|
|
2514
2533
|
create: create$28
|
|
2515
2534
|
});
|
|
2516
2535
|
function create$28(context) {
|
|
2536
|
+
if (!context.sourceCode.text.includes("...")) return {};
|
|
2517
2537
|
return createImplicitPropListener(context, {
|
|
2518
2538
|
name: "ref",
|
|
2519
2539
|
isAllowedProp: (fqn) => fqn.endsWith("attributes.ref"),
|
|
@@ -2658,7 +2678,20 @@ function create$25(context) {
|
|
|
2658
2678
|
})) context.report({
|
|
2659
2679
|
fix(fixer) {
|
|
2660
2680
|
if (id.type !== AST_NODE_TYPES.Identifier || id.parent !== call.parent) return [];
|
|
2661
|
-
|
|
2681
|
+
const declaration = id.parent.parent;
|
|
2682
|
+
if (declaration == null || declaration.type !== AST_NODE_TYPES.VariableDeclaration) return [];
|
|
2683
|
+
switch (declaration.parent.type) {
|
|
2684
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
2685
|
+
case AST_NODE_TYPES.ExportNamedDeclaration:
|
|
2686
|
+
case AST_NODE_TYPES.Program:
|
|
2687
|
+
case AST_NODE_TYPES.StaticBlock:
|
|
2688
|
+
case AST_NODE_TYPES.SwitchCase:
|
|
2689
|
+
case AST_NODE_TYPES.TSModuleBlock: break;
|
|
2690
|
+
default: return [];
|
|
2691
|
+
}
|
|
2692
|
+
const lastToken = context.sourceCode.getLastToken(declaration);
|
|
2693
|
+
if (lastToken == null) return [];
|
|
2694
|
+
return fixer.insertTextAfter(lastToken, [
|
|
2662
2695
|
"\n",
|
|
2663
2696
|
id.name,
|
|
2664
2697
|
".",
|
|
@@ -2677,8 +2710,9 @@ function create$25(context) {
|
|
|
2677
2710
|
}
|
|
2678
2711
|
};
|
|
2679
2712
|
}
|
|
2680
|
-
// src/rules/no-missing-key/
|
|
2681
|
-
const
|
|
2713
|
+
// src/rules/no-missing-key/no-missing-key.ts
|
|
2714
|
+
const RULE_NAME$24 = "no-missing-key";
|
|
2715
|
+
const ITERATOR_CALLBACK_POSITIONS = /* @__PURE__ */ new Map([
|
|
2682
2716
|
["flatMap", 0],
|
|
2683
2717
|
["from", 1],
|
|
2684
2718
|
["map", 0]
|
|
@@ -2693,19 +2727,9 @@ var no_missing_key_default = createRule({
|
|
|
2693
2727
|
},
|
|
2694
2728
|
schema: []
|
|
2695
2729
|
},
|
|
2696
|
-
name:
|
|
2730
|
+
name: RULE_NAME$24,
|
|
2697
2731
|
create: create$24
|
|
2698
2732
|
});
|
|
2699
|
-
function getIteratorCallback(node) {
|
|
2700
|
-
const callee = Extract.unwrap(node.callee);
|
|
2701
|
-
if (callee.type !== AST_NODE_TYPES.MemberExpression) return null;
|
|
2702
|
-
if (!Check.isIdentifier(callee.property)) return null;
|
|
2703
|
-
const position = KNOWN_CALLBACK_POSITIONS.get(callee.property.name);
|
|
2704
|
-
if (position == null) return null;
|
|
2705
|
-
const callback = node.arguments[position];
|
|
2706
|
-
if (callback == null || !Check.isFunction(callback)) return null;
|
|
2707
|
-
return callback;
|
|
2708
|
-
}
|
|
2709
2733
|
function create$24(context) {
|
|
2710
2734
|
let childrenToArrayDepth = 0;
|
|
2711
2735
|
function visitItemExpression(node) {
|
|
@@ -2716,10 +2740,13 @@ function create$24(context) {
|
|
|
2716
2740
|
case AST_NODE_TYPES.TSNonNullExpression:
|
|
2717
2741
|
case AST_NODE_TYPES.TSSatisfiesExpression:
|
|
2718
2742
|
case AST_NODE_TYPES.TSInstantiationExpression: return visitItemExpression(node.expression);
|
|
2719
|
-
case AST_NODE_TYPES.JSXElement:
|
|
2720
|
-
|
|
2721
|
-
node
|
|
2722
|
-
|
|
2743
|
+
case AST_NODE_TYPES.JSXElement:
|
|
2744
|
+
if (hasAttribute(node, "key")) return [];
|
|
2745
|
+
if (node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute)) return [];
|
|
2746
|
+
return [{
|
|
2747
|
+
messageId: "default",
|
|
2748
|
+
node
|
|
2749
|
+
}];
|
|
2723
2750
|
case AST_NODE_TYPES.JSXFragment: return [{
|
|
2724
2751
|
messageId: "unexpected-fragment-syntax",
|
|
2725
2752
|
node
|
|
@@ -2741,13 +2768,20 @@ function create$24(context) {
|
|
|
2741
2768
|
}
|
|
2742
2769
|
},
|
|
2743
2770
|
CallExpression(node) {
|
|
2771
|
+
const call = node;
|
|
2744
2772
|
if (core.isChildrenToArrayCall(context, node)) {
|
|
2745
2773
|
childrenToArrayDepth += 1;
|
|
2746
2774
|
return;
|
|
2747
2775
|
}
|
|
2748
2776
|
if (childrenToArrayDepth > 0) return;
|
|
2749
|
-
const
|
|
2750
|
-
if (
|
|
2777
|
+
const callee = Extract.unwrap(call.callee);
|
|
2778
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression || !Check.isIdentifier(callee.property)) return;
|
|
2779
|
+
const position = ITERATOR_CALLBACK_POSITIONS.get(callee.property.name);
|
|
2780
|
+
if (position == null) return;
|
|
2781
|
+
const argument = call.arguments[position];
|
|
2782
|
+
if (argument == null) return;
|
|
2783
|
+
const callback = Extract.unwrap(argument);
|
|
2784
|
+
if (!Check.isFunction(callback)) return;
|
|
2751
2785
|
for (const desc of visitIteratorCallback(callback)) context.report(desc);
|
|
2752
2786
|
},
|
|
2753
2787
|
"CallExpression:exit"(node) {
|
|
@@ -2961,6 +2995,7 @@ var no_nested_lazy_component_declarations_default = createRule({
|
|
|
2961
2995
|
create: create$21
|
|
2962
2996
|
});
|
|
2963
2997
|
function create$21(context) {
|
|
2998
|
+
if (!context.sourceCode.text.includes("lazy")) return {};
|
|
2964
2999
|
const fc = core.getFunctionComponentCollector(context);
|
|
2965
3000
|
const cc = core.getClassComponentCollector(context);
|
|
2966
3001
|
const hc = core.getHookCollector(context);
|
|
@@ -3205,14 +3240,15 @@ function create$13(context) {
|
|
|
3205
3240
|
const constructions = /* @__PURE__ */ new WeakMap();
|
|
3206
3241
|
return merge(visitor, {
|
|
3207
3242
|
JSXOpeningElement(node) {
|
|
3208
|
-
const selfName =
|
|
3209
|
-
if (selfName
|
|
3243
|
+
const selfName = getElementSelfType(node.parent);
|
|
3244
|
+
if (selfName === "") return;
|
|
3210
3245
|
if (!isContextName(selfName, isReact18OrBelow)) return;
|
|
3211
3246
|
const enclosingFunction = Traverse.findParent(node, Check.isFunction);
|
|
3212
3247
|
if (enclosingFunction == null) return;
|
|
3213
3248
|
if (compilationMode === "annotation" && core.isFunctionHasDirective(enclosingFunction, "use memo")) return;
|
|
3214
|
-
const attribute = node.attributes.findLast(
|
|
3215
|
-
if (attribute?.
|
|
3249
|
+
const attribute = node.attributes.findLast(isPlainAttribute("value"));
|
|
3250
|
+
if (attribute?.type !== AST_NODE_TYPES.JSXAttribute) return;
|
|
3251
|
+
if (attribute.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
3216
3252
|
const valueExpression = attribute.value.expression;
|
|
3217
3253
|
const construction = resolveObjectType(context, valueExpression);
|
|
3218
3254
|
if (construction == null) return;
|
|
@@ -3252,35 +3288,32 @@ function getHumanReadableKind(node) {
|
|
|
3252
3288
|
}
|
|
3253
3289
|
return toLowerCase(delimiterCase(node.type, " "));
|
|
3254
3290
|
}
|
|
3255
|
-
// src/rules/no-unstable-default-props/no-unstable-default-props.ts
|
|
3256
|
-
const RULE_NAME$12 = "no-unstable-default-props";
|
|
3257
|
-
const defaultOptions$1 = [{ safeDefaultProps: [] }];
|
|
3258
|
-
const schema$1 = [{
|
|
3259
|
-
type: "object",
|
|
3260
|
-
additionalProperties: false,
|
|
3261
|
-
properties: { safeDefaultProps: {
|
|
3262
|
-
type: "array",
|
|
3263
|
-
items: { type: "string" }
|
|
3264
|
-
} }
|
|
3265
|
-
}];
|
|
3266
3291
|
var no_unstable_default_props_default = createRule({
|
|
3267
3292
|
meta: {
|
|
3268
3293
|
type: "problem",
|
|
3269
|
-
defaultOptions: [
|
|
3294
|
+
defaultOptions: [{}],
|
|
3270
3295
|
docs: { description: "Prevents using referential-type values as default props in object destructuring." },
|
|
3271
3296
|
messages: { default: "A/an '{{kind}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{kind}}'." },
|
|
3272
|
-
schema:
|
|
3297
|
+
schema: [{
|
|
3298
|
+
type: "object",
|
|
3299
|
+
additionalProperties: false,
|
|
3300
|
+
properties: { safeDefaultProps: {
|
|
3301
|
+
type: "array",
|
|
3302
|
+
description: "Property names or patterns that are safe to use as default props.",
|
|
3303
|
+
items: { type: "string" }
|
|
3304
|
+
} }
|
|
3305
|
+
}]
|
|
3273
3306
|
},
|
|
3274
|
-
name:
|
|
3307
|
+
name: "no-unstable-default-props",
|
|
3275
3308
|
create: create$12
|
|
3276
3309
|
});
|
|
3277
|
-
function create$12(context
|
|
3310
|
+
function create$12(context) {
|
|
3311
|
+
const safeDefaultProps = (context.options[0] ?? {}).safeDefaultProps ?? [];
|
|
3278
3312
|
const { compilationMode } = getSettingsFromContext(context);
|
|
3279
3313
|
if (compilationMode === "infer" || compilationMode === "all") return {};
|
|
3280
3314
|
if (compilationMode === "annotation" && context.sourceCode.ast.body.some((stmt) => Check.isDirective(stmt, "use memo"))) return {};
|
|
3281
3315
|
const { api, visitor } = core.getFunctionComponentCollector(context);
|
|
3282
3316
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
3283
|
-
const { safeDefaultProps = [] } = options;
|
|
3284
3317
|
const safePatterns = safeDefaultProps.map((s) => toRegExp(s));
|
|
3285
3318
|
return merge(visitor, {
|
|
3286
3319
|
[SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR](node) {
|
|
@@ -3297,7 +3330,7 @@ function create$12(context, [options]) {
|
|
|
3297
3330
|
return declarators.get(component)?.filter((d) => d.init.name === name).flatMap((d) => d.id.properties) ?? [];
|
|
3298
3331
|
}).otherwise(() => []);
|
|
3299
3332
|
for (const prop of properties) {
|
|
3300
|
-
if (prop.type !== AST_NODE_TYPES.Property || prop.value
|
|
3333
|
+
if (prop.type !== AST_NODE_TYPES.Property || !Check.isObjectPatternElementDefault(prop.value)) continue;
|
|
3301
3334
|
const { value } = prop;
|
|
3302
3335
|
const { right } = value;
|
|
3303
3336
|
const construction = resolveObjectType(context, value);
|
|
@@ -3354,8 +3387,7 @@ function isExportedClass(node) {
|
|
|
3354
3387
|
default: return false;
|
|
3355
3388
|
}
|
|
3356
3389
|
}
|
|
3357
|
-
function isPublicMethod(
|
|
3358
|
-
const member = def.parent;
|
|
3390
|
+
function isPublicMethod(member) {
|
|
3359
3391
|
switch (member.type) {
|
|
3360
3392
|
case AST_NODE_TYPES.MethodDefinition: return member.accessibility == null || member.accessibility === "public";
|
|
3361
3393
|
case AST_NODE_TYPES.PropertyDefinition: return (member.accessibility == null || member.accessibility === "public") && (member.value?.type === AST_NODE_TYPES.ArrowFunctionExpression || member.value?.type === AST_NODE_TYPES.FunctionExpression);
|
|
@@ -3373,8 +3405,17 @@ var no_unused_class_component_members_default = createRule({
|
|
|
3373
3405
|
create: create$11
|
|
3374
3406
|
});
|
|
3375
3407
|
function create$11(context) {
|
|
3408
|
+
if (!context.sourceCode.text.includes("Component")) return {};
|
|
3376
3409
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
3410
|
+
const publicMethods = /* @__PURE__ */ new WeakMap();
|
|
3377
3411
|
const propertyUsages = /* @__PURE__ */ new WeakMap();
|
|
3412
|
+
function getStaticName(key, computed) {
|
|
3413
|
+
const unwrapped = Extract.unwrap(key);
|
|
3414
|
+
if (!computed && Check.isIdentifier(unwrapped)) return unwrapped.name;
|
|
3415
|
+
if (unwrapped.type === AST_NODE_TYPES.Literal && typeof unwrapped.value === "string") return unwrapped.value;
|
|
3416
|
+
if (unwrapped.type === AST_NODE_TYPES.TemplateLiteral && unwrapped.expressions.length === 0) return unwrapped.quasis[0]?.value.cooked ?? unwrapped.quasis[0]?.value.raw ?? null;
|
|
3417
|
+
return null;
|
|
3418
|
+
}
|
|
3378
3419
|
function classExit(node) {
|
|
3379
3420
|
if (!core.isClassComponent(node)) return;
|
|
3380
3421
|
const id = core.getClassId(node);
|
|
@@ -3382,21 +3423,20 @@ function create$11(context) {
|
|
|
3382
3423
|
if (defs == null) return;
|
|
3383
3424
|
const usages = propertyUsages.get(node);
|
|
3384
3425
|
const exported = isExportedClass(node);
|
|
3385
|
-
|
|
3386
|
-
|
|
3426
|
+
const publicMembers = publicMethods.get(node);
|
|
3427
|
+
for (const [methodName, defNode] of defs) {
|
|
3387
3428
|
if (usages?.has(methodName) ?? false) continue;
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
}
|
|
3429
|
+
const isPureComponentShouldUpdate = methodName === "shouldComponentUpdate" && core.isPureComponent(node);
|
|
3430
|
+
if (LIFECYCLE_METHODS.has(methodName) && !isPureComponentShouldUpdate) continue;
|
|
3391
3431
|
if (KNOWN_HOST_CONVENTION_METHODS.has(methodName)) continue;
|
|
3392
|
-
if (exported &&
|
|
3432
|
+
if (exported && (publicMembers?.has(methodName) ?? false)) continue;
|
|
3393
3433
|
context.report({
|
|
3394
3434
|
data: {
|
|
3395
3435
|
className: id != null ? getText(context, id) : "Component",
|
|
3396
3436
|
methodName
|
|
3397
3437
|
},
|
|
3398
3438
|
messageId: "default",
|
|
3399
|
-
node:
|
|
3439
|
+
node: defNode
|
|
3400
3440
|
});
|
|
3401
3441
|
}
|
|
3402
3442
|
}
|
|
@@ -3404,7 +3444,11 @@ function create$11(context) {
|
|
|
3404
3444
|
const currentClass = Traverse.findParent(node, Check.isClass);
|
|
3405
3445
|
if (currentClass == null || !core.isClassComponent(currentClass)) return;
|
|
3406
3446
|
if (node.static) return;
|
|
3407
|
-
if (
|
|
3447
|
+
if (node.computed || !Check.isIdentifier(node.key)) return;
|
|
3448
|
+
const methodName = node.key.name;
|
|
3449
|
+
const defs = getOrInsertComputed(propertyDefs, currentClass, () => /* @__PURE__ */ new Map());
|
|
3450
|
+
if (!defs.has(methodName)) defs.set(methodName, node.key);
|
|
3451
|
+
if (isPublicMethod(node)) getOrInsertComputed(publicMethods, currentClass, () => /* @__PURE__ */ new Set()).add(methodName);
|
|
3408
3452
|
}
|
|
3409
3453
|
return {
|
|
3410
3454
|
"ClassDeclaration:exit": classExit,
|
|
@@ -3414,12 +3458,17 @@ function create$11(context) {
|
|
|
3414
3458
|
const currentMethod = Traverse.findParent(node, Check.isPropertyOrMethod);
|
|
3415
3459
|
if (currentClass == null || currentMethod == null) return;
|
|
3416
3460
|
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3417
|
-
if (node.object.type !== AST_NODE_TYPES.ThisExpression
|
|
3461
|
+
if (node.object.type !== AST_NODE_TYPES.ThisExpression) return;
|
|
3418
3462
|
if (node.parent.type === AST_NODE_TYPES.AssignmentExpression && node.parent.left === node) {
|
|
3419
|
-
|
|
3463
|
+
if (!node.computed && Check.isIdentifier(node.property)) {
|
|
3464
|
+
const defs = getOrInsertComputed(propertyDefs, currentClass, () => /* @__PURE__ */ new Map());
|
|
3465
|
+
if (!defs.has(node.property.name)) defs.set(node.property.name, node.property);
|
|
3466
|
+
}
|
|
3420
3467
|
return;
|
|
3421
3468
|
}
|
|
3422
|
-
|
|
3469
|
+
const propertyName = getStaticName(node.property, node.computed);
|
|
3470
|
+
if (propertyName == null) return;
|
|
3471
|
+
getOrInsertComputed(propertyUsages, currentClass, () => /* @__PURE__ */ new Set()).add(propertyName);
|
|
3423
3472
|
},
|
|
3424
3473
|
MethodDefinition: methodEnter,
|
|
3425
3474
|
PropertyDefinition: methodEnter,
|
|
@@ -3428,8 +3477,11 @@ function create$11(context) {
|
|
|
3428
3477
|
const currentMethod = Traverse.findParent(node, Check.isPropertyOrMethod);
|
|
3429
3478
|
if (currentClass == null || currentMethod == null) return;
|
|
3430
3479
|
if (!core.isClassComponent(currentClass) || currentMethod.static) return;
|
|
3431
|
-
if (node.init != null && node.init.type === AST_NODE_TYPES.ThisExpression && node.id.type === AST_NODE_TYPES.ObjectPattern) {
|
|
3432
|
-
|
|
3480
|
+
if (node.init != null && node.init.type === AST_NODE_TYPES.ThisExpression && node.id.type === AST_NODE_TYPES.ObjectPattern) for (const prop of node.id.properties) {
|
|
3481
|
+
if (prop.type !== AST_NODE_TYPES.Property) continue;
|
|
3482
|
+
const name = getStaticName(prop.key, prop.computed);
|
|
3483
|
+
if (name == null) continue;
|
|
3484
|
+
getOrInsertComputed(propertyUsages, currentClass, () => /* @__PURE__ */ new Set()).add(name);
|
|
3433
3485
|
}
|
|
3434
3486
|
}
|
|
3435
3487
|
};
|
|
@@ -4021,16 +4073,23 @@ function getDestructuredPropertyName(pattern, name) {
|
|
|
4021
4073
|
for (const property of pattern.properties) {
|
|
4022
4074
|
if (property.type !== AST_NODE_TYPES.Property) continue;
|
|
4023
4075
|
if ((property.value.type === AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value) !== name) continue;
|
|
4024
|
-
|
|
4076
|
+
const key = Extract.unwrap(property.key);
|
|
4077
|
+
if (!property.computed && Check.isIdentifier(key)) return key.name;
|
|
4078
|
+
if (key.type === AST_NODE_TYPES.Literal && typeof key.value === "string") return key.value;
|
|
4079
|
+
if (key.type === AST_NODE_TYPES.TemplateLiteral && key.expressions.length === 0) return key.quasis[0]?.value.cooked ?? key.quasis[0]?.value.raw ?? null;
|
|
4080
|
+
return null;
|
|
4025
4081
|
}
|
|
4026
4082
|
return null;
|
|
4027
4083
|
}
|
|
4028
4084
|
function resolveBuiltinMember(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
4029
|
-
|
|
4030
|
-
const
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4085
|
+
let rootId = Extract.unwrap(node);
|
|
4086
|
+
const segments = [];
|
|
4087
|
+
for (let current = rootId; current.type === AST_NODE_TYPES.MemberExpression; current = Extract.unwrap(current.object)) {
|
|
4088
|
+
if (current.computed) return null;
|
|
4089
|
+
segments.unshift(Extract.unwrap(current.property));
|
|
4090
|
+
rootId = Extract.unwrap(current.object);
|
|
4091
|
+
}
|
|
4092
|
+
if (!Check.isIdentifier(rootId)) return null;
|
|
4034
4093
|
if (segments.length === 0 || !segments.every((segment) => Check.isIdentifier(segment))) return null;
|
|
4035
4094
|
const resolved = resolveBuiltinObjectName(context, rootId, seen);
|
|
4036
4095
|
if (resolved == null) return null;
|
|
@@ -4291,18 +4350,6 @@ function getGuardDisposition(node, getNullBranch) {
|
|
|
4291
4350
|
}
|
|
4292
4351
|
return null;
|
|
4293
4352
|
}
|
|
4294
|
-
function isUnconditionallyTerminating(statement) {
|
|
4295
|
-
switch (statement.type) {
|
|
4296
|
-
case AST_NODE_TYPES.ReturnStatement:
|
|
4297
|
-
case AST_NODE_TYPES.ThrowStatement: return true;
|
|
4298
|
-
case AST_NODE_TYPES.BlockStatement: {
|
|
4299
|
-
const last = statement.body.at(-1);
|
|
4300
|
-
return last != null && isUnconditionallyTerminating(last);
|
|
4301
|
-
}
|
|
4302
|
-
case AST_NODE_TYPES.IfStatement: return statement.alternate != null && isUnconditionallyTerminating(statement.consequent) && isUnconditionallyTerminating(statement.alternate);
|
|
4303
|
-
default: return false;
|
|
4304
|
-
}
|
|
4305
|
-
}
|
|
4306
4353
|
function isAfterTerminatingNonNullGuard(node, getNullBranch) {
|
|
4307
4354
|
let statement = node;
|
|
4308
4355
|
while (statement.parent?.type !== AST_NODE_TYPES.BlockStatement) {
|
|
@@ -4317,7 +4364,7 @@ function isAfterTerminatingNonNullGuard(node, getNullBranch) {
|
|
|
4317
4364
|
const nullBranch = getNullBranch(sibling.test);
|
|
4318
4365
|
if (nullBranch == null) continue;
|
|
4319
4366
|
const nonNullBranch = nullBranch === "alternate" ? sibling.consequent : sibling.alternate;
|
|
4320
|
-
return nonNullBranch != null && isUnconditionallyTerminating(nonNullBranch);
|
|
4367
|
+
return nonNullBranch != null && Analyze.isUnconditionallyTerminating(nonNullBranch);
|
|
4321
4368
|
}
|
|
4322
4369
|
return false;
|
|
4323
4370
|
}
|
|
@@ -6373,10 +6420,11 @@ function createFactCollector$3(additionalStateHooks, additionalEffectHooks) {
|
|
|
6373
6420
|
};
|
|
6374
6421
|
}
|
|
6375
6422
|
// src/rules/set-state-in-effect/helpers.ts
|
|
6376
|
-
function
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
return
|
|
6423
|
+
function getImmediateInvocation(fn) {
|
|
6424
|
+
let parent = fn.parent;
|
|
6425
|
+
while (Check.isTypeOrChainExpression(parent)) parent = parent.parent;
|
|
6426
|
+
if (parent.type !== AST_NODE_TYPES.CallExpression) return null;
|
|
6427
|
+
return Extract.unwrap(parent.callee) === fn ? parent : null;
|
|
6380
6428
|
}
|
|
6381
6429
|
function getConditionalBranch(node) {
|
|
6382
6430
|
let child = node;
|
|
@@ -6411,11 +6459,8 @@ function isRefLikeName(name) {
|
|
|
6411
6459
|
return name === "ref" || name.endsWith("Ref");
|
|
6412
6460
|
}
|
|
6413
6461
|
function getParameterId(param) {
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
case AST_NODE_TYPES.AssignmentPattern: return param.left.type === AST_NODE_TYPES.Identifier ? param.left : null;
|
|
6417
|
-
default: return null;
|
|
6418
|
-
}
|
|
6462
|
+
const target = param.type === AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
6463
|
+
return target.type === AST_NODE_TYPES.Identifier ? target : null;
|
|
6419
6464
|
}
|
|
6420
6465
|
function getRefSourceName(node) {
|
|
6421
6466
|
switch (node.type) {
|
|
@@ -6540,6 +6585,47 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6540
6585
|
}
|
|
6541
6586
|
return refParams;
|
|
6542
6587
|
}
|
|
6588
|
+
function isDeferredInvocation(invocation) {
|
|
6589
|
+
let current = invocation.parent;
|
|
6590
|
+
while (current != null) {
|
|
6591
|
+
if (Check.isFunction(current)) return false;
|
|
6592
|
+
switch (current.type) {
|
|
6593
|
+
case AST_NODE_TYPES.AssignmentPattern: return true;
|
|
6594
|
+
case AST_NODE_TYPES.PropertyDefinition: {
|
|
6595
|
+
if (current.static) return false;
|
|
6596
|
+
const value = current.value;
|
|
6597
|
+
return value != null && (value === invocation || Traverse.hasParent(invocation, (n) => n === value));
|
|
6598
|
+
}
|
|
6599
|
+
default: current = current.parent;
|
|
6600
|
+
}
|
|
6601
|
+
}
|
|
6602
|
+
return false;
|
|
6603
|
+
}
|
|
6604
|
+
function getVisibleWriteLocation(value, id) {
|
|
6605
|
+
let branch = getConditionalBranch(value);
|
|
6606
|
+
let node = value;
|
|
6607
|
+
let order = 1;
|
|
6608
|
+
let boundary = Traverse.findParent(value, Check.isFunction);
|
|
6609
|
+
while (boundary != null) {
|
|
6610
|
+
if (Traverse.hasParent(id, (n) => n === boundary)) return {
|
|
6611
|
+
branch,
|
|
6612
|
+
node,
|
|
6613
|
+
order
|
|
6614
|
+
};
|
|
6615
|
+
if (boundary.async || boundary.generator) return null;
|
|
6616
|
+
const invocation = getImmediateInvocation(boundary);
|
|
6617
|
+
if (invocation == null || isDeferredInvocation(invocation)) return null;
|
|
6618
|
+
branch ??= getConditionalBranch(invocation);
|
|
6619
|
+
node = invocation;
|
|
6620
|
+
order = 0;
|
|
6621
|
+
boundary = Traverse.findParent(invocation, Check.isFunction);
|
|
6622
|
+
}
|
|
6623
|
+
return {
|
|
6624
|
+
branch,
|
|
6625
|
+
node,
|
|
6626
|
+
order
|
|
6627
|
+
};
|
|
6628
|
+
}
|
|
6543
6629
|
function isInitializedFromRef(id, refParams, seen = /* @__PURE__ */ new Set()) {
|
|
6544
6630
|
const variable = findVariable(context.sourceCode.getScope(id), id);
|
|
6545
6631
|
if (variable == null) return false;
|
|
@@ -6548,11 +6634,16 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6548
6634
|
seen.add(key);
|
|
6549
6635
|
if (isStateHeldDomNode(variable)) return true;
|
|
6550
6636
|
const candidates = [];
|
|
6551
|
-
const addCandidate = (value,
|
|
6552
|
-
|
|
6637
|
+
const addCandidate = (value, visibility = {
|
|
6638
|
+
branch: getConditionalBranch(value),
|
|
6639
|
+
node: value,
|
|
6640
|
+
order: 1
|
|
6641
|
+
}, previous) => {
|
|
6642
|
+
if (visibility.node.range[1] > id.range[0] || candidates.some((c) => c.value === value)) return;
|
|
6553
6643
|
candidates.push({
|
|
6554
|
-
branch:
|
|
6555
|
-
|
|
6644
|
+
branch: visibility.branch,
|
|
6645
|
+
order: visibility.order,
|
|
6646
|
+
position: visibility.node.range[1],
|
|
6556
6647
|
previous,
|
|
6557
6648
|
value
|
|
6558
6649
|
});
|
|
@@ -6565,12 +6656,13 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6565
6656
|
if (!reference.isWrite() || reference.writeExpr == null) continue;
|
|
6566
6657
|
if (reference.init === true && variable.defs.some((d) => d.type === DefinitionType.Parameter && refParams?.has(d.name) === true)) continue;
|
|
6567
6658
|
const writeExpr = reference.writeExpr;
|
|
6568
|
-
|
|
6659
|
+
const visibility = getVisibleWriteLocation(writeExpr, id);
|
|
6660
|
+
if (visibility == null) continue;
|
|
6569
6661
|
const parent = reference.identifier.parent;
|
|
6570
|
-
addCandidate(writeExpr, parent.type === AST_NODE_TYPES.AssignmentExpression && parent.operator !== "=" && Extract.unwrap(parent.left) === reference.identifier ? reference.identifier : void 0);
|
|
6662
|
+
addCandidate(writeExpr, visibility, parent.type === AST_NODE_TYPES.AssignmentExpression && parent.operator !== "=" && Extract.unwrap(parent.left) === reference.identifier ? reference.identifier : void 0);
|
|
6571
6663
|
}
|
|
6572
6664
|
const survivingCandidates = [];
|
|
6573
|
-
for (const candidate of [...candidates].sort((a, b) => a.position - b.position)) {
|
|
6665
|
+
for (const candidate of [...candidates].sort((a, b) => a.position - b.position || a.order - b.order)) {
|
|
6574
6666
|
if (candidate.branch == null) survivingCandidates.length = 0;
|
|
6575
6667
|
else {
|
|
6576
6668
|
const previousIndex = survivingCandidates.findIndex((o) => o.branch === candidate.branch);
|
|
@@ -6581,6 +6673,9 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6581
6673
|
if (survivingCandidates.length > 0) return survivingCandidates.some((c) => c.previous != null && isInitializedFromRef(c.previous, refParams, seen) || isRefValue(c.value, refParams, seen, "initializer"));
|
|
6582
6674
|
return variable.defs.some((d) => d.type === DefinitionType.Parameter && (refParams?.has(d.name) === true || d.name.type === AST_NODE_TYPES.Identifier && isRefLikeName(d.name.name)));
|
|
6583
6675
|
}
|
|
6676
|
+
function isInitializedFromParameter(id) {
|
|
6677
|
+
return findVariable(context.sourceCode.getScope(id), id)?.defs.some((d) => d.type === DefinitionType.Parameter) ?? false;
|
|
6678
|
+
}
|
|
6584
6679
|
function isRefValue(node, refParams, seen, mode) {
|
|
6585
6680
|
const expression = Extract.unwrap(node);
|
|
6586
6681
|
if (isUseRefCall(expression)) return true;
|
|
@@ -6589,7 +6684,7 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6589
6684
|
case AST_NODE_TYPES.MemberExpression: {
|
|
6590
6685
|
const property = Extract.unwrap(expression.property);
|
|
6591
6686
|
const object = Extract.unwrap(expression.object);
|
|
6592
|
-
if (!expression.computed && Check.isIdentifier(property, "current") && object.type === AST_NODE_TYPES.Identifier &&
|
|
6687
|
+
if (!expression.computed && Check.isIdentifier(property, "current") && object.type === AST_NODE_TYPES.Identifier && isInitializedFromParameter(object)) return true;
|
|
6593
6688
|
if (mode === "initializer") {
|
|
6594
6689
|
let current = expression;
|
|
6595
6690
|
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
@@ -6598,7 +6693,7 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6598
6693
|
if (!current.computed && Check.isIdentifier(currentProperty, "current")) {
|
|
6599
6694
|
const sourceName = getRefSourceName(currentObject);
|
|
6600
6695
|
if (sourceName != null && isRefLikeName(sourceName)) return true;
|
|
6601
|
-
if (currentObject.type === AST_NODE_TYPES.Identifier &&
|
|
6696
|
+
if (currentObject.type === AST_NODE_TYPES.Identifier && isInitializedFromParameter(currentObject)) return true;
|
|
6602
6697
|
}
|
|
6603
6698
|
current = currentObject;
|
|
6604
6699
|
}
|
|
@@ -6620,7 +6715,11 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6620
6715
|
case AST_NODE_TYPES.LogicalExpression: return isRefValue(expression.left, refParams, seen, mode) || isRefValue(expression.right, refParams, seen, mode);
|
|
6621
6716
|
case AST_NODE_TYPES.UnaryExpression:
|
|
6622
6717
|
case AST_NODE_TYPES.UpdateExpression: return isRefValue(expression.argument, refParams, seen, mode);
|
|
6623
|
-
case AST_NODE_TYPES.ConditionalExpression: return
|
|
6718
|
+
case AST_NODE_TYPES.ConditionalExpression: return [
|
|
6719
|
+
mode === "initializer" ? expression.test : null,
|
|
6720
|
+
expression.consequent,
|
|
6721
|
+
expression.alternate
|
|
6722
|
+
].some((e) => e != null && isRefValue(e, refParams, seen, mode));
|
|
6624
6723
|
case AST_NODE_TYPES.SequenceExpression: return expression.expressions.some((p) => isRefValue(p, refParams, seen, mode));
|
|
6625
6724
|
case AST_NODE_TYPES.TemplateLiteral: return expression.expressions.some((p) => isRefValue(p, refParams, seen, mode));
|
|
6626
6725
|
case AST_NODE_TYPES.TaggedTemplateExpression: return isRefValue(expression.tag, refParams, seen, mode) || isRefValue(expression.quasi, refParams, seen, mode);
|
|
@@ -6643,6 +6742,29 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6643
6742
|
function isRefInExpression(node, refParams) {
|
|
6644
6743
|
return Collect.getIdentifiers(node).some((id) => isInitializedFromRef(id, refParams));
|
|
6645
6744
|
}
|
|
6745
|
+
function hasRefGatedTerminator(statements, refParams) {
|
|
6746
|
+
return statements.some((statement) => isRefGatedTerminator(statement, refParams));
|
|
6747
|
+
}
|
|
6748
|
+
function isRefGatedTerminator(statement, refParams) {
|
|
6749
|
+
switch (statement.type) {
|
|
6750
|
+
case AST_NODE_TYPES.IfStatement: return isRefInExpression(statement.test, refParams) && (Analyze.isTerminatingStatement(statement.consequent) || statement.alternate != null && Analyze.isTerminatingStatement(statement.alternate));
|
|
6751
|
+
case AST_NODE_TYPES.BlockStatement: return hasRefGatedTerminator(statement.body, refParams);
|
|
6752
|
+
case AST_NODE_TYPES.TryStatement:
|
|
6753
|
+
if (statement.finalizer != null && hasRefGatedTerminator(statement.finalizer.body, refParams)) return true;
|
|
6754
|
+
if (statement.handler != null && !Analyze.isTerminatingStatement(statement.handler.body)) return false;
|
|
6755
|
+
return hasRefGatedTerminator(statement.block.body, refParams);
|
|
6756
|
+
default: return false;
|
|
6757
|
+
}
|
|
6758
|
+
}
|
|
6759
|
+
function hasRefGatedEarlyExit(statements, child, refParams) {
|
|
6760
|
+
const index = statements.findIndex((statement) => statement === child);
|
|
6761
|
+
if (index < 0) return false;
|
|
6762
|
+
for (let i = 0; i < index; i++) {
|
|
6763
|
+
const statement = statements[i];
|
|
6764
|
+
if (statement != null && isRefGatedTerminator(statement, refParams)) return true;
|
|
6765
|
+
}
|
|
6766
|
+
return false;
|
|
6767
|
+
}
|
|
6646
6768
|
function isRefGatedContext(node, refParams) {
|
|
6647
6769
|
let child = node;
|
|
6648
6770
|
let current = node.parent;
|
|
@@ -6656,24 +6778,22 @@ function createSetStateResolver$1(context, facts = EMPTY_FACTS) {
|
|
|
6656
6778
|
case AST_NODE_TYPES.LogicalExpression:
|
|
6657
6779
|
if (child === current.right && isRefInExpression(current.left, refParams)) return true;
|
|
6658
6780
|
break;
|
|
6659
|
-
case AST_NODE_TYPES.
|
|
6660
|
-
|
|
6661
|
-
for (const statement of current.body.slice(0, Math.max(0, index))) {
|
|
6662
|
-
if (statement.type !== AST_NODE_TYPES.IfStatement) continue;
|
|
6663
|
-
if (!isRefInExpression(statement.test, refParams)) continue;
|
|
6664
|
-
if (isTerminatingStatement(statement.consequent)) return true;
|
|
6665
|
-
}
|
|
6781
|
+
case AST_NODE_TYPES.WhileStatement:
|
|
6782
|
+
if (child === current.body && isRefInExpression(current.test, refParams)) return true;
|
|
6666
6783
|
break;
|
|
6667
|
-
|
|
6784
|
+
case AST_NODE_TYPES.ForStatement:
|
|
6785
|
+
if ((child === current.body || child === current.update) && current.test != null && isRefInExpression(current.test, refParams)) return true;
|
|
6786
|
+
break;
|
|
6787
|
+
case AST_NODE_TYPES.BlockStatement:
|
|
6788
|
+
if (hasRefGatedEarlyExit(current.body, child, refParams)) return true;
|
|
6789
|
+
break;
|
|
6790
|
+
case AST_NODE_TYPES.SwitchCase: if (hasRefGatedEarlyExit(current.consequent, child, refParams)) return true;
|
|
6668
6791
|
}
|
|
6669
6792
|
child = current;
|
|
6670
6793
|
current = current.parent;
|
|
6671
6794
|
}
|
|
6672
6795
|
return false;
|
|
6673
6796
|
}
|
|
6674
|
-
function isParameterId(id) {
|
|
6675
|
-
return findVariable(context.sourceCode.getScope(id), id)?.defs.some((d) => d.type === DefinitionType.Parameter) ?? false;
|
|
6676
|
-
}
|
|
6677
6797
|
return {
|
|
6678
6798
|
getRefDerivedParams,
|
|
6679
6799
|
getSetterName,
|
|
@@ -6703,24 +6823,24 @@ function inferViolations$2(context, facts) {
|
|
|
6703
6823
|
visited.add(key);
|
|
6704
6824
|
queue.push(state);
|
|
6705
6825
|
};
|
|
6706
|
-
const report = (
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6826
|
+
const report = (setter, reportNode) => {
|
|
6827
|
+
const name = resolver.getSetterName(setter.node);
|
|
6828
|
+
const key = `${String(reportNode.range[0])}:${String(reportNode.range[1])}:${name}`;
|
|
6829
|
+
getOrInsertComputed(violations, key, () => ({
|
|
6830
|
+
name,
|
|
6710
6831
|
node: reportNode
|
|
6711
|
-
});
|
|
6832
|
+
}));
|
|
6712
6833
|
};
|
|
6713
6834
|
const isExemptCall = (call, state) => {
|
|
6714
6835
|
if (state.inheritedRefGate || resolver.isRefGatedContext(call, state.refParams)) return true;
|
|
6715
|
-
|
|
6716
|
-
return argument != null && resolver.isArgumentUsingRefValue(argument, state.refParams);
|
|
6836
|
+
return call.arguments.some((argument) => resolver.isArgumentUsingRefValue(argument, state.refParams));
|
|
6717
6837
|
};
|
|
6718
6838
|
for (const root of [...facts.effectRoots].sort((a, b) => a.node.range[0] - b.node.range[0])) {
|
|
6719
6839
|
const setup = root.setup;
|
|
6720
6840
|
const unwrappedSetup = Extract.unwrap(setup);
|
|
6721
6841
|
for (const target of resolver.resolveValues(setup)) {
|
|
6722
6842
|
if (target.kind === "setter") {
|
|
6723
|
-
if (!resolver.isRefGatedContext(setup)) report(target
|
|
6843
|
+
if (!resolver.isRefGatedContext(setup)) report(target, setup);
|
|
6724
6844
|
continue;
|
|
6725
6845
|
}
|
|
6726
6846
|
const reportNode = unwrappedSetup === target.node ? null : setup;
|
|
@@ -6738,7 +6858,7 @@ function inferViolations$2(context, facts) {
|
|
|
6738
6858
|
const calls = callsByFunction.get(state.fn) ?? [];
|
|
6739
6859
|
for (const call of calls) for (const target of resolver.resolveValues(call.callee)) {
|
|
6740
6860
|
if (target.kind === "setter") {
|
|
6741
|
-
if (!isExemptCall(call, state)) report(
|
|
6861
|
+
if (!isExemptCall(call, state)) report(target, state.reportNode ?? call);
|
|
6742
6862
|
continue;
|
|
6743
6863
|
}
|
|
6744
6864
|
enqueue({
|
|
@@ -7160,12 +7280,12 @@ function createFactCollector(isUseMemoCall) {
|
|
|
7160
7280
|
Traverse.simpleTraverse(callback.body, { enter(node) {
|
|
7161
7281
|
switch (node.type) {
|
|
7162
7282
|
case AST_NODE_TYPES.AssignmentExpression:
|
|
7163
|
-
for (const target of
|
|
7283
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
7164
7284
|
return;
|
|
7165
7285
|
case AST_NODE_TYPES.ForInStatement:
|
|
7166
7286
|
case AST_NODE_TYPES.ForOfStatement:
|
|
7167
7287
|
if (node.left.type === AST_NODE_TYPES.VariableDeclaration) return;
|
|
7168
|
-
for (const target of
|
|
7288
|
+
for (const target of resolveAssignmentTargets(node.left)) pushWrite(node, target);
|
|
7169
7289
|
return;
|
|
7170
7290
|
}
|
|
7171
7291
|
} });
|
|
@@ -7277,48 +7397,43 @@ const LAZY_INIT_ALLOW_LIST = [
|
|
|
7277
7397
|
"String",
|
|
7278
7398
|
"Number"
|
|
7279
7399
|
];
|
|
7280
|
-
// src/rules/use-state/use-state.ts
|
|
7281
|
-
const RULE_NAME = "use-state";
|
|
7282
|
-
const defaultOptions = [{
|
|
7283
|
-
enforceAssignment: true,
|
|
7284
|
-
enforceLazyInitialization: true,
|
|
7285
|
-
enforceSetterName: true
|
|
7286
|
-
}];
|
|
7287
|
-
const schema = [{
|
|
7288
|
-
type: "object",
|
|
7289
|
-
additionalProperties: false,
|
|
7290
|
-
properties: {
|
|
7291
|
-
enforceAssignment: {
|
|
7292
|
-
type: "boolean",
|
|
7293
|
-
default: true
|
|
7294
|
-
},
|
|
7295
|
-
enforceLazyInitialization: {
|
|
7296
|
-
type: "boolean",
|
|
7297
|
-
default: true
|
|
7298
|
-
},
|
|
7299
|
-
enforceSetterName: {
|
|
7300
|
-
type: "boolean",
|
|
7301
|
-
default: true
|
|
7302
|
-
}
|
|
7303
|
-
}
|
|
7304
|
-
}];
|
|
7305
7400
|
var use_state_default = createRule({
|
|
7306
7401
|
meta: {
|
|
7307
7402
|
type: "suggestion",
|
|
7308
|
-
defaultOptions: [
|
|
7403
|
+
defaultOptions: [{}],
|
|
7309
7404
|
docs: { description: "Enforces correct usage of 'useState', including destructuring, symmetric naming of the value and setter, and wrapping expensive initializers in a lazy initializer function." },
|
|
7310
7405
|
messages: {
|
|
7311
7406
|
"invalid-initialization": "To prevent re-computation, consider using lazy initial state for useState calls that involve function calls. Ex: 'useState(() => getValue())'.",
|
|
7312
7407
|
"invalid-assignment": "useState should be destructured into a value and setter pair, e.g., const [state, setState] = useState(...).",
|
|
7313
7408
|
"invalid-setter-name": "The setter should be named 'set' followed by the capitalized state variable name, e.g., 'setState' for 'state'."
|
|
7314
7409
|
},
|
|
7315
|
-
schema
|
|
7410
|
+
schema: [{
|
|
7411
|
+
type: "object",
|
|
7412
|
+
additionalProperties: false,
|
|
7413
|
+
properties: {
|
|
7414
|
+
enforceAssignment: {
|
|
7415
|
+
type: "boolean",
|
|
7416
|
+
description: "Require the useState result to be assigned to a destructured value/setter pair."
|
|
7417
|
+
},
|
|
7418
|
+
enforceLazyInitialization: {
|
|
7419
|
+
type: "boolean",
|
|
7420
|
+
description: "Require expensive initializers to be wrapped in a lazy initializer function."
|
|
7421
|
+
},
|
|
7422
|
+
enforceSetterName: {
|
|
7423
|
+
type: "boolean",
|
|
7424
|
+
description: "Require the setter name to match the state value name."
|
|
7425
|
+
}
|
|
7426
|
+
}
|
|
7427
|
+
}]
|
|
7316
7428
|
},
|
|
7317
|
-
name:
|
|
7429
|
+
name: "use-state",
|
|
7318
7430
|
create
|
|
7319
7431
|
});
|
|
7320
7432
|
function create(context) {
|
|
7321
|
-
const
|
|
7433
|
+
const options = context.options[0] ?? {};
|
|
7434
|
+
const enforceAssignment = options.enforceAssignment ?? true;
|
|
7435
|
+
const enforceLazyInitialization = options.enforceLazyInitialization ?? true;
|
|
7436
|
+
const enforceSetterName = options.enforceSetterName ?? true;
|
|
7322
7437
|
const { additionalStateHooks } = getSettingsFromContext(context);
|
|
7323
7438
|
return { CallExpression(node) {
|
|
7324
7439
|
if (!core.isUseStateLikeCall(node, additionalStateHooks)) return;
|
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.20",
|
|
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,17 +36,17 @@
|
|
|
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.
|
|
45
|
-
"@typescript-eslint/scope-manager": "^8.72.
|
|
46
|
-
"@typescript-eslint/types": "^8.72.
|
|
47
|
-
"@typescript-eslint/utils": "^8.72.
|
|
39
|
+
"@eslint-react/ast": "5.30.0-beta.20",
|
|
40
|
+
"@eslint-react/core": "5.30.0-beta.20",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.20",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.20",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.20",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.20",
|
|
45
|
+
"@typescript-eslint/scope-manager": "^8.72.1",
|
|
46
|
+
"@typescript-eslint/types": "^8.72.1",
|
|
47
|
+
"@typescript-eslint/utils": "^8.72.1",
|
|
48
48
|
"compare-versions": "^6.1.1",
|
|
49
|
-
"string-ts": "^2.
|
|
49
|
+
"string-ts": "^2.4.0",
|
|
50
50
|
"ts-api-utils": "^2.5.0",
|
|
51
51
|
"ts-pattern": "^5.9.2"
|
|
52
52
|
},
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"@types/react": "^19.3.0",
|
|
61
61
|
"@types/react-dom": "^19.3.0",
|
|
62
62
|
"dedent": "^1.7.2",
|
|
63
|
-
"eslint": "^10.
|
|
63
|
+
"eslint": "^10.14.0",
|
|
64
64
|
"react": "^19.3.1",
|
|
65
65
|
"react-dom": "^19.3.1",
|
|
66
|
-
"tsdown": "^0.23.
|
|
66
|
+
"tsdown": "^0.23.4",
|
|
67
67
|
"tsl": "^1.0.30",
|
|
68
|
-
"tsl-dx": "^0.15.
|
|
68
|
+
"tsl-dx": "^0.15.1",
|
|
69
69
|
"typescript": "6.0.3"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|