eslint-plugin-react-x 1.24.0-beta.0 → 1.24.0-beta.1
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 +45 -41
- package/dist/index.mjs +45 -41
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -42,7 +42,7 @@ var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
|
42
42
|
|
|
43
43
|
// package.json
|
|
44
44
|
var name = "eslint-plugin-react-x";
|
|
45
|
-
var version = "1.24.0-beta.
|
|
45
|
+
var version = "1.24.0-beta.1";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -221,15 +221,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
221
221
|
if (!AST11__namespace.isThisExpression(node.object)) {
|
|
222
222
|
return;
|
|
223
223
|
}
|
|
224
|
-
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
224
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
225
225
|
if (currClass == null || !isComponent) {
|
|
226
226
|
return;
|
|
227
227
|
}
|
|
228
|
-
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
228
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
229
229
|
if (currMethod == null || isStatic) {
|
|
230
230
|
return;
|
|
231
231
|
}
|
|
232
|
-
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
232
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
233
233
|
if (setState == null || hasThisState) {
|
|
234
234
|
return;
|
|
235
235
|
}
|
|
@@ -251,15 +251,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
251
251
|
methodEntries.pop();
|
|
252
252
|
},
|
|
253
253
|
VariableDeclarator(node) {
|
|
254
|
-
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
254
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
255
255
|
if (currClass == null || !isComponent) {
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
|
-
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
258
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
259
259
|
if (currMethod == null || isStatic) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
262
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
263
263
|
if (setState == null || hasThisState) {
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
@@ -615,7 +615,7 @@ var no_children_prop_default = createRule({
|
|
|
615
615
|
context.sourceCode.getScope(node),
|
|
616
616
|
node.openingElement.attributes
|
|
617
617
|
);
|
|
618
|
-
if (prop) {
|
|
618
|
+
if (prop != null) {
|
|
619
619
|
context.report({
|
|
620
620
|
messageId: "noChildrenProp",
|
|
621
621
|
node: prop
|
|
@@ -1063,7 +1063,7 @@ var no_create_ref_default = createRule({
|
|
|
1063
1063
|
create(context) {
|
|
1064
1064
|
return {
|
|
1065
1065
|
CallExpression(node) {
|
|
1066
|
-
if (core.isCreateRefCall(node, context) &&
|
|
1066
|
+
if (core.isCreateRefCall(node, context) && AST11__namespace.findParentNode(node, core.isClassComponent) == null) {
|
|
1067
1067
|
context.report({ messageId: "noCreateRef", node });
|
|
1068
1068
|
}
|
|
1069
1069
|
}
|
|
@@ -1109,7 +1109,7 @@ var no_default_props_default = createRule({
|
|
|
1109
1109
|
}
|
|
1110
1110
|
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1111
1111
|
const variableNode = VAR__namespace.getVariableNode(variable, 0);
|
|
1112
|
-
if (variableNode
|
|
1112
|
+
if (variableNode == null) return;
|
|
1113
1113
|
if (!AST11__namespace.isFunction(variableNode) && !core.isClassComponent(variableNode)) return;
|
|
1114
1114
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1115
1115
|
},
|
|
@@ -1178,7 +1178,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1178
1178
|
types.AST_NODE_TYPES.ClassExpression
|
|
1179
1179
|
])
|
|
1180
1180
|
);
|
|
1181
|
-
if (
|
|
1181
|
+
if (parentClass == null) return;
|
|
1182
1182
|
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNodeGuard(node, isConstructorFunction)) {
|
|
1183
1183
|
context.report({
|
|
1184
1184
|
messageId: "noDirectMutationState",
|
|
@@ -1281,9 +1281,10 @@ var no_duplicate_key_default = createRule({
|
|
|
1281
1281
|
}
|
|
1282
1282
|
default: {
|
|
1283
1283
|
const call = AST11__namespace.findParentNodeGuard(jsxElement, AST11__namespace.isMapCallLoose);
|
|
1284
|
-
const iter =
|
|
1284
|
+
const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
|
|
1285
|
+
if (!AST11__namespace.isFunction(iter)) return;
|
|
1285
1286
|
const arg0 = call?.arguments[0];
|
|
1286
|
-
if (
|
|
1287
|
+
if (call == null || arg0 == null) return;
|
|
1287
1288
|
if (AST11__namespace.unwrapTypeExpression(arg0) !== iter) {
|
|
1288
1289
|
return;
|
|
1289
1290
|
}
|
|
@@ -1447,7 +1448,7 @@ var no_implicit_key_default = createRule({
|
|
|
1447
1448
|
const keyPropOnElement = node.attributes.some(
|
|
1448
1449
|
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1449
1450
|
);
|
|
1450
|
-
if (keyPropFound && !keyPropOnElement) {
|
|
1451
|
+
if (keyPropFound != null && !keyPropOnElement) {
|
|
1451
1452
|
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1452
1453
|
}
|
|
1453
1454
|
}
|
|
@@ -1544,7 +1545,7 @@ function isInitExpression(node) {
|
|
|
1544
1545
|
}
|
|
1545
1546
|
function getVariableInitExpression(variable, at) {
|
|
1546
1547
|
const def = variable?.defs[at];
|
|
1547
|
-
if (def?.node
|
|
1548
|
+
if (def?.node == null || !("init" in def.node)) {
|
|
1548
1549
|
return eff._;
|
|
1549
1550
|
}
|
|
1550
1551
|
return isInitExpression(def.node.init) ? def.node.init : eff._;
|
|
@@ -1581,7 +1582,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1581
1582
|
];
|
|
1582
1583
|
const services = utils.ESLintUtils.getParserServices(context, false);
|
|
1583
1584
|
function getReportDescriptor(node) {
|
|
1584
|
-
if (node
|
|
1585
|
+
if (node == null) return eff._;
|
|
1585
1586
|
return tsPattern.match(node).when(AST11__namespace.isJSX, () => eff._).with({ type: types.AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1586
1587
|
const isLeftUnaryNot = left.type === types.AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1587
1588
|
if (isLeftUnaryNot) {
|
|
@@ -1617,7 +1618,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1617
1618
|
}
|
|
1618
1619
|
const visitorFunction = (node) => {
|
|
1619
1620
|
const descriptor = getReportDescriptor(node);
|
|
1620
|
-
if (descriptor
|
|
1621
|
+
if (descriptor == null) return;
|
|
1621
1622
|
context.report(descriptor);
|
|
1622
1623
|
};
|
|
1623
1624
|
return {
|
|
@@ -1655,13 +1656,13 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1655
1656
|
const components = ctx.getAllComponents(node);
|
|
1656
1657
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1657
1658
|
const isMemoOrForwardRef = (flag & (core.ERFunctionComponentFlag.ForwardRef | core.ERFunctionComponentFlag.Memo)) > 0n;
|
|
1658
|
-
if (AST11__namespace.getFunctionIdentifier(node2)) {
|
|
1659
|
+
if (AST11__namespace.getFunctionIdentifier(node2) != null) {
|
|
1659
1660
|
continue;
|
|
1660
1661
|
}
|
|
1661
1662
|
if (!isMemoOrForwardRef) {
|
|
1662
1663
|
continue;
|
|
1663
1664
|
}
|
|
1664
|
-
if (
|
|
1665
|
+
if (displayName == null) {
|
|
1665
1666
|
context.report({
|
|
1666
1667
|
messageId: "noMissingComponentDisplayName",
|
|
1667
1668
|
node: node2
|
|
@@ -1860,7 +1861,7 @@ var no_nested_components_default = createRule({
|
|
|
1860
1861
|
continue;
|
|
1861
1862
|
}
|
|
1862
1863
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1863
|
-
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute ||
|
|
1864
|
+
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.findParentProp(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1864
1865
|
if (isInsideJSXPropValue) {
|
|
1865
1866
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1866
1867
|
context.report({
|
|
@@ -1884,7 +1885,7 @@ var no_nested_components_default = createRule({
|
|
|
1884
1885
|
continue;
|
|
1885
1886
|
}
|
|
1886
1887
|
const parentComponent = AST11__namespace.findParentNodeGuard(component, isFunctionComponent);
|
|
1887
|
-
const isParnetComponentNotDirectValueOfRenderProperty =
|
|
1888
|
+
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1888
1889
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1889
1890
|
context.report({
|
|
1890
1891
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
@@ -1906,7 +1907,7 @@ var no_nested_components_default = createRule({
|
|
|
1906
1907
|
}
|
|
1907
1908
|
}
|
|
1908
1909
|
for (const { name: name2 = "unknown", node: component } of classComponents) {
|
|
1909
|
-
if (
|
|
1910
|
+
if (AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
1910
1911
|
continue;
|
|
1911
1912
|
}
|
|
1912
1913
|
context.report({
|
|
@@ -1959,8 +1960,8 @@ var no_prop_types_default = createRule({
|
|
|
1959
1960
|
return;
|
|
1960
1961
|
}
|
|
1961
1962
|
const variable = VAR__namespace.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1962
|
-
const variableNode =
|
|
1963
|
-
if (variableNode && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
1963
|
+
const variableNode = VAR__namespace.getVariableNode(variable, 0);
|
|
1964
|
+
if (variableNode != null && (AST11__namespace.isFunction(variableNode) || core.isClassComponent(variableNode))) {
|
|
1964
1965
|
context.report({ messageId: "noPropTypes", node: property });
|
|
1965
1966
|
}
|
|
1966
1967
|
},
|
|
@@ -2058,10 +2059,11 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2058
2059
|
return;
|
|
2059
2060
|
}
|
|
2060
2061
|
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2061
|
-
const method =
|
|
2062
|
-
|
|
2062
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2063
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2064
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2063
2065
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2064
|
-
if (
|
|
2066
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2065
2067
|
context.report({
|
|
2066
2068
|
messageId: "noSetStateInComponentDidMount",
|
|
2067
2069
|
node
|
|
@@ -2102,10 +2104,11 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2102
2104
|
return;
|
|
2103
2105
|
}
|
|
2104
2106
|
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2105
|
-
const method =
|
|
2106
|
-
|
|
2107
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2108
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2109
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2107
2110
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2108
|
-
if (
|
|
2111
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2109
2112
|
context.report({
|
|
2110
2113
|
messageId: "noSetStateInComponentDidUpdate",
|
|
2111
2114
|
node
|
|
@@ -2146,10 +2149,11 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2146
2149
|
return;
|
|
2147
2150
|
}
|
|
2148
2151
|
const clazz = AST11__namespace.findParentNodeGuard(node, core.isClassComponent);
|
|
2149
|
-
const method =
|
|
2150
|
-
|
|
2152
|
+
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2153
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2154
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2151
2155
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2152
|
-
if (
|
|
2156
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2153
2157
|
context.report({
|
|
2154
2158
|
messageId: "noSetStateInComponentWillUpdate",
|
|
2155
2159
|
node
|
|
@@ -2374,17 +2378,17 @@ var no_unstable_context_value_default = createRule({
|
|
|
2374
2378
|
return;
|
|
2375
2379
|
}
|
|
2376
2380
|
const functionEntry = ctx.getCurrentEntry();
|
|
2377
|
-
if (functionEntry
|
|
2381
|
+
if (functionEntry == null) return;
|
|
2378
2382
|
const attribute = node.attributes.find(
|
|
2379
2383
|
(attribute2) => attribute2.type === types.AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2380
2384
|
);
|
|
2381
|
-
if (attribute
|
|
2385
|
+
if (attribute == null || !("value" in attribute)) return;
|
|
2382
2386
|
const value = attribute.value;
|
|
2383
2387
|
if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2384
2388
|
const valueExpression = value.expression;
|
|
2385
2389
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2386
2390
|
const construction = VAR__namespace.getValueConstruction(valueExpression, initialScope);
|
|
2387
|
-
if (construction
|
|
2391
|
+
if (construction == null) return;
|
|
2388
2392
|
if (core.isReactHookCall(construction.node)) {
|
|
2389
2393
|
return;
|
|
2390
2394
|
}
|
|
@@ -2456,7 +2460,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2456
2460
|
initialScope,
|
|
2457
2461
|
VAR__namespace.ValueConstructionHint.StrictCallExpression
|
|
2458
2462
|
);
|
|
2459
|
-
if (construction
|
|
2463
|
+
if (construction == null) {
|
|
2460
2464
|
continue;
|
|
2461
2465
|
}
|
|
2462
2466
|
if (core.isReactHookCall(construction.node)) {
|
|
@@ -2475,7 +2479,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2475
2479
|
},
|
|
2476
2480
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2477
2481
|
const functionEntry = ctx.getCurrentEntry();
|
|
2478
|
-
if (
|
|
2482
|
+
if (functionEntry == null) return;
|
|
2479
2483
|
const prevs = declarators.get(functionEntry.node) ?? [];
|
|
2480
2484
|
declarators.set(functionEntry.node, [...prevs, node]);
|
|
2481
2485
|
}
|
|
@@ -2703,8 +2707,8 @@ var no_unused_state_default = createRule({
|
|
|
2703
2707
|
return;
|
|
2704
2708
|
}
|
|
2705
2709
|
const className = AST11__namespace.getClassIdentifier(currentClass)?.name;
|
|
2706
|
-
const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
|
|
2707
|
-
if (
|
|
2710
|
+
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2711
|
+
if (defNode == null || isUsed) {
|
|
2708
2712
|
return;
|
|
2709
2713
|
}
|
|
2710
2714
|
context.report({
|
|
@@ -2947,7 +2951,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2947
2951
|
return false;
|
|
2948
2952
|
}
|
|
2949
2953
|
const id = AST11__namespace.getFunctionIdentifier(block);
|
|
2950
|
-
return
|
|
2954
|
+
return id != null && core.isComponentName(id.name) && components.some((component) => component.node === block);
|
|
2951
2955
|
}
|
|
2952
2956
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
2953
2957
|
let scope = initialScope;
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReado
|
|
|
15
15
|
|
|
16
16
|
// package.json
|
|
17
17
|
var name = "eslint-plugin-react-x";
|
|
18
|
-
var version = "1.24.0-beta.
|
|
18
|
+
var version = "1.24.0-beta.1";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -194,15 +194,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
194
194
|
if (!AST11.isThisExpression(node.object)) {
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
|
-
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
197
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
198
198
|
if (currClass == null || !isComponent) {
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
|
-
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
201
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
202
202
|
if (currMethod == null || isStatic) {
|
|
203
203
|
return;
|
|
204
204
|
}
|
|
205
|
-
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
205
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
206
206
|
if (setState == null || hasThisState) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
@@ -224,15 +224,15 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
224
224
|
methodEntries.pop();
|
|
225
225
|
},
|
|
226
226
|
VariableDeclarator(node) {
|
|
227
|
-
const [currClass, isComponent] = classEntries.at(-1) ?? [];
|
|
227
|
+
const [currClass, isComponent = false] = classEntries.at(-1) ?? [];
|
|
228
228
|
if (currClass == null || !isComponent) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
|
-
const [currMethod, isStatic] = methodEntries.at(-1) ?? [];
|
|
231
|
+
const [currMethod, isStatic = false] = methodEntries.at(-1) ?? [];
|
|
232
232
|
if (currMethod == null || isStatic) {
|
|
233
233
|
return;
|
|
234
234
|
}
|
|
235
|
-
const [setState, hasThisState] = setStateEntries.at(-1) ?? [];
|
|
235
|
+
const [setState, hasThisState = false] = setStateEntries.at(-1) ?? [];
|
|
236
236
|
if (setState == null || hasThisState) {
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
@@ -588,7 +588,7 @@ var no_children_prop_default = createRule({
|
|
|
588
588
|
context.sourceCode.getScope(node),
|
|
589
589
|
node.openingElement.attributes
|
|
590
590
|
);
|
|
591
|
-
if (prop) {
|
|
591
|
+
if (prop != null) {
|
|
592
592
|
context.report({
|
|
593
593
|
messageId: "noChildrenProp",
|
|
594
594
|
node: prop
|
|
@@ -1036,7 +1036,7 @@ var no_create_ref_default = createRule({
|
|
|
1036
1036
|
create(context) {
|
|
1037
1037
|
return {
|
|
1038
1038
|
CallExpression(node) {
|
|
1039
|
-
if (isCreateRefCall(node, context) &&
|
|
1039
|
+
if (isCreateRefCall(node, context) && AST11.findParentNode(node, isClassComponent) == null) {
|
|
1040
1040
|
context.report({ messageId: "noCreateRef", node });
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
@@ -1082,7 +1082,7 @@ var no_default_props_default = createRule({
|
|
|
1082
1082
|
}
|
|
1083
1083
|
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1084
1084
|
const variableNode = VAR.getVariableNode(variable, 0);
|
|
1085
|
-
if (variableNode
|
|
1085
|
+
if (variableNode == null) return;
|
|
1086
1086
|
if (!AST11.isFunction(variableNode) && !isClassComponent(variableNode)) return;
|
|
1087
1087
|
context.report({ messageId: "noDefaultProps", node: property });
|
|
1088
1088
|
},
|
|
@@ -1151,7 +1151,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1151
1151
|
AST_NODE_TYPES.ClassExpression
|
|
1152
1152
|
])
|
|
1153
1153
|
);
|
|
1154
|
-
if (
|
|
1154
|
+
if (parentClass == null) return;
|
|
1155
1155
|
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNodeGuard(node, isConstructorFunction)) {
|
|
1156
1156
|
context.report({
|
|
1157
1157
|
messageId: "noDirectMutationState",
|
|
@@ -1254,9 +1254,10 @@ var no_duplicate_key_default = createRule({
|
|
|
1254
1254
|
}
|
|
1255
1255
|
default: {
|
|
1256
1256
|
const call = AST11.findParentNodeGuard(jsxElement, AST11.isMapCallLoose);
|
|
1257
|
-
const iter =
|
|
1257
|
+
const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
|
|
1258
|
+
if (!AST11.isFunction(iter)) return;
|
|
1258
1259
|
const arg0 = call?.arguments[0];
|
|
1259
|
-
if (
|
|
1260
|
+
if (call == null || arg0 == null) return;
|
|
1260
1261
|
if (AST11.unwrapTypeExpression(arg0) !== iter) {
|
|
1261
1262
|
return;
|
|
1262
1263
|
}
|
|
@@ -1420,7 +1421,7 @@ var no_implicit_key_default = createRule({
|
|
|
1420
1421
|
const keyPropOnElement = node.attributes.some(
|
|
1421
1422
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1422
1423
|
);
|
|
1423
|
-
if (keyPropFound && !keyPropOnElement) {
|
|
1424
|
+
if (keyPropFound != null && !keyPropOnElement) {
|
|
1424
1425
|
context.report({ messageId: "noImplicitKey", node: keyPropFound });
|
|
1425
1426
|
}
|
|
1426
1427
|
}
|
|
@@ -1517,7 +1518,7 @@ function isInitExpression(node) {
|
|
|
1517
1518
|
}
|
|
1518
1519
|
function getVariableInitExpression(variable, at) {
|
|
1519
1520
|
const def = variable?.defs[at];
|
|
1520
|
-
if (def?.node
|
|
1521
|
+
if (def?.node == null || !("init" in def.node)) {
|
|
1521
1522
|
return _;
|
|
1522
1523
|
}
|
|
1523
1524
|
return isInitExpression(def.node.init) ? def.node.init : _;
|
|
@@ -1554,7 +1555,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1554
1555
|
];
|
|
1555
1556
|
const services = ESLintUtils.getParserServices(context, false);
|
|
1556
1557
|
function getReportDescriptor(node) {
|
|
1557
|
-
if (node
|
|
1558
|
+
if (node == null) return _;
|
|
1558
1559
|
return match(node).when(AST11.isJSX, () => _).with({ type: AST_NODE_TYPES.LogicalExpression, operator: "&&" }, ({ left, right }) => {
|
|
1559
1560
|
const isLeftUnaryNot = left.type === AST_NODE_TYPES.UnaryExpression && left.operator === "!";
|
|
1560
1561
|
if (isLeftUnaryNot) {
|
|
@@ -1590,7 +1591,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1590
1591
|
}
|
|
1591
1592
|
const visitorFunction = (node) => {
|
|
1592
1593
|
const descriptor = getReportDescriptor(node);
|
|
1593
|
-
if (descriptor
|
|
1594
|
+
if (descriptor == null) return;
|
|
1594
1595
|
context.report(descriptor);
|
|
1595
1596
|
};
|
|
1596
1597
|
return {
|
|
@@ -1628,13 +1629,13 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1628
1629
|
const components = ctx.getAllComponents(node);
|
|
1629
1630
|
for (const { node: node2, displayName, flag } of components.values()) {
|
|
1630
1631
|
const isMemoOrForwardRef = (flag & (ERFunctionComponentFlag.ForwardRef | ERFunctionComponentFlag.Memo)) > 0n;
|
|
1631
|
-
if (AST11.getFunctionIdentifier(node2)) {
|
|
1632
|
+
if (AST11.getFunctionIdentifier(node2) != null) {
|
|
1632
1633
|
continue;
|
|
1633
1634
|
}
|
|
1634
1635
|
if (!isMemoOrForwardRef) {
|
|
1635
1636
|
continue;
|
|
1636
1637
|
}
|
|
1637
|
-
if (
|
|
1638
|
+
if (displayName == null) {
|
|
1638
1639
|
context.report({
|
|
1639
1640
|
messageId: "noMissingComponentDisplayName",
|
|
1640
1641
|
node: node2
|
|
@@ -1833,7 +1834,7 @@ var no_nested_components_default = createRule({
|
|
|
1833
1834
|
continue;
|
|
1834
1835
|
}
|
|
1835
1836
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1836
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute ||
|
|
1837
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentProp(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1837
1838
|
if (isInsideJSXPropValue) {
|
|
1838
1839
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1839
1840
|
context.report({
|
|
@@ -1857,7 +1858,7 @@ var no_nested_components_default = createRule({
|
|
|
1857
1858
|
continue;
|
|
1858
1859
|
}
|
|
1859
1860
|
const parentComponent = AST11.findParentNodeGuard(component, isFunctionComponent);
|
|
1860
|
-
const isParnetComponentNotDirectValueOfRenderProperty =
|
|
1861
|
+
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1861
1862
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1862
1863
|
context.report({
|
|
1863
1864
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
@@ -1879,7 +1880,7 @@ var no_nested_components_default = createRule({
|
|
|
1879
1880
|
}
|
|
1880
1881
|
}
|
|
1881
1882
|
for (const { name: name2 = "unknown", node: component } of classComponents) {
|
|
1882
|
-
if (
|
|
1883
|
+
if (AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
1883
1884
|
continue;
|
|
1884
1885
|
}
|
|
1885
1886
|
context.report({
|
|
@@ -1932,8 +1933,8 @@ var no_prop_types_default = createRule({
|
|
|
1932
1933
|
return;
|
|
1933
1934
|
}
|
|
1934
1935
|
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
|
|
1935
|
-
const variableNode =
|
|
1936
|
-
if (variableNode && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
|
|
1936
|
+
const variableNode = VAR.getVariableNode(variable, 0);
|
|
1937
|
+
if (variableNode != null && (AST11.isFunction(variableNode) || isClassComponent(variableNode))) {
|
|
1937
1938
|
context.report({ messageId: "noPropTypes", node: property });
|
|
1938
1939
|
}
|
|
1939
1940
|
},
|
|
@@ -2031,10 +2032,11 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2031
2032
|
return;
|
|
2032
2033
|
}
|
|
2033
2034
|
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2034
|
-
const method =
|
|
2035
|
-
|
|
2035
|
+
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2036
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2037
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2036
2038
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2037
|
-
if (
|
|
2039
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2038
2040
|
context.report({
|
|
2039
2041
|
messageId: "noSetStateInComponentDidMount",
|
|
2040
2042
|
node
|
|
@@ -2075,10 +2077,11 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2075
2077
|
return;
|
|
2076
2078
|
}
|
|
2077
2079
|
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2078
|
-
const method =
|
|
2079
|
-
|
|
2080
|
+
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2081
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2082
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2080
2083
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2081
|
-
if (
|
|
2084
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2082
2085
|
context.report({
|
|
2083
2086
|
messageId: "noSetStateInComponentDidUpdate",
|
|
2084
2087
|
node
|
|
@@ -2119,10 +2122,11 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2119
2122
|
return;
|
|
2120
2123
|
}
|
|
2121
2124
|
const clazz = AST11.findParentNodeGuard(node, isClassComponent);
|
|
2122
|
-
const method =
|
|
2123
|
-
|
|
2125
|
+
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2126
|
+
if (clazz == null || method == null || method === clazz) return;
|
|
2127
|
+
const methodScope = context.sourceCode.getScope(method);
|
|
2124
2128
|
const upperScope = context.sourceCode.getScope(node).upper;
|
|
2125
|
-
if (
|
|
2129
|
+
if (method.parent === clazz.body && upperScope === methodScope) {
|
|
2126
2130
|
context.report({
|
|
2127
2131
|
messageId: "noSetStateInComponentWillUpdate",
|
|
2128
2132
|
node
|
|
@@ -2347,17 +2351,17 @@ var no_unstable_context_value_default = createRule({
|
|
|
2347
2351
|
return;
|
|
2348
2352
|
}
|
|
2349
2353
|
const functionEntry = ctx.getCurrentEntry();
|
|
2350
|
-
if (functionEntry
|
|
2354
|
+
if (functionEntry == null) return;
|
|
2351
2355
|
const attribute = node.attributes.find(
|
|
2352
2356
|
(attribute2) => attribute2.type === AST_NODE_TYPES.JSXAttribute && attribute2.name.name === "value"
|
|
2353
2357
|
);
|
|
2354
|
-
if (attribute
|
|
2358
|
+
if (attribute == null || !("value" in attribute)) return;
|
|
2355
2359
|
const value = attribute.value;
|
|
2356
2360
|
if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) return;
|
|
2357
2361
|
const valueExpression = value.expression;
|
|
2358
2362
|
const initialScope = context.sourceCode.getScope(valueExpression);
|
|
2359
2363
|
const construction = VAR.getValueConstruction(valueExpression, initialScope);
|
|
2360
|
-
if (construction
|
|
2364
|
+
if (construction == null) return;
|
|
2361
2365
|
if (isReactHookCall(construction.node)) {
|
|
2362
2366
|
return;
|
|
2363
2367
|
}
|
|
@@ -2429,7 +2433,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2429
2433
|
initialScope,
|
|
2430
2434
|
VAR.ValueConstructionHint.StrictCallExpression
|
|
2431
2435
|
);
|
|
2432
|
-
if (construction
|
|
2436
|
+
if (construction == null) {
|
|
2433
2437
|
continue;
|
|
2434
2438
|
}
|
|
2435
2439
|
if (isReactHookCall(construction.node)) {
|
|
@@ -2448,7 +2452,7 @@ var no_unstable_default_props_default = createRule({
|
|
|
2448
2452
|
},
|
|
2449
2453
|
"VariableDeclarator[id.type='ObjectPattern'][init.type='Identifier']"(node) {
|
|
2450
2454
|
const functionEntry = ctx.getCurrentEntry();
|
|
2451
|
-
if (
|
|
2455
|
+
if (functionEntry == null) return;
|
|
2452
2456
|
const prevs = declarators.get(functionEntry.node) ?? [];
|
|
2453
2457
|
declarators.set(functionEntry.node, [...prevs, node]);
|
|
2454
2458
|
}
|
|
@@ -2676,8 +2680,8 @@ var no_unused_state_default = createRule({
|
|
|
2676
2680
|
return;
|
|
2677
2681
|
}
|
|
2678
2682
|
const className = AST11.getClassIdentifier(currentClass)?.name;
|
|
2679
|
-
const { node: defNode, isUsed } = stateDefs.get(currentClass) ?? {};
|
|
2680
|
-
if (
|
|
2683
|
+
const { node: defNode, isUsed = false } = stateDefs.get(currentClass) ?? {};
|
|
2684
|
+
if (defNode == null || isUsed) {
|
|
2681
2685
|
return;
|
|
2682
2686
|
}
|
|
2683
2687
|
context.report({
|
|
@@ -2920,7 +2924,7 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
2920
2924
|
return false;
|
|
2921
2925
|
}
|
|
2922
2926
|
const id = AST11.getFunctionIdentifier(block);
|
|
2923
|
-
return
|
|
2927
|
+
return id != null && isComponentName(id.name) && components.some((component) => component.node === block);
|
|
2924
2928
|
}
|
|
2925
2929
|
for (const [initialScope, memberExpression] of memberExpressionWithNames) {
|
|
2926
2930
|
let scope = initialScope;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.24.0-beta.
|
|
3
|
+
"version": "1.24.0-beta.1",
|
|
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",
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"is-immutable-type": "^5.0.1",
|
|
49
49
|
"string-ts": "^2.2.0",
|
|
50
50
|
"ts-pattern": "^5.6.0",
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/shared": "1.24.0-beta.
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
51
|
+
"@eslint-react/ast": "1.24.0-beta.1",
|
|
52
|
+
"@eslint-react/core": "1.24.0-beta.1",
|
|
53
|
+
"@eslint-react/eff": "1.24.0-beta.1",
|
|
54
|
+
"@eslint-react/jsx": "1.24.0-beta.1",
|
|
55
|
+
"@eslint-react/shared": "1.24.0-beta.1",
|
|
56
|
+
"@eslint-react/types": "1.24.0-beta.1",
|
|
57
|
+
"@eslint-react/var": "1.24.0-beta.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@types/react": "^19.0.
|
|
61
|
-
"@types/react-dom": "^19.0.
|
|
60
|
+
"@types/react": "^19.0.5",
|
|
61
|
+
"@types/react-dom": "^19.0.3",
|
|
62
62
|
"ts-api-utils": "^2.0.0",
|
|
63
63
|
"tsup": "^8.3.5",
|
|
64
64
|
"@workspace/configs": "0.0.0"
|