eslint-plugin-react-x 1.24.0-next.6 → 1.24.0-next.9
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 +12 -27
- package/dist/index.mjs +12 -27
- package/package.json +12 -12
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-next.
|
|
45
|
+
var version = "1.24.0-next.9";
|
|
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
|
});
|
|
@@ -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.getAttributeNode(
|
|
614
614
|
"children",
|
|
615
615
|
context.sourceCode.getScope(node),
|
|
616
616
|
node.openingElement.attributes
|
|
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({
|
|
@@ -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.getAttributeNode("key", initialScope, node.attributes);
|
|
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
|
);
|
|
@@ -1708,7 +1702,7 @@ var no_missing_key_default = createRule({
|
|
|
1708
1702
|
switch (node.type) {
|
|
1709
1703
|
case types.AST_NODE_TYPES.JSXElement: {
|
|
1710
1704
|
const initialScope = context.sourceCode.getScope(node);
|
|
1711
|
-
if (!JSX7__namespace.
|
|
1705
|
+
if (!JSX7__namespace.hasAttribute("key", initialScope, node.openingElement.attributes)) {
|
|
1712
1706
|
return {
|
|
1713
1707
|
messageId: "noMissingKey",
|
|
1714
1708
|
node
|
|
@@ -1769,7 +1763,7 @@ var no_missing_key_default = createRule({
|
|
|
1769
1763
|
}
|
|
1770
1764
|
const initialScope = context.sourceCode.getScope(node);
|
|
1771
1765
|
for (const element of elements) {
|
|
1772
|
-
if (!JSX7__namespace.
|
|
1766
|
+
if (!JSX7__namespace.hasAttribute("key", initialScope, element.openingElement.attributes)) {
|
|
1773
1767
|
context.report({
|
|
1774
1768
|
messageId: "noMissingKey",
|
|
1775
1769
|
node: element
|
|
@@ -1871,7 +1865,7 @@ var no_nested_components_default = createRule({
|
|
|
1871
1865
|
continue;
|
|
1872
1866
|
}
|
|
1873
1867
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
1874
|
-
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.findParentAttributeNode(node, (n) => n.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1875
1869
|
if (isInsideJSXPropValue) {
|
|
1876
1870
|
if (!core.isDeclaredInRenderPropLoose(component)) {
|
|
1877
1871
|
context.report({
|
|
@@ -2680,15 +2674,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2680
2674
|
const { left } = node;
|
|
2681
2675
|
return left.type === types.AST_NODE_TYPES.MemberExpression && AST11__namespace.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2682
2676
|
}
|
|
2683
|
-
var isGetDerivedStateFromProps = tsPattern.isMatching({
|
|
2684
|
-
key: {
|
|
2685
|
-
name: "getDerivedStateFromProps"
|
|
2686
|
-
},
|
|
2687
|
-
static: true,
|
|
2688
|
-
value: {
|
|
2689
|
-
params: tsPattern.P.array()
|
|
2690
|
-
}
|
|
2691
|
-
});
|
|
2692
2677
|
var no_unused_state_default = createRule({
|
|
2693
2678
|
meta: {
|
|
2694
2679
|
type: "problem",
|
|
@@ -2735,7 +2720,7 @@ var no_unused_state_default = createRule({
|
|
|
2735
2720
|
return;
|
|
2736
2721
|
}
|
|
2737
2722
|
if (node.static) {
|
|
2738
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2723
|
+
if (core.isGetDerivedStateFromProps(node) && tsPattern.isMatching({ params: [tsPattern.P.nonNullable, ...tsPattern.P.array()] })(node.value)) {
|
|
2739
2724
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2740
2725
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2741
2726
|
}
|
|
@@ -3128,7 +3113,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3128
3113
|
return {
|
|
3129
3114
|
JSXAttribute(node) {
|
|
3130
3115
|
const { value } = node;
|
|
3131
|
-
const propName = JSX7__namespace.
|
|
3116
|
+
const propName = JSX7__namespace.getAttributeName(node);
|
|
3132
3117
|
const hasValueTrue = value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === types.AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3133
3118
|
if (!hasValueTrue) {
|
|
3134
3119
|
return;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, DEFAULT_COMPONENT_HINT, ERFunctionComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, ERClassComponentFlag, isReactHookCall, isCreateElementCall, isInitializedFromReact } from '@eslint-react/core';
|
|
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
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';
|
|
@@ -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-next.
|
|
18
|
+
var version = "1.24.0-next.9";
|
|
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
|
});
|
|
@@ -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.getAttributeNode(
|
|
587
587
|
"children",
|
|
588
588
|
context.sourceCode.getScope(node),
|
|
589
589
|
node.openingElement.attributes
|
|
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",
|
|
@@ -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.getAttributeNode("key", initialScope, node.attributes);
|
|
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
|
);
|
|
@@ -1681,7 +1675,7 @@ var no_missing_key_default = createRule({
|
|
|
1681
1675
|
switch (node.type) {
|
|
1682
1676
|
case AST_NODE_TYPES.JSXElement: {
|
|
1683
1677
|
const initialScope = context.sourceCode.getScope(node);
|
|
1684
|
-
if (!JSX7.
|
|
1678
|
+
if (!JSX7.hasAttribute("key", initialScope, node.openingElement.attributes)) {
|
|
1685
1679
|
return {
|
|
1686
1680
|
messageId: "noMissingKey",
|
|
1687
1681
|
node
|
|
@@ -1742,7 +1736,7 @@ var no_missing_key_default = createRule({
|
|
|
1742
1736
|
}
|
|
1743
1737
|
const initialScope = context.sourceCode.getScope(node);
|
|
1744
1738
|
for (const element of elements) {
|
|
1745
|
-
if (!JSX7.
|
|
1739
|
+
if (!JSX7.hasAttribute("key", initialScope, element.openingElement.attributes)) {
|
|
1746
1740
|
context.report({
|
|
1747
1741
|
messageId: "noMissingKey",
|
|
1748
1742
|
node: element
|
|
@@ -1844,7 +1838,7 @@ var no_nested_components_default = createRule({
|
|
|
1844
1838
|
continue;
|
|
1845
1839
|
}
|
|
1846
1840
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
1847
|
-
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.
|
|
1841
|
+
const isInsideJSXPropValue = component.parent.type === AST_NODE_TYPES.JSXAttribute || JSX7.findParentAttributeNode(node, (n) => n.value?.type === AST_NODE_TYPES.JSXExpressionContainer) != null;
|
|
1848
1842
|
if (isInsideJSXPropValue) {
|
|
1849
1843
|
if (!isDeclaredInRenderPropLoose(component)) {
|
|
1850
1844
|
context.report({
|
|
@@ -2653,15 +2647,6 @@ function isAssignmentToThisState2(node) {
|
|
|
2653
2647
|
const { left } = node;
|
|
2654
2648
|
return left.type === AST_NODE_TYPES.MemberExpression && AST11.isThisExpression(left.object) && getName4(left.property) === "state";
|
|
2655
2649
|
}
|
|
2656
|
-
var isGetDerivedStateFromProps = isMatching({
|
|
2657
|
-
key: {
|
|
2658
|
-
name: "getDerivedStateFromProps"
|
|
2659
|
-
},
|
|
2660
|
-
static: true,
|
|
2661
|
-
value: {
|
|
2662
|
-
params: P.array()
|
|
2663
|
-
}
|
|
2664
|
-
});
|
|
2665
2650
|
var no_unused_state_default = createRule({
|
|
2666
2651
|
meta: {
|
|
2667
2652
|
type: "problem",
|
|
@@ -2708,7 +2693,7 @@ var no_unused_state_default = createRule({
|
|
|
2708
2693
|
return;
|
|
2709
2694
|
}
|
|
2710
2695
|
if (node.static) {
|
|
2711
|
-
if (isGetDerivedStateFromProps(node) &&
|
|
2696
|
+
if (isGetDerivedStateFromProps(node) && isMatching({ params: [P.nonNullable, ...P.array()] })(node.value)) {
|
|
2712
2697
|
const defNode = stateDefs.get(currentClass)?.node;
|
|
2713
2698
|
stateDefs.set(currentClass, { node: defNode, isUsed: true });
|
|
2714
2699
|
}
|
|
@@ -3101,7 +3086,7 @@ var prefer_shorthand_boolean_default = createRule({
|
|
|
3101
3086
|
return {
|
|
3102
3087
|
JSXAttribute(node) {
|
|
3103
3088
|
const { value } = node;
|
|
3104
|
-
const propName = JSX7.
|
|
3089
|
+
const propName = JSX7.getAttributeName(node);
|
|
3105
3090
|
const hasValueTrue = value?.type === AST_NODE_TYPES.JSXExpressionContainer && value.expression.type === AST_NODE_TYPES.Literal && value.expression.value === true;
|
|
3106
3091
|
if (!hasValueTrue) {
|
|
3107
3092
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.9",
|
|
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,23 +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/ast": "1.24.0-next.
|
|
52
|
-
"@eslint-react/core": "1.24.0-next.
|
|
53
|
-
"@eslint-react/eff": "1.24.0-next.
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/var": "1.24.0-next.
|
|
51
|
+
"@eslint-react/ast": "1.24.0-next.9",
|
|
52
|
+
"@eslint-react/core": "1.24.0-next.9",
|
|
53
|
+
"@eslint-react/eff": "1.24.0-next.9",
|
|
54
|
+
"@eslint-react/shared": "1.24.0-next.9",
|
|
55
|
+
"@eslint-react/jsx": "1.24.0-next.9",
|
|
56
|
+
"@eslint-react/var": "1.24.0-next.9"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@types/react": "^19.0.
|
|
59
|
+
"@types/react": "^19.0.7",
|
|
60
60
|
"@types/react-dom": "^19.0.3",
|
|
61
61
|
"ts-api-utils": "^2.0.0",
|
|
62
62
|
"tsup": "^8.3.5",
|