eslint-plugin-react-x 1.24.0-beta.1 → 1.24.0-beta.16
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 +40 -50
- package/dist/index.mjs +41 -51
- package/package.json +12 -13
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.16";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -72,7 +72,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
72
72
|
messageId: "avoidShorthandBoolean",
|
|
73
73
|
node,
|
|
74
74
|
data: {
|
|
75
|
-
propName: JSX7__namespace.
|
|
75
|
+
propName: JSX7__namespace.getAttributeName(node)
|
|
76
76
|
},
|
|
77
77
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
78
78
|
});
|
|
@@ -301,7 +301,7 @@ function isReactChildrenMethod(name2) {
|
|
|
301
301
|
return reactChildrenMethod.some((method) => method === name2);
|
|
302
302
|
}
|
|
303
303
|
function isUsingReactChildren(node, context) {
|
|
304
|
-
const
|
|
304
|
+
const { importSource = "react" } = shared.unsafeDecodeSettings(context.settings);
|
|
305
305
|
const { callee } = node;
|
|
306
306
|
if (!("property" in callee) || !("object" in callee) || !("name" in callee.property)) {
|
|
307
307
|
return false;
|
|
@@ -314,7 +314,7 @@ function isUsingReactChildren(node, context) {
|
|
|
314
314
|
return true;
|
|
315
315
|
}
|
|
316
316
|
if (callee.object.type === types.AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
317
|
-
return core.isInitializedFromReact(callee.object.object.name,
|
|
317
|
+
return core.isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
318
318
|
}
|
|
319
319
|
return false;
|
|
320
320
|
}
|
|
@@ -610,15 +610,15 @@ var no_children_prop_default = createRule({
|
|
|
610
610
|
create(context) {
|
|
611
611
|
return {
|
|
612
612
|
JSXElement(node) {
|
|
613
|
-
const
|
|
613
|
+
const attribute = JSX7__namespace.getAttribute(
|
|
614
614
|
"children",
|
|
615
|
-
|
|
616
|
-
|
|
615
|
+
node.openingElement.attributes,
|
|
616
|
+
context.sourceCode.getScope(node)
|
|
617
617
|
);
|
|
618
|
-
if (
|
|
618
|
+
if (attribute != null) {
|
|
619
619
|
context.report({
|
|
620
620
|
messageId: "noChildrenProp",
|
|
621
|
-
node:
|
|
621
|
+
node: attribute
|
|
622
622
|
});
|
|
623
623
|
}
|
|
624
624
|
}
|
|
@@ -661,12 +661,6 @@ var RULE_NAME12 = "no-class-component";
|
|
|
661
661
|
var RULE_FEATURES12 = [
|
|
662
662
|
"CHK"
|
|
663
663
|
];
|
|
664
|
-
function isComponentDidCatch(node) {
|
|
665
|
-
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
666
|
-
}
|
|
667
|
-
function isGetDerivedStateFromError(node) {
|
|
668
|
-
return (node.type === types.AST_NODE_TYPES.MethodDefinition || node.type === types.AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === types.AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
669
|
-
}
|
|
670
664
|
var no_class_component_default = createRule({
|
|
671
665
|
meta: {
|
|
672
666
|
type: "problem",
|
|
@@ -690,7 +684,7 @@ var no_class_component_default = createRule({
|
|
|
690
684
|
"Program:exit"(node) {
|
|
691
685
|
const components = ctx.getAllComponents(node);
|
|
692
686
|
for (const { name: name2 = "anonymous", node: component } of components.values()) {
|
|
693
|
-
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
687
|
+
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) {
|
|
694
688
|
continue;
|
|
695
689
|
}
|
|
696
690
|
context.report({
|
|
@@ -1018,7 +1012,7 @@ var no_context_provider_default = createRule({
|
|
|
1018
1012
|
}
|
|
1019
1013
|
return {
|
|
1020
1014
|
JSXElement(node) {
|
|
1021
|
-
const elementName = JSX7__namespace.getElementName(node
|
|
1015
|
+
const elementName = JSX7__namespace.getElementName(node);
|
|
1022
1016
|
if (!elementName.endsWith(".Provider")) {
|
|
1023
1017
|
return;
|
|
1024
1018
|
}
|
|
@@ -1171,7 +1165,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1171
1165
|
if (!isAssignmentToThisState(node)) {
|
|
1172
1166
|
return;
|
|
1173
1167
|
}
|
|
1174
|
-
const parentClass = AST11__namespace.
|
|
1168
|
+
const parentClass = AST11__namespace.findParentNode(
|
|
1175
1169
|
node,
|
|
1176
1170
|
AST11__namespace.isOneOf([
|
|
1177
1171
|
types.AST_NODE_TYPES.ClassDeclaration,
|
|
@@ -1179,7 +1173,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1179
1173
|
])
|
|
1180
1174
|
);
|
|
1181
1175
|
if (parentClass == null) return;
|
|
1182
|
-
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.
|
|
1176
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1183
1177
|
context.report({
|
|
1184
1178
|
messageId: "noDirectMutationState",
|
|
1185
1179
|
node
|
|
@@ -1280,7 +1274,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1280
1274
|
break;
|
|
1281
1275
|
}
|
|
1282
1276
|
default: {
|
|
1283
|
-
const call = AST11__namespace.
|
|
1277
|
+
const call = AST11__namespace.findParentNode(jsxElement, AST11__namespace.isMapCallLoose);
|
|
1284
1278
|
const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
|
|
1285
1279
|
if (!AST11__namespace.isFunction(iter)) return;
|
|
1286
1280
|
const arg0 = call?.arguments[0];
|
|
@@ -1444,7 +1438,7 @@ var no_implicit_key_default = createRule({
|
|
|
1444
1438
|
return {
|
|
1445
1439
|
JSXOpeningElement(node) {
|
|
1446
1440
|
const initialScope = context.sourceCode.getScope(node);
|
|
1447
|
-
const keyPropFound = JSX7__namespace.
|
|
1441
|
+
const keyPropFound = JSX7__namespace.getAttribute("key", node.attributes, initialScope);
|
|
1448
1442
|
const keyPropOnElement = node.attributes.some(
|
|
1449
1443
|
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1450
1444
|
);
|
|
@@ -1589,7 +1583,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1589
1583
|
return getReportDescriptor(right);
|
|
1590
1584
|
}
|
|
1591
1585
|
const initialScope = context.sourceCode.getScope(left);
|
|
1592
|
-
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.
|
|
1586
|
+
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1593
1587
|
if (isLeftNan) {
|
|
1594
1588
|
return {
|
|
1595
1589
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1649,7 +1643,17 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1649
1643
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1650
1644
|
return {};
|
|
1651
1645
|
}
|
|
1652
|
-
const {
|
|
1646
|
+
const {
|
|
1647
|
+
ctx,
|
|
1648
|
+
listeners
|
|
1649
|
+
} = core.useComponentCollector(
|
|
1650
|
+
context,
|
|
1651
|
+
core.DEFAULT_COMPONENT_HINT,
|
|
1652
|
+
{
|
|
1653
|
+
collectDisplayName: true,
|
|
1654
|
+
collectHookCalls: false
|
|
1655
|
+
}
|
|
1656
|
+
);
|
|
1653
1657
|
return {
|
|
1654
1658
|
...listeners,
|
|
1655
1659
|
"Program:exit"(node) {
|
|
@@ -1698,7 +1702,7 @@ var no_missing_key_default = createRule({
|
|
|
1698
1702
|
switch (node.type) {
|
|
1699
1703
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1700
1704
|
const initialScope = context.sourceCode.getScope(node);
|
|
1701
|
-
if (!JSX7__namespace.
|
|
1705
|
+
if (!JSX7__namespace.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1702
1706
|
return {
|
|
1703
1707
|
messageId: "noMissingKey",
|
|
1704
1708
|
node
|
|
@@ -1759,7 +1763,7 @@ var no_missing_key_default = createRule({
|
|
|
1759
1763
|
}
|
|
1760
1764
|
const initialScope = context.sourceCode.getScope(node);
|
|
1761
1765
|
for (const element of elements) {
|
|
1762
|
-
if (!JSX7__namespace.
|
|
1766
|
+
if (!JSX7__namespace.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1763
1767
|
context.report({
|
|
1764
1768
|
messageId: "noMissingKey",
|
|
1765
1769
|
node: element
|
|
@@ -1861,7 +1865,7 @@ var no_nested_components_default = createRule({
|
|
|
1861
1865
|
continue;
|
|
1862
1866
|
}
|
|
1863
1867
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1864
|
-
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.
|
|
1868
|
+
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.findParentAttribute(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1865
1869
|
if (isInsideJSXPropValue) {
|
|
1866
1870
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1867
1871
|
context.report({
|
|
@@ -1884,7 +1888,7 @@ var no_nested_components_default = createRule({
|
|
|
1884
1888
|
});
|
|
1885
1889
|
continue;
|
|
1886
1890
|
}
|
|
1887
|
-
const parentComponent = AST11__namespace.
|
|
1891
|
+
const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
|
|
1888
1892
|
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1889
1893
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1890
1894
|
context.report({
|
|
@@ -2058,7 +2062,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2058
2062
|
if (!core.isThisSetState(node)) {
|
|
2059
2063
|
return;
|
|
2060
2064
|
}
|
|
2061
|
-
const clazz = AST11__namespace.
|
|
2065
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2062
2066
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2063
2067
|
if (clazz == null || method == null || method === clazz) return;
|
|
2064
2068
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2103,7 +2107,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2103
2107
|
if (!core.isThisSetState(node)) {
|
|
2104
2108
|
return;
|
|
2105
2109
|
}
|
|
2106
|
-
const clazz = AST11__namespace.
|
|
2110
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2107
2111
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2108
2112
|
if (clazz == null || method == null || method === clazz) return;
|
|
2109
2113
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2148,7 +2152,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2148
2152
|
if (!core.isThisSetState(node)) {
|
|
2149
2153
|
return;
|
|
2150
2154
|
}
|
|
2151
|
-
const clazz = AST11__namespace.
|
|
2155
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2152
2156
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2153
2157
|
if (clazz == null || method == null || method === clazz) return;
|
|
2154
2158
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2392,8 +2396,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2392
2396
|
if (core.isReactHookCall(construction.node)) {
|
|
2393
2397
|
return;
|
|
2394
2398
|
}
|
|
2395
|
-
|
|
2396
|
-
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2399
|
+
eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2397
2400
|
},
|
|
2398
2401
|
"Program:exit"(node) {
|
|
2399
2402
|
const components = ctx.getAllComponents(node).values();
|
|
@@ -2671,15 +2674,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2671
2674
|
const { left } = node;
|
|
2672
2675
|
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2673
2676
|
}
|
|
2674
|
-
var isGetDerivedStateFromProps = tsPattern.isMatching({
|
|
2675
|
-
key: {
|
|
2676
|
-
name: "getDerivedStateFromProps"
|
|
2677
|
-
},
|
|
2678
|
-
static: true,
|
|
2679
|
-
value: {
|
|
2680
|
-
params: tsPattern.P.array()
|
|
2681
|
-
}
|
|
2682
|
-
});
|
|
2683
2677
|
var no_unused_state_default = createRule({
|
|
2684
2678
|
meta: {
|
|
2685
2679
|
type: "problem",
|
|
@@ -2726,7 +2720,7 @@ var no_unused_state_default = createRule({
|
|
|
2726
2720
|
return;
|
|
2727
2721
|
}
|
|
2728
2722
|
if (node.static) {
|
|
2729
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2723
|
+
if (core.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
|
|
2730
2724
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2731
2725
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2732
2726
|
}
|
|
@@ -2899,9 +2893,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2899
2893
|
const { allowExpressions = true } = option;
|
|
2900
2894
|
return {
|
|
2901
2895
|
JSXElement(node) {
|
|
2902
|
-
if (JSX7__namespace.
|
|
2903
|
-
return;
|
|
2904
|
-
}
|
|
2896
|
+
if (!JSX7__namespace.isFragmentElement(node)) return;
|
|
2905
2897
|
checkAndReport(node, context, allowExpressions);
|
|
2906
2898
|
},
|
|
2907
2899
|
JSXFragment(node) {
|
|
@@ -3013,7 +3005,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
3013
3005
|
},
|
|
3014
3006
|
name: RULE_NAME46,
|
|
3015
3007
|
create(context) {
|
|
3016
|
-
const importSource = shared.getSettingsFromContext(context)
|
|
3008
|
+
const { importSource } = shared.getSettingsFromContext(context);
|
|
3017
3009
|
return {
|
|
3018
3010
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3019
3011
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
@@ -3119,7 +3111,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3119
3111
|
return {
|
|
3120
3112
|
JSXAttribute(node) {
|
|
3121
3113
|
const { value } = node;
|
|
3122
|
-
const propName = JSX7__namespace.
|
|
3114
|
+
const propName = JSX7__namespace.getAttributeName(node);
|
|
3123
3115
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3124
3116
|
if (!hasValueTrue) {
|
|
3125
3117
|
return;
|
|
@@ -3159,9 +3151,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3159
3151
|
create(context) {
|
|
3160
3152
|
return {
|
|
3161
3153
|
JSXElement(node) {
|
|
3162
|
-
if (JSX7__namespace.
|
|
3163
|
-
return;
|
|
3164
|
-
}
|
|
3154
|
+
if (!JSX7__namespace.isFragmentElement(node)) return;
|
|
3165
3155
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3166
3156
|
if (hasAttributes) {
|
|
3167
3157
|
return;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as JSX7 from '@eslint-react/jsx';
|
|
2
2
|
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
|
|
3
3
|
import * as AST11 from '@eslint-react/ast';
|
|
4
|
-
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
5
|
-
import { _ } from '@eslint-react/eff';
|
|
4
|
+
import { isForwardRefCall, isThisSetState, isClassComponent, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
5
|
+
import { _, getOrUpdate } from '@eslint-react/eff';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { isMatching, match, P } from 'ts-pattern';
|
|
8
8
|
import { compare } from 'compare-versions';
|
|
@@ -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.16";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -45,7 +45,7 @@ var avoid_shorthand_boolean_default = createRule({
|
|
|
45
45
|
messageId: "avoidShorthandBoolean",
|
|
46
46
|
node,
|
|
47
47
|
data: {
|
|
48
|
-
propName: JSX7.
|
|
48
|
+
propName: JSX7.getAttributeName(node)
|
|
49
49
|
},
|
|
50
50
|
fix: (fixer) => fixer.insertTextAfter(node.name, `={true}`)
|
|
51
51
|
});
|
|
@@ -274,7 +274,7 @@ function isReactChildrenMethod(name2) {
|
|
|
274
274
|
return reactChildrenMethod.some((method) => method === name2);
|
|
275
275
|
}
|
|
276
276
|
function isUsingReactChildren(node, context) {
|
|
277
|
-
const
|
|
277
|
+
const { importSource = "react" } = unsafeDecodeSettings(context.settings);
|
|
278
278
|
const { callee } = node;
|
|
279
279
|
if (!("property" in callee) || !("object" in callee) || !("name" in callee.property)) {
|
|
280
280
|
return false;
|
|
@@ -287,7 +287,7 @@ function isUsingReactChildren(node, context) {
|
|
|
287
287
|
return true;
|
|
288
288
|
}
|
|
289
289
|
if (callee.object.type === AST_NODE_TYPES.MemberExpression && "name" in callee.object.object) {
|
|
290
|
-
return isInitializedFromReact(callee.object.object.name,
|
|
290
|
+
return isInitializedFromReact(callee.object.object.name, importSource, initialScope);
|
|
291
291
|
}
|
|
292
292
|
return false;
|
|
293
293
|
}
|
|
@@ -583,15 +583,15 @@ var no_children_prop_default = createRule({
|
|
|
583
583
|
create(context) {
|
|
584
584
|
return {
|
|
585
585
|
JSXElement(node) {
|
|
586
|
-
const
|
|
586
|
+
const attribute = JSX7.getAttribute(
|
|
587
587
|
"children",
|
|
588
|
-
|
|
589
|
-
|
|
588
|
+
node.openingElement.attributes,
|
|
589
|
+
context.sourceCode.getScope(node)
|
|
590
590
|
);
|
|
591
|
-
if (
|
|
591
|
+
if (attribute != null) {
|
|
592
592
|
context.report({
|
|
593
593
|
messageId: "noChildrenProp",
|
|
594
|
-
node:
|
|
594
|
+
node: attribute
|
|
595
595
|
});
|
|
596
596
|
}
|
|
597
597
|
}
|
|
@@ -634,12 +634,6 @@ var RULE_NAME12 = "no-class-component";
|
|
|
634
634
|
var RULE_FEATURES12 = [
|
|
635
635
|
"CHK"
|
|
636
636
|
];
|
|
637
|
-
function isComponentDidCatch(node) {
|
|
638
|
-
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
|
|
639
|
-
}
|
|
640
|
-
function isGetDerivedStateFromError(node) {
|
|
641
|
-
return (node.type === AST_NODE_TYPES.MethodDefinition || node.type === AST_NODE_TYPES.PropertyDefinition) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
|
|
642
|
-
}
|
|
643
637
|
var no_class_component_default = createRule({
|
|
644
638
|
meta: {
|
|
645
639
|
type: "problem",
|
|
@@ -991,7 +985,7 @@ var no_context_provider_default = createRule({
|
|
|
991
985
|
}
|
|
992
986
|
return {
|
|
993
987
|
JSXElement(node) {
|
|
994
|
-
const elementName = JSX7.getElementName(node
|
|
988
|
+
const elementName = JSX7.getElementName(node);
|
|
995
989
|
if (!elementName.endsWith(".Provider")) {
|
|
996
990
|
return;
|
|
997
991
|
}
|
|
@@ -1144,7 +1138,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1144
1138
|
if (!isAssignmentToThisState(node)) {
|
|
1145
1139
|
return;
|
|
1146
1140
|
}
|
|
1147
|
-
const parentClass = AST11.
|
|
1141
|
+
const parentClass = AST11.findParentNode(
|
|
1148
1142
|
node,
|
|
1149
1143
|
AST11.isOneOf([
|
|
1150
1144
|
AST_NODE_TYPES.ClassDeclaration,
|
|
@@ -1152,7 +1146,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1152
1146
|
])
|
|
1153
1147
|
);
|
|
1154
1148
|
if (parentClass == null) return;
|
|
1155
|
-
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.
|
|
1149
|
+
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNode(node, isConstructorFunction)) {
|
|
1156
1150
|
context.report({
|
|
1157
1151
|
messageId: "noDirectMutationState",
|
|
1158
1152
|
node
|
|
@@ -1253,7 +1247,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1253
1247
|
break;
|
|
1254
1248
|
}
|
|
1255
1249
|
default: {
|
|
1256
|
-
const call = AST11.
|
|
1250
|
+
const call = AST11.findParentNode(jsxElement, AST11.isMapCallLoose);
|
|
1257
1251
|
const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
|
|
1258
1252
|
if (!AST11.isFunction(iter)) return;
|
|
1259
1253
|
const arg0 = call?.arguments[0];
|
|
@@ -1417,7 +1411,7 @@ var no_implicit_key_default = createRule({
|
|
|
1417
1411
|
return {
|
|
1418
1412
|
JSXOpeningElement(node) {
|
|
1419
1413
|
const initialScope = context.sourceCode.getScope(node);
|
|
1420
|
-
const keyPropFound = JSX7.
|
|
1414
|
+
const keyPropFound = JSX7.getAttribute("key", node.attributes, initialScope);
|
|
1421
1415
|
const keyPropOnElement = node.attributes.some(
|
|
1422
1416
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1423
1417
|
);
|
|
@@ -1562,7 +1556,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1562
1556
|
return getReportDescriptor(right);
|
|
1563
1557
|
}
|
|
1564
1558
|
const initialScope = context.sourceCode.getScope(left);
|
|
1565
|
-
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.
|
|
1559
|
+
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1566
1560
|
if (isLeftNan) {
|
|
1567
1561
|
return {
|
|
1568
1562
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1622,7 +1616,17 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1622
1616
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1623
1617
|
return {};
|
|
1624
1618
|
}
|
|
1625
|
-
const {
|
|
1619
|
+
const {
|
|
1620
|
+
ctx,
|
|
1621
|
+
listeners
|
|
1622
|
+
} = useComponentCollector(
|
|
1623
|
+
context,
|
|
1624
|
+
DEFAULT_COMPONENT_HINT,
|
|
1625
|
+
{
|
|
1626
|
+
collectDisplayName: true,
|
|
1627
|
+
collectHookCalls: false
|
|
1628
|
+
}
|
|
1629
|
+
);
|
|
1626
1630
|
return {
|
|
1627
1631
|
...listeners,
|
|
1628
1632
|
"Program:exit"(node) {
|
|
@@ -1671,7 +1675,7 @@ var no_missing_key_default = createRule({
|
|
|
1671
1675
|
switch (node.type) {
|
|
1672
1676
|
case AST_NODE_TYPES.JSXElement: {
|
|
1673
1677
|
const initialScope = context.sourceCode.getScope(node);
|
|
1674
|
-
if (!JSX7.
|
|
1678
|
+
if (!JSX7.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1675
1679
|
return {
|
|
1676
1680
|
messageId: "noMissingKey",
|
|
1677
1681
|
node
|
|
@@ -1732,7 +1736,7 @@ var no_missing_key_default = createRule({
|
|
|
1732
1736
|
}
|
|
1733
1737
|
const initialScope = context.sourceCode.getScope(node);
|
|
1734
1738
|
for (const element of elements) {
|
|
1735
|
-
if (!JSX7.
|
|
1739
|
+
if (!JSX7.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1736
1740
|
context.report({
|
|
1737
1741
|
messageId: "noMissingKey",
|
|
1738
1742
|
node: element
|
|
@@ -1834,7 +1838,7 @@ var no_nested_components_default = createRule({
|
|
|
1834
1838
|
continue;
|
|
1835
1839
|
}
|
|
1836
1840
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1837
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.
|
|
1841
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1838
1842
|
if (isInsideJSXPropValue) {
|
|
1839
1843
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1840
1844
|
context.report({
|
|
@@ -1857,7 +1861,7 @@ var no_nested_components_default = createRule({
|
|
|
1857
1861
|
});
|
|
1858
1862
|
continue;
|
|
1859
1863
|
}
|
|
1860
|
-
const parentComponent = AST11.
|
|
1864
|
+
const parentComponent = AST11.findParentNode(component, isFunctionComponent);
|
|
1861
1865
|
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1862
1866
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1863
1867
|
context.report({
|
|
@@ -2031,7 +2035,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2031
2035
|
if (!isThisSetState(node)) {
|
|
2032
2036
|
return;
|
|
2033
2037
|
}
|
|
2034
|
-
const clazz = AST11.
|
|
2038
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2035
2039
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2036
2040
|
if (clazz == null || method == null || method === clazz) return;
|
|
2037
2041
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2076,7 +2080,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2076
2080
|
if (!isThisSetState(node)) {
|
|
2077
2081
|
return;
|
|
2078
2082
|
}
|
|
2079
|
-
const clazz = AST11.
|
|
2083
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2080
2084
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2081
2085
|
if (clazz == null || method == null || method === clazz) return;
|
|
2082
2086
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2121,7 +2125,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2121
2125
|
if (!isThisSetState(node)) {
|
|
2122
2126
|
return;
|
|
2123
2127
|
}
|
|
2124
|
-
const clazz = AST11.
|
|
2128
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2125
2129
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2126
2130
|
if (clazz == null || method == null || method === clazz) return;
|
|
2127
2131
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2365,8 +2369,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2365
2369
|
if (isReactHookCall(construction.node)) {
|
|
2366
2370
|
return;
|
|
2367
2371
|
}
|
|
2368
|
-
|
|
2369
|
-
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2372
|
+
getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2370
2373
|
},
|
|
2371
2374
|
"Program:exit"(node) {
|
|
2372
2375
|
const components = ctx.getAllComponents(node).values();
|
|
@@ -2644,15 +2647,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2644
2647
|
const { left } = node;
|
|
2645
2648
|
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2646
2649
|
}
|
|
2647
|
-
var isGetDerivedStateFromProps = isMatching({
|
|
2648
|
-
key: {
|
|
2649
|
-
name: "getDerivedStateFromProps"
|
|
2650
|
-
},
|
|
2651
|
-
static: true,
|
|
2652
|
-
value: {
|
|
2653
|
-
params: P.array()
|
|
2654
|
-
}
|
|
2655
|
-
});
|
|
2656
2650
|
var no_unused_state_default = createRule({
|
|
2657
2651
|
meta: {
|
|
2658
2652
|
type: "problem",
|
|
@@ -2699,7 +2693,7 @@ var no_unused_state_default = createRule({
|
|
|
2699
2693
|
return;
|
|
2700
2694
|
}
|
|
2701
2695
|
if (node.static) {
|
|
2702
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2696
|
+
if (isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
2703
2697
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2704
2698
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2705
2699
|
}
|
|
@@ -2872,9 +2866,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2872
2866
|
const { allowExpressions = true } = option;
|
|
2873
2867
|
return {
|
|
2874
2868
|
JSXElement(node) {
|
|
2875
|
-
if (JSX7.
|
|
2876
|
-
return;
|
|
2877
|
-
}
|
|
2869
|
+
if (!JSX7.isFragmentElement(node)) return;
|
|
2878
2870
|
checkAndReport(node, context, allowExpressions);
|
|
2879
2871
|
},
|
|
2880
2872
|
JSXFragment(node) {
|
|
@@ -2986,7 +2978,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
2986
2978
|
},
|
|
2987
2979
|
name: RULE_NAME46,
|
|
2988
2980
|
create(context) {
|
|
2989
|
-
const importSource = getSettingsFromContext(context)
|
|
2981
|
+
const { importSource } = getSettingsFromContext(context);
|
|
2990
2982
|
return {
|
|
2991
2983
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
2992
2984
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
@@ -3092,7 +3084,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3092
3084
|
return {
|
|
3093
3085
|
JSXAttribute(node) {
|
|
3094
3086
|
const { value } = node;
|
|
3095
|
-
const propName = JSX7.
|
|
3087
|
+
const propName = JSX7.getAttributeName(node);
|
|
3096
3088
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3097
3089
|
if (!hasValueTrue) {
|
|
3098
3090
|
return;
|
|
@@ -3132,9 +3124,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3132
3124
|
create(context) {
|
|
3133
3125
|
return {
|
|
3134
3126
|
JSXElement(node) {
|
|
3135
|
-
if (JSX7.
|
|
3136
|
-
return;
|
|
3137
|
-
}
|
|
3127
|
+
if (!JSX7.isFragmentElement(node)) return;
|
|
3138
3128
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3139
3129
|
if (hasAttributes) {
|
|
3140
3130
|
return;
|
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.16",
|
|
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",
|
|
@@ -40,24 +40,23 @@
|
|
|
40
40
|
"./package.json"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
44
|
-
"@typescript-eslint/type-utils": "^8.
|
|
45
|
-
"@typescript-eslint/types": "^8.
|
|
46
|
-
"@typescript-eslint/utils": "^8.
|
|
43
|
+
"@typescript-eslint/scope-manager": "^8.20.0",
|
|
44
|
+
"@typescript-eslint/type-utils": "^8.20.0",
|
|
45
|
+
"@typescript-eslint/types": "^8.20.0",
|
|
46
|
+
"@typescript-eslint/utils": "^8.20.0",
|
|
47
47
|
"compare-versions": "^6.1.1",
|
|
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/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/var": "1.24.0-beta.1"
|
|
51
|
+
"@eslint-react/core": "1.24.0-beta.16",
|
|
52
|
+
"@eslint-react/ast": "1.24.0-beta.16",
|
|
53
|
+
"@eslint-react/jsx": "1.24.0-beta.16",
|
|
54
|
+
"@eslint-react/shared": "1.24.0-beta.16",
|
|
55
|
+
"@eslint-react/eff": "1.24.0-beta.16",
|
|
56
|
+
"@eslint-react/var": "1.24.0-beta.16"
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
|
-
"@types/react": "^19.0.
|
|
59
|
+
"@types/react": "^19.0.7",
|
|
61
60
|
"@types/react-dom": "^19.0.3",
|
|
62
61
|
"ts-api-utils": "^2.0.0",
|
|
63
62
|
"tsup": "^8.3.5",
|