eslint-plugin-react-x 1.24.0-beta.1 → 1.24.0-beta.18
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 -54
- package/dist/index.mjs +41 -55
- package/package.json +13 -14
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.18";
|
|
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,14 +684,13 @@ 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({
|
|
697
691
|
messageId: "noClassComponent",
|
|
698
692
|
node: component,
|
|
699
693
|
data: {
|
|
700
|
-
// eslint-disable-next-line eslint-plugin/no-unused-placeholders
|
|
701
694
|
name: name2
|
|
702
695
|
}
|
|
703
696
|
});
|
|
@@ -1018,7 +1011,7 @@ var no_context_provider_default = createRule({
|
|
|
1018
1011
|
}
|
|
1019
1012
|
return {
|
|
1020
1013
|
JSXElement(node) {
|
|
1021
|
-
const elementName = JSX7__namespace.getElementName(node
|
|
1014
|
+
const elementName = JSX7__namespace.getElementName(node);
|
|
1022
1015
|
if (!elementName.endsWith(".Provider")) {
|
|
1023
1016
|
return;
|
|
1024
1017
|
}
|
|
@@ -1171,7 +1164,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1171
1164
|
if (!isAssignmentToThisState(node)) {
|
|
1172
1165
|
return;
|
|
1173
1166
|
}
|
|
1174
|
-
const parentClass = AST11__namespace.
|
|
1167
|
+
const parentClass = AST11__namespace.findParentNode(
|
|
1175
1168
|
node,
|
|
1176
1169
|
AST11__namespace.isOneOf([
|
|
1177
1170
|
types.AST_NODE_TYPES.ClassDeclaration,
|
|
@@ -1179,7 +1172,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1179
1172
|
])
|
|
1180
1173
|
);
|
|
1181
1174
|
if (parentClass == null) return;
|
|
1182
|
-
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.
|
|
1175
|
+
if (core.isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11__namespace.findParentNode(node, isConstructorFunction)) {
|
|
1183
1176
|
context.report({
|
|
1184
1177
|
messageId: "noDirectMutationState",
|
|
1185
1178
|
node
|
|
@@ -1280,7 +1273,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1280
1273
|
break;
|
|
1281
1274
|
}
|
|
1282
1275
|
default: {
|
|
1283
|
-
const call = AST11__namespace.
|
|
1276
|
+
const call = AST11__namespace.findParentNode(jsxElement, AST11__namespace.isMapCallLoose);
|
|
1284
1277
|
const iter = AST11__namespace.findParentNode(jsxElement, (n) => n === call || AST11__namespace.isFunction(n));
|
|
1285
1278
|
if (!AST11__namespace.isFunction(iter)) return;
|
|
1286
1279
|
const arg0 = call?.arguments[0];
|
|
@@ -1444,7 +1437,7 @@ var no_implicit_key_default = createRule({
|
|
|
1444
1437
|
return {
|
|
1445
1438
|
JSXOpeningElement(node) {
|
|
1446
1439
|
const initialScope = context.sourceCode.getScope(node);
|
|
1447
|
-
const keyPropFound = JSX7__namespace.
|
|
1440
|
+
const keyPropFound = JSX7__namespace.getAttribute("key", node.attributes, initialScope);
|
|
1448
1441
|
const keyPropOnElement = node.attributes.some(
|
|
1449
1442
|
(n) => n.type === types.AST_NODE_TYPES.JSXAttribute && n.name.type === types.AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1450
1443
|
);
|
|
@@ -1589,7 +1582,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1589
1582
|
return getReportDescriptor(right);
|
|
1590
1583
|
}
|
|
1591
1584
|
const initialScope = context.sourceCode.getScope(left);
|
|
1592
|
-
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.
|
|
1585
|
+
const isLeftNan = left.type === types.AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR__namespace.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1593
1586
|
if (isLeftNan) {
|
|
1594
1587
|
return {
|
|
1595
1588
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1649,7 +1642,17 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1649
1642
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1650
1643
|
return {};
|
|
1651
1644
|
}
|
|
1652
|
-
const {
|
|
1645
|
+
const {
|
|
1646
|
+
ctx,
|
|
1647
|
+
listeners
|
|
1648
|
+
} = core.useComponentCollector(
|
|
1649
|
+
context,
|
|
1650
|
+
core.DEFAULT_COMPONENT_HINT,
|
|
1651
|
+
{
|
|
1652
|
+
collectDisplayName: true,
|
|
1653
|
+
collectHookCalls: false
|
|
1654
|
+
}
|
|
1655
|
+
);
|
|
1653
1656
|
return {
|
|
1654
1657
|
...listeners,
|
|
1655
1658
|
"Program:exit"(node) {
|
|
@@ -1698,7 +1701,7 @@ var no_missing_key_default = createRule({
|
|
|
1698
1701
|
switch (node.type) {
|
|
1699
1702
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1700
1703
|
const initialScope = context.sourceCode.getScope(node);
|
|
1701
|
-
if (!JSX7__namespace.
|
|
1704
|
+
if (!JSX7__namespace.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1702
1705
|
return {
|
|
1703
1706
|
messageId: "noMissingKey",
|
|
1704
1707
|
node
|
|
@@ -1759,7 +1762,7 @@ var no_missing_key_default = createRule({
|
|
|
1759
1762
|
}
|
|
1760
1763
|
const initialScope = context.sourceCode.getScope(node);
|
|
1761
1764
|
for (const element of elements) {
|
|
1762
|
-
if (!JSX7__namespace.
|
|
1765
|
+
if (!JSX7__namespace.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1763
1766
|
context.report({
|
|
1764
1767
|
messageId: "noMissingKey",
|
|
1765
1768
|
node: element
|
|
@@ -1861,7 +1864,7 @@ var no_nested_components_default = createRule({
|
|
|
1861
1864
|
continue;
|
|
1862
1865
|
}
|
|
1863
1866
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1864
|
-
const isInsideJSXPropValue = component.parent.type === types.AST_NODE_TYPES.JSXAttribute || JSX7__namespace.
|
|
1867
|
+
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
1868
|
if (isInsideJSXPropValue) {
|
|
1866
1869
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1867
1870
|
context.report({
|
|
@@ -1884,7 +1887,7 @@ var no_nested_components_default = createRule({
|
|
|
1884
1887
|
});
|
|
1885
1888
|
continue;
|
|
1886
1889
|
}
|
|
1887
|
-
const parentComponent = AST11__namespace.
|
|
1890
|
+
const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
|
|
1888
1891
|
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1889
1892
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1890
1893
|
context.report({
|
|
@@ -2058,7 +2061,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2058
2061
|
if (!core.isThisSetState(node)) {
|
|
2059
2062
|
return;
|
|
2060
2063
|
}
|
|
2061
|
-
const clazz = AST11__namespace.
|
|
2064
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2062
2065
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2063
2066
|
if (clazz == null || method == null || method === clazz) return;
|
|
2064
2067
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2103,7 +2106,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2103
2106
|
if (!core.isThisSetState(node)) {
|
|
2104
2107
|
return;
|
|
2105
2108
|
}
|
|
2106
|
-
const clazz = AST11__namespace.
|
|
2109
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2107
2110
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2108
2111
|
if (clazz == null || method == null || method === clazz) return;
|
|
2109
2112
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2148,7 +2151,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2148
2151
|
if (!core.isThisSetState(node)) {
|
|
2149
2152
|
return;
|
|
2150
2153
|
}
|
|
2151
|
-
const clazz = AST11__namespace.
|
|
2154
|
+
const clazz = AST11__namespace.findParentNode(node, core.isClassComponent);
|
|
2152
2155
|
const method = AST11__namespace.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2153
2156
|
if (clazz == null || method == null || method === clazz) return;
|
|
2154
2157
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2392,8 +2395,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2392
2395
|
if (core.isReactHookCall(construction.node)) {
|
|
2393
2396
|
return;
|
|
2394
2397
|
}
|
|
2395
|
-
|
|
2396
|
-
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2398
|
+
eff.getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2397
2399
|
},
|
|
2398
2400
|
"Program:exit"(node) {
|
|
2399
2401
|
const components = ctx.getAllComponents(node).values();
|
|
@@ -2671,15 +2673,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2671
2673
|
const { left } = node;
|
|
2672
2674
|
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2673
2675
|
}
|
|
2674
|
-
var isGetDerivedStateFromProps = tsPattern.isMatching({
|
|
2675
|
-
key: {
|
|
2676
|
-
name: "getDerivedStateFromProps"
|
|
2677
|
-
},
|
|
2678
|
-
static: true,
|
|
2679
|
-
value: {
|
|
2680
|
-
params: tsPattern.P.array()
|
|
2681
|
-
}
|
|
2682
|
-
});
|
|
2683
2676
|
var no_unused_state_default = createRule({
|
|
2684
2677
|
meta: {
|
|
2685
2678
|
type: "problem",
|
|
@@ -2726,7 +2719,7 @@ var no_unused_state_default = createRule({
|
|
|
2726
2719
|
return;
|
|
2727
2720
|
}
|
|
2728
2721
|
if (node.static) {
|
|
2729
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2722
|
+
if (core.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
|
|
2730
2723
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2731
2724
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2732
2725
|
}
|
|
@@ -2899,9 +2892,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2899
2892
|
const { allowExpressions = true } = option;
|
|
2900
2893
|
return {
|
|
2901
2894
|
JSXElement(node) {
|
|
2902
|
-
if (JSX7__namespace.
|
|
2903
|
-
return;
|
|
2904
|
-
}
|
|
2895
|
+
if (!JSX7__namespace.isFragmentElement(node)) return;
|
|
2905
2896
|
checkAndReport(node, context, allowExpressions);
|
|
2906
2897
|
},
|
|
2907
2898
|
JSXFragment(node) {
|
|
@@ -3013,7 +3004,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
3013
3004
|
},
|
|
3014
3005
|
name: RULE_NAME46,
|
|
3015
3006
|
create(context) {
|
|
3016
|
-
const importSource = shared.getSettingsFromContext(context)
|
|
3007
|
+
const { importSource } = shared.getSettingsFromContext(context);
|
|
3017
3008
|
return {
|
|
3018
3009
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3019
3010
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
@@ -3119,7 +3110,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3119
3110
|
return {
|
|
3120
3111
|
JSXAttribute(node) {
|
|
3121
3112
|
const { value } = node;
|
|
3122
|
-
const propName = JSX7__namespace.
|
|
3113
|
+
const propName = JSX7__namespace.getAttributeName(node);
|
|
3123
3114
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3124
3115
|
if (!hasValueTrue) {
|
|
3125
3116
|
return;
|
|
@@ -3159,9 +3150,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3159
3150
|
create(context) {
|
|
3160
3151
|
return {
|
|
3161
3152
|
JSXElement(node) {
|
|
3162
|
-
if (JSX7__namespace.
|
|
3163
|
-
return;
|
|
3164
|
-
}
|
|
3153
|
+
if (!JSX7__namespace.isFragmentElement(node)) return;
|
|
3165
3154
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3166
3155
|
if (hasAttributes) {
|
|
3167
3156
|
return;
|
|
@@ -3175,9 +3164,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3175
3164
|
return [];
|
|
3176
3165
|
}
|
|
3177
3166
|
return [
|
|
3178
|
-
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3179
3167
|
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3180
|
-
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3181
3168
|
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3182
3169
|
];
|
|
3183
3170
|
}
|
|
@@ -3193,7 +3180,6 @@ var use_jsx_vars_default = createRule({
|
|
|
3193
3180
|
meta: {
|
|
3194
3181
|
type: "problem",
|
|
3195
3182
|
docs: {
|
|
3196
|
-
// eslint-disable-next-line eslint-plugin/require-meta-docs-description
|
|
3197
3183
|
description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
|
|
3198
3184
|
[Symbol.for("rule_features")]: RULE_FEATURES49
|
|
3199
3185
|
},
|
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.18";
|
|
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",
|
|
@@ -670,7 +664,6 @@ var no_class_component_default = createRule({
|
|
|
670
664
|
messageId: "noClassComponent",
|
|
671
665
|
node: component,
|
|
672
666
|
data: {
|
|
673
|
-
// eslint-disable-next-line eslint-plugin/no-unused-placeholders
|
|
674
667
|
name: name2
|
|
675
668
|
}
|
|
676
669
|
});
|
|
@@ -991,7 +984,7 @@ var no_context_provider_default = createRule({
|
|
|
991
984
|
}
|
|
992
985
|
return {
|
|
993
986
|
JSXElement(node) {
|
|
994
|
-
const elementName = JSX7.getElementName(node
|
|
987
|
+
const elementName = JSX7.getElementName(node);
|
|
995
988
|
if (!elementName.endsWith(".Provider")) {
|
|
996
989
|
return;
|
|
997
990
|
}
|
|
@@ -1144,7 +1137,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1144
1137
|
if (!isAssignmentToThisState(node)) {
|
|
1145
1138
|
return;
|
|
1146
1139
|
}
|
|
1147
|
-
const parentClass = AST11.
|
|
1140
|
+
const parentClass = AST11.findParentNode(
|
|
1148
1141
|
node,
|
|
1149
1142
|
AST11.isOneOf([
|
|
1150
1143
|
AST_NODE_TYPES.ClassDeclaration,
|
|
@@ -1152,7 +1145,7 @@ var no_direct_mutation_state_default = createRule({
|
|
|
1152
1145
|
])
|
|
1153
1146
|
);
|
|
1154
1147
|
if (parentClass == null) return;
|
|
1155
|
-
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.
|
|
1148
|
+
if (isClassComponent(parentClass) && context.sourceCode.getScope(node).block !== AST11.findParentNode(node, isConstructorFunction)) {
|
|
1156
1149
|
context.report({
|
|
1157
1150
|
messageId: "noDirectMutationState",
|
|
1158
1151
|
node
|
|
@@ -1253,7 +1246,7 @@ var no_duplicate_key_default = createRule({
|
|
|
1253
1246
|
break;
|
|
1254
1247
|
}
|
|
1255
1248
|
default: {
|
|
1256
|
-
const call = AST11.
|
|
1249
|
+
const call = AST11.findParentNode(jsxElement, AST11.isMapCallLoose);
|
|
1257
1250
|
const iter = AST11.findParentNode(jsxElement, (n) => n === call || AST11.isFunction(n));
|
|
1258
1251
|
if (!AST11.isFunction(iter)) return;
|
|
1259
1252
|
const arg0 = call?.arguments[0];
|
|
@@ -1417,7 +1410,7 @@ var no_implicit_key_default = createRule({
|
|
|
1417
1410
|
return {
|
|
1418
1411
|
JSXOpeningElement(node) {
|
|
1419
1412
|
const initialScope = context.sourceCode.getScope(node);
|
|
1420
|
-
const keyPropFound = JSX7.
|
|
1413
|
+
const keyPropFound = JSX7.getAttribute("key", node.attributes, initialScope);
|
|
1421
1414
|
const keyPropOnElement = node.attributes.some(
|
|
1422
1415
|
(n) => n.type === AST_NODE_TYPES.JSXAttribute && n.name.type === AST_NODE_TYPES.JSXIdentifier && n.name.name === "key"
|
|
1423
1416
|
);
|
|
@@ -1562,7 +1555,7 @@ var no_leaked_conditional_rendering_default = createRule({
|
|
|
1562
1555
|
return getReportDescriptor(right);
|
|
1563
1556
|
}
|
|
1564
1557
|
const initialScope = context.sourceCode.getScope(left);
|
|
1565
|
-
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.
|
|
1558
|
+
const isLeftNan = left.type === AST_NODE_TYPES.Identifier && left.name === "NaN" || VAR.toStaticValue({ kind: "lazy", node: left, initialScope }).value === "NaN";
|
|
1566
1559
|
if (isLeftNan) {
|
|
1567
1560
|
return {
|
|
1568
1561
|
messageId: "noLeakedConditionalRendering",
|
|
@@ -1622,7 +1615,17 @@ var no_missing_component_display_name_default = createRule({
|
|
|
1622
1615
|
if (!context.sourceCode.text.includes("memo") && !context.sourceCode.text.includes("forwardRef")) {
|
|
1623
1616
|
return {};
|
|
1624
1617
|
}
|
|
1625
|
-
const {
|
|
1618
|
+
const {
|
|
1619
|
+
ctx,
|
|
1620
|
+
listeners
|
|
1621
|
+
} = useComponentCollector(
|
|
1622
|
+
context,
|
|
1623
|
+
DEFAULT_COMPONENT_HINT,
|
|
1624
|
+
{
|
|
1625
|
+
collectDisplayName: true,
|
|
1626
|
+
collectHookCalls: false
|
|
1627
|
+
}
|
|
1628
|
+
);
|
|
1626
1629
|
return {
|
|
1627
1630
|
...listeners,
|
|
1628
1631
|
"Program:exit"(node) {
|
|
@@ -1671,7 +1674,7 @@ var no_missing_key_default = createRule({
|
|
|
1671
1674
|
switch (node.type) {
|
|
1672
1675
|
case AST_NODE_TYPES.JSXElement: {
|
|
1673
1676
|
const initialScope = context.sourceCode.getScope(node);
|
|
1674
|
-
if (!JSX7.
|
|
1677
|
+
if (!JSX7.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1675
1678
|
return {
|
|
1676
1679
|
messageId: "noMissingKey",
|
|
1677
1680
|
node
|
|
@@ -1732,7 +1735,7 @@ var no_missing_key_default = createRule({
|
|
|
1732
1735
|
}
|
|
1733
1736
|
const initialScope = context.sourceCode.getScope(node);
|
|
1734
1737
|
for (const element of elements) {
|
|
1735
|
-
if (!JSX7.
|
|
1738
|
+
if (!JSX7.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1736
1739
|
context.report({
|
|
1737
1740
|
messageId: "noMissingKey",
|
|
1738
1741
|
node: element
|
|
@@ -1834,7 +1837,7 @@ var no_nested_components_default = createRule({
|
|
|
1834
1837
|
continue;
|
|
1835
1838
|
}
|
|
1836
1839
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1837
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.
|
|
1840
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentAttribute(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1838
1841
|
if (isInsideJSXPropValue) {
|
|
1839
1842
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1840
1843
|
context.report({
|
|
@@ -1857,7 +1860,7 @@ var no_nested_components_default = createRule({
|
|
|
1857
1860
|
});
|
|
1858
1861
|
continue;
|
|
1859
1862
|
}
|
|
1860
|
-
const parentComponent = AST11.
|
|
1863
|
+
const parentComponent = AST11.findParentNode(component, isFunctionComponent);
|
|
1861
1864
|
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1862
1865
|
if (isParnetComponentNotDirectValueOfRenderProperty) {
|
|
1863
1866
|
context.report({
|
|
@@ -2031,7 +2034,7 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2031
2034
|
if (!isThisSetState(node)) {
|
|
2032
2035
|
return;
|
|
2033
2036
|
}
|
|
2034
|
-
const clazz = AST11.
|
|
2037
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2035
2038
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
|
|
2036
2039
|
if (clazz == null || method == null || method === clazz) return;
|
|
2037
2040
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2076,7 +2079,7 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2076
2079
|
if (!isThisSetState(node)) {
|
|
2077
2080
|
return;
|
|
2078
2081
|
}
|
|
2079
|
-
const clazz = AST11.
|
|
2082
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2080
2083
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentDidUpdate(n));
|
|
2081
2084
|
if (clazz == null || method == null || method === clazz) return;
|
|
2082
2085
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2121,7 +2124,7 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2121
2124
|
if (!isThisSetState(node)) {
|
|
2122
2125
|
return;
|
|
2123
2126
|
}
|
|
2124
|
-
const clazz = AST11.
|
|
2127
|
+
const clazz = AST11.findParentNode(node, isClassComponent);
|
|
2125
2128
|
const method = AST11.findParentNode(node, (n) => n === clazz || isComponentWillUpdate3(n));
|
|
2126
2129
|
if (clazz == null || method == null || method === clazz) return;
|
|
2127
2130
|
const methodScope = context.sourceCode.getScope(method);
|
|
@@ -2365,8 +2368,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2365
2368
|
if (isReactHookCall(construction.node)) {
|
|
2366
2369
|
return;
|
|
2367
2370
|
}
|
|
2368
|
-
|
|
2369
|
-
constructions.set(functionEntry.node, [...prevs, construction]);
|
|
2371
|
+
getOrUpdate(constructions, functionEntry.node, () => []).push(construction);
|
|
2370
2372
|
},
|
|
2371
2373
|
"Program:exit"(node) {
|
|
2372
2374
|
const components = ctx.getAllComponents(node).values();
|
|
@@ -2644,15 +2646,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2644
2646
|
const { left } = node;
|
|
2645
2647
|
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2646
2648
|
}
|
|
2647
|
-
var isGetDerivedStateFromProps = isMatching({
|
|
2648
|
-
key: {
|
|
2649
|
-
name: "getDerivedStateFromProps"
|
|
2650
|
-
},
|
|
2651
|
-
static: true,
|
|
2652
|
-
value: {
|
|
2653
|
-
params: P.array()
|
|
2654
|
-
}
|
|
2655
|
-
});
|
|
2656
2649
|
var no_unused_state_default = createRule({
|
|
2657
2650
|
meta: {
|
|
2658
2651
|
type: "problem",
|
|
@@ -2699,7 +2692,7 @@ var no_unused_state_default = createRule({
|
|
|
2699
2692
|
return;
|
|
2700
2693
|
}
|
|
2701
2694
|
if (node.static) {
|
|
2702
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2695
|
+
if (isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
2703
2696
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2704
2697
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2705
2698
|
}
|
|
@@ -2872,9 +2865,7 @@ var no_useless_fragment_default = createRule({
|
|
|
2872
2865
|
const { allowExpressions = true } = option;
|
|
2873
2866
|
return {
|
|
2874
2867
|
JSXElement(node) {
|
|
2875
|
-
if (JSX7.
|
|
2876
|
-
return;
|
|
2877
|
-
}
|
|
2868
|
+
if (!JSX7.isFragmentElement(node)) return;
|
|
2878
2869
|
checkAndReport(node, context, allowExpressions);
|
|
2879
2870
|
},
|
|
2880
2871
|
JSXFragment(node) {
|
|
@@ -2986,7 +2977,7 @@ var prefer_react_namespace_import_default = createRule({
|
|
|
2986
2977
|
},
|
|
2987
2978
|
name: RULE_NAME46,
|
|
2988
2979
|
create(context) {
|
|
2989
|
-
const importSource = getSettingsFromContext(context)
|
|
2980
|
+
const { importSource } = getSettingsFromContext(context);
|
|
2990
2981
|
return {
|
|
2991
2982
|
[`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
2992
2983
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
@@ -3092,7 +3083,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3092
3083
|
return {
|
|
3093
3084
|
JSXAttribute(node) {
|
|
3094
3085
|
const { value } = node;
|
|
3095
|
-
const propName = JSX7.
|
|
3086
|
+
const propName = JSX7.getAttributeName(node);
|
|
3096
3087
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3097
3088
|
if (!hasValueTrue) {
|
|
3098
3089
|
return;
|
|
@@ -3132,9 +3123,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3132
3123
|
create(context) {
|
|
3133
3124
|
return {
|
|
3134
3125
|
JSXElement(node) {
|
|
3135
|
-
if (JSX7.
|
|
3136
|
-
return;
|
|
3137
|
-
}
|
|
3126
|
+
if (!JSX7.isFragmentElement(node)) return;
|
|
3138
3127
|
const hasAttributes = node.openingElement.attributes.length > 0;
|
|
3139
3128
|
if (hasAttributes) {
|
|
3140
3129
|
return;
|
|
@@ -3148,9 +3137,7 @@ var prefer_shorthand_fragment_default = createRule({
|
|
|
3148
3137
|
return [];
|
|
3149
3138
|
}
|
|
3150
3139
|
return [
|
|
3151
|
-
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3152
3140
|
fixer.replaceTextRange([openingElement.range[0], openingElement.range[1]], "<>"),
|
|
3153
|
-
// eslint-disable-next-line eslint-plugin/prefer-replace-text
|
|
3154
3141
|
fixer.replaceTextRange([closingElement.range[0], closingElement.range[1]], "</>")
|
|
3155
3142
|
];
|
|
3156
3143
|
}
|
|
@@ -3166,7 +3153,6 @@ var use_jsx_vars_default = createRule({
|
|
|
3166
3153
|
meta: {
|
|
3167
3154
|
type: "problem",
|
|
3168
3155
|
docs: {
|
|
3169
|
-
// eslint-disable-next-line eslint-plugin/require-meta-docs-description
|
|
3170
3156
|
description: "helpes `eslint/no-unused-vars` to correctly mark JSX variables as used.",
|
|
3171
3157
|
[Symbol.for("rule_features")]: RULE_FEATURES49
|
|
3172
3158
|
},
|
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.18",
|
|
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
|
-
"ts-pattern": "^5.6.
|
|
51
|
-
"@eslint-react/ast": "1.24.0-beta.
|
|
52
|
-
"@eslint-react/core": "1.24.0-beta.
|
|
53
|
-
"@eslint-react/eff": "1.24.0-beta.
|
|
54
|
-
"@eslint-react/jsx": "1.24.0-beta.
|
|
55
|
-
"@eslint-react/shared": "1.24.0-beta.
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/var": "1.24.0-beta.1"
|
|
50
|
+
"ts-pattern": "^5.6.1",
|
|
51
|
+
"@eslint-react/ast": "1.24.0-beta.18",
|
|
52
|
+
"@eslint-react/core": "1.24.0-beta.18",
|
|
53
|
+
"@eslint-react/eff": "1.24.0-beta.18",
|
|
54
|
+
"@eslint-react/jsx": "1.24.0-beta.18",
|
|
55
|
+
"@eslint-react/shared": "1.24.0-beta.18",
|
|
56
|
+
"@eslint-react/var": "1.24.0-beta.18"
|
|
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",
|