eslint-plugin-react-x 1.26.3-beta.2 → 1.26.3-beta.21
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/README.md +1 -4
- package/dist/index.d.mts +282 -64
- package/dist/index.d.ts +282 -64
- package/dist/index.js +217 -62
- package/dist/index.mjs +217 -62
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
1
2
|
import * as JSX7 from '@eslint-react/jsx';
|
|
2
|
-
import { createRuleForPlugin, getSettingsFromContext, unsafeDecodeSettings } from '@eslint-react/shared';
|
|
3
3
|
import * as AST11 from '@eslint-react/ast';
|
|
4
4
|
import { isForwardRefCall, isClassComponent, isThisSetState, isChildrenCount, isChildrenForEach, isChildrenMap, isChildrenOnly, isChildrenToArray, useComponentCollectorLegacy, isComponentDidCatch, isGetDerivedStateFromError, isCloneElementCall, isCreateRefCall, isComponentName, useComponentCollector, DEFAULT_COMPONENT_HINT, ERComponentFlag, isChildrenToArrayCall, ERComponentHint, isDirectValueOfRenderPropertyLoose, isDeclaredInRenderPropLoose, isInsideCreateElementProps, isInsideRenderMethod, isReactHookCall, isReactHookCallWithNameAlias, isCreateElementCall, isGetDerivedStateFromProps, isInitializedFromReact } from '@eslint-react/core';
|
|
5
5
|
import { _, getOrUpdate, identity } from '@eslint-react/eff';
|
|
@@ -13,9 +13,104 @@ import { unionTypeParts, isTypeFlagSet, isTrueLiteralType, isFalseLiteralType }
|
|
|
13
13
|
import ts from 'typescript';
|
|
14
14
|
import { getTypeImmutability, isUnknown, isImmutable, isReadonlyShallow, isReadonlyDeep } from 'is-immutable-type';
|
|
15
15
|
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __export = (target, all) => {
|
|
18
|
+
for (var name5 in all)
|
|
19
|
+
__defProp(target, name5, { get: all[name5], enumerable: true });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/configs/recommended.ts
|
|
23
|
+
var recommended_exports = {};
|
|
24
|
+
__export(recommended_exports, {
|
|
25
|
+
name: () => name,
|
|
26
|
+
rules: () => rules,
|
|
27
|
+
settings: () => settings
|
|
28
|
+
});
|
|
29
|
+
var name = "react-x/recommended";
|
|
30
|
+
var rules = {
|
|
31
|
+
"react-x/ensure-forward-ref-using-ref": "warn",
|
|
32
|
+
"react-x/no-access-state-in-setstate": "error",
|
|
33
|
+
"react-x/no-array-index-key": "warn",
|
|
34
|
+
"react-x/no-children-count": "warn",
|
|
35
|
+
"react-x/no-children-for-each": "warn",
|
|
36
|
+
"react-x/no-children-map": "warn",
|
|
37
|
+
"react-x/no-children-only": "warn",
|
|
38
|
+
"react-x/no-children-to-array": "warn",
|
|
39
|
+
"react-x/no-clone-element": "warn",
|
|
40
|
+
"react-x/no-comment-textnodes": "warn",
|
|
41
|
+
"react-x/no-component-will-mount": "error",
|
|
42
|
+
"react-x/no-component-will-receive-props": "error",
|
|
43
|
+
"react-x/no-component-will-update": "error",
|
|
44
|
+
"react-x/no-context-provider": "warn",
|
|
45
|
+
"react-x/no-create-ref": "error",
|
|
46
|
+
"react-x/no-default-props": "error",
|
|
47
|
+
"react-x/no-direct-mutation-state": "error",
|
|
48
|
+
"react-x/no-duplicate-jsx-props": "warn",
|
|
49
|
+
"react-x/no-duplicate-key": "warn",
|
|
50
|
+
"react-x/no-forward-ref": "warn",
|
|
51
|
+
"react-x/no-implicit-key": "warn",
|
|
52
|
+
"react-x/no-missing-key": "error",
|
|
53
|
+
"react-x/no-nested-components": "error",
|
|
54
|
+
"react-x/no-prop-types": "error",
|
|
55
|
+
"react-x/no-redundant-should-component-update": "error",
|
|
56
|
+
"react-x/no-set-state-in-component-did-mount": "warn",
|
|
57
|
+
"react-x/no-set-state-in-component-did-update": "warn",
|
|
58
|
+
"react-x/no-set-state-in-component-will-update": "warn",
|
|
59
|
+
"react-x/no-string-refs": "error",
|
|
60
|
+
"react-x/no-unsafe-component-will-mount": "warn",
|
|
61
|
+
"react-x/no-unsafe-component-will-receive-props": "warn",
|
|
62
|
+
"react-x/no-unsafe-component-will-update": "warn",
|
|
63
|
+
"react-x/no-unstable-context-value": "warn",
|
|
64
|
+
"react-x/no-unstable-default-props": "warn",
|
|
65
|
+
"react-x/no-unused-class-component-members": "warn",
|
|
66
|
+
"react-x/no-unused-state": "warn",
|
|
67
|
+
"react-x/no-use-context": "warn",
|
|
68
|
+
"react-x/use-jsx-vars": "warn"
|
|
69
|
+
};
|
|
70
|
+
var settings = {
|
|
71
|
+
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// src/configs/recommended-type-checked.ts
|
|
75
|
+
var recommended_type_checked_exports = {};
|
|
76
|
+
__export(recommended_type_checked_exports, {
|
|
77
|
+
name: () => name3,
|
|
78
|
+
rules: () => rules3,
|
|
79
|
+
settings: () => settings3
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// src/configs/recommended-typescript.ts
|
|
83
|
+
var recommended_typescript_exports = {};
|
|
84
|
+
__export(recommended_typescript_exports, {
|
|
85
|
+
name: () => name2,
|
|
86
|
+
rules: () => rules2,
|
|
87
|
+
settings: () => settings2
|
|
88
|
+
});
|
|
89
|
+
var name2 = "react-x/recommended-typescript";
|
|
90
|
+
var rules2 = {
|
|
91
|
+
...rules,
|
|
92
|
+
"react-x/dom/no-unknown-property": "off",
|
|
93
|
+
"react-x/no-duplicate-jsx-props": "off",
|
|
94
|
+
"react-x/use-jsx-vars": "off"
|
|
95
|
+
};
|
|
96
|
+
var settings2 = {
|
|
97
|
+
...settings
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/configs/recommended-type-checked.ts
|
|
101
|
+
var name3 = "react-x/recommended-type-checked";
|
|
102
|
+
var rules3 = {
|
|
103
|
+
...rules2,
|
|
104
|
+
"react-x/no-leaked-conditional-rendering": "warn"
|
|
105
|
+
// "react-x/prefer-read-only-props": "warn",
|
|
106
|
+
};
|
|
107
|
+
var settings3 = {
|
|
108
|
+
...settings2
|
|
109
|
+
};
|
|
110
|
+
|
|
16
111
|
// package.json
|
|
17
|
-
var
|
|
18
|
-
var version = "1.26.3-beta.
|
|
112
|
+
var name4 = "eslint-plugin-react-x";
|
|
113
|
+
var version = "1.26.3-beta.21";
|
|
19
114
|
var createRule = createRuleForPlugin("x");
|
|
20
115
|
|
|
21
116
|
// src/utils/get-associated-tokens.ts
|
|
@@ -252,7 +347,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
252
347
|
if (setState == null || hasThisState) {
|
|
253
348
|
return;
|
|
254
349
|
}
|
|
255
|
-
if (
|
|
350
|
+
if (node.init == null || !AST11.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
256
351
|
return;
|
|
257
352
|
}
|
|
258
353
|
const hasState = node.id.properties.some(
|
|
@@ -286,8 +381,8 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
286
381
|
["reduceRight", 2],
|
|
287
382
|
["some", 1]
|
|
288
383
|
]);
|
|
289
|
-
function isReactChildrenMethod(
|
|
290
|
-
return reactChildrenMethod.some((method) => method ===
|
|
384
|
+
function isReactChildrenMethod(name5) {
|
|
385
|
+
return reactChildrenMethod.some((method) => method === name5);
|
|
291
386
|
}
|
|
292
387
|
function isUsingReactChildren(node, context) {
|
|
293
388
|
const { importSource = "react" } = unsafeDecodeSettings(context.settings);
|
|
@@ -315,8 +410,8 @@ function getMapIndexParamName(node, context) {
|
|
|
315
410
|
if (callee.property.type !== AST_NODE_TYPES.Identifier) {
|
|
316
411
|
return _;
|
|
317
412
|
}
|
|
318
|
-
const { name:
|
|
319
|
-
if (!iteratorFunctionIndexParamPosition.has(
|
|
413
|
+
const { name: name5 } = callee.property;
|
|
414
|
+
if (!iteratorFunctionIndexParamPosition.has(name5)) {
|
|
320
415
|
return _;
|
|
321
416
|
}
|
|
322
417
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
@@ -327,7 +422,7 @@ function getMapIndexParamName(node, context) {
|
|
|
327
422
|
return _;
|
|
328
423
|
}
|
|
329
424
|
const { params } = callbackArg;
|
|
330
|
-
const indexParamPosition = iteratorFunctionIndexParamPosition.get(
|
|
425
|
+
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name5);
|
|
331
426
|
if (indexParamPosition == null) {
|
|
332
427
|
return _;
|
|
333
428
|
}
|
|
@@ -353,7 +448,7 @@ var no_array_index_key_default = createRule({
|
|
|
353
448
|
create(context) {
|
|
354
449
|
const indexParamNames = [];
|
|
355
450
|
function isArrayIndex(node) {
|
|
356
|
-
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((
|
|
451
|
+
return node.type === AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
357
452
|
}
|
|
358
453
|
function isCreateOrCloneElementCall(node) {
|
|
359
454
|
return isCreateElementCall(node, context) || isCloneElementCall(node, context);
|
|
@@ -362,7 +457,7 @@ var no_array_index_key_default = createRule({
|
|
|
362
457
|
switch (node.type) {
|
|
363
458
|
// key={bar}
|
|
364
459
|
case AST_NODE_TYPES.Identifier: {
|
|
365
|
-
if (indexParamNames.some((
|
|
460
|
+
if (indexParamNames.some((name5) => name5 != null && name5 === node.name)) {
|
|
366
461
|
return [{
|
|
367
462
|
messageId: "noArrayIndexKey",
|
|
368
463
|
node
|
|
@@ -672,7 +767,7 @@ var no_class_component_default = createRule({
|
|
|
672
767
|
...listeners,
|
|
673
768
|
"Program:exit"(node) {
|
|
674
769
|
const components = ctx.getAllComponents(node);
|
|
675
|
-
for (const { name:
|
|
770
|
+
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
676
771
|
if (component.body.body.some((m) => isComponentDidCatch(m) || isGetDerivedStateFromError(m))) {
|
|
677
772
|
continue;
|
|
678
773
|
}
|
|
@@ -680,7 +775,7 @@ var no_class_component_default = createRule({
|
|
|
680
775
|
messageId: "noClassComponent",
|
|
681
776
|
node: component,
|
|
682
777
|
data: {
|
|
683
|
-
name:
|
|
778
|
+
name: name5
|
|
684
779
|
}
|
|
685
780
|
});
|
|
686
781
|
}
|
|
@@ -998,8 +1093,8 @@ var no_context_provider_default = createRule({
|
|
|
998
1093
|
}
|
|
999
1094
|
return {
|
|
1000
1095
|
JSXElement(node) {
|
|
1001
|
-
const [
|
|
1002
|
-
if (
|
|
1096
|
+
const [name5, ...rest] = JSX7.getElementName(node).split(".").reverse();
|
|
1097
|
+
if (name5 !== "Provider") return;
|
|
1003
1098
|
const contextName = rest.reverse().join(".");
|
|
1004
1099
|
context.report({
|
|
1005
1100
|
messageId: "noContextProvider",
|
|
@@ -1196,12 +1291,12 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1196
1291
|
if (attr.type === AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1197
1292
|
continue;
|
|
1198
1293
|
}
|
|
1199
|
-
const
|
|
1200
|
-
if (typeof
|
|
1294
|
+
const name5 = attr.name.name;
|
|
1295
|
+
if (typeof name5 !== "string") {
|
|
1201
1296
|
continue;
|
|
1202
1297
|
}
|
|
1203
|
-
if (!props.includes(
|
|
1204
|
-
props.push(
|
|
1298
|
+
if (!props.includes(name5)) {
|
|
1299
|
+
props.push(name5);
|
|
1205
1300
|
continue;
|
|
1206
1301
|
}
|
|
1207
1302
|
context.report({
|
|
@@ -1666,8 +1761,8 @@ var no_missing_key_default = createRule({
|
|
|
1666
1761
|
[Symbol.for("rule_features")]: RULE_FEATURES29
|
|
1667
1762
|
},
|
|
1668
1763
|
messages: {
|
|
1669
|
-
|
|
1670
|
-
|
|
1764
|
+
missingKey: "Missing 'key' for element when rendering list.",
|
|
1765
|
+
unexpectedFragmentSyntax: "Use fragment component instead of '<>' because it does not support `key`."
|
|
1671
1766
|
},
|
|
1672
1767
|
schema: []
|
|
1673
1768
|
},
|
|
@@ -1680,7 +1775,7 @@ var no_missing_key_default = createRule({
|
|
|
1680
1775
|
const initialScope = context.sourceCode.getScope(node);
|
|
1681
1776
|
if (!JSX7.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1682
1777
|
return {
|
|
1683
|
-
messageId: "
|
|
1778
|
+
messageId: "missingKey",
|
|
1684
1779
|
node
|
|
1685
1780
|
};
|
|
1686
1781
|
}
|
|
@@ -1688,7 +1783,7 @@ var no_missing_key_default = createRule({
|
|
|
1688
1783
|
}
|
|
1689
1784
|
case AST_NODE_TYPES.JSXFragment: {
|
|
1690
1785
|
return {
|
|
1691
|
-
messageId: "
|
|
1786
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1692
1787
|
node
|
|
1693
1788
|
};
|
|
1694
1789
|
}
|
|
@@ -1741,7 +1836,7 @@ var no_missing_key_default = createRule({
|
|
|
1741
1836
|
for (const element of elements) {
|
|
1742
1837
|
if (!JSX7.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1743
1838
|
context.report({
|
|
1744
|
-
messageId: "
|
|
1839
|
+
messageId: "missingKey",
|
|
1745
1840
|
node: element
|
|
1746
1841
|
});
|
|
1747
1842
|
}
|
|
@@ -1783,7 +1878,7 @@ var no_missing_key_default = createRule({
|
|
|
1783
1878
|
}
|
|
1784
1879
|
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) {
|
|
1785
1880
|
context.report({
|
|
1786
|
-
messageId: "
|
|
1881
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1787
1882
|
node
|
|
1788
1883
|
});
|
|
1789
1884
|
}
|
|
@@ -1833,11 +1928,11 @@ var no_nested_components_default = createRule({
|
|
|
1833
1928
|
const isClassComponent11 = (node2) => {
|
|
1834
1929
|
return AST11.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1835
1930
|
};
|
|
1836
|
-
for (const { name:
|
|
1931
|
+
for (const { name: name5, node: component } of functionComponents) {
|
|
1837
1932
|
if (isDirectValueOfRenderPropertyLoose(component)) {
|
|
1838
1933
|
continue;
|
|
1839
1934
|
}
|
|
1840
|
-
if (
|
|
1935
|
+
if (name5 === _) {
|
|
1841
1936
|
continue;
|
|
1842
1937
|
}
|
|
1843
1938
|
const isInsideProperty = component.parent.type === AST_NODE_TYPES.Property;
|
|
@@ -1848,7 +1943,7 @@ var no_nested_components_default = createRule({
|
|
|
1848
1943
|
messageId: "nestedComponentInProps",
|
|
1849
1944
|
node: component,
|
|
1850
1945
|
data: {
|
|
1851
|
-
name:
|
|
1946
|
+
name: name5
|
|
1852
1947
|
}
|
|
1853
1948
|
});
|
|
1854
1949
|
}
|
|
@@ -1859,19 +1954,19 @@ var no_nested_components_default = createRule({
|
|
|
1859
1954
|
messageId: "nestedComponentInProps",
|
|
1860
1955
|
node: component,
|
|
1861
1956
|
data: {
|
|
1862
|
-
name:
|
|
1957
|
+
name: name5
|
|
1863
1958
|
}
|
|
1864
1959
|
});
|
|
1865
1960
|
continue;
|
|
1866
1961
|
}
|
|
1867
1962
|
const parentComponent = AST11.findParentNode(component, isFunctionComponent);
|
|
1868
|
-
const
|
|
1869
|
-
if (
|
|
1963
|
+
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1964
|
+
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
1870
1965
|
context.report({
|
|
1871
1966
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
1872
1967
|
node: component,
|
|
1873
1968
|
data: {
|
|
1874
|
-
name:
|
|
1969
|
+
name: name5
|
|
1875
1970
|
}
|
|
1876
1971
|
});
|
|
1877
1972
|
continue;
|
|
@@ -1881,12 +1976,12 @@ var no_nested_components_default = createRule({
|
|
|
1881
1976
|
messageId: "nestedComponent",
|
|
1882
1977
|
node: component,
|
|
1883
1978
|
data: {
|
|
1884
|
-
name:
|
|
1979
|
+
name: name5
|
|
1885
1980
|
}
|
|
1886
1981
|
});
|
|
1887
1982
|
}
|
|
1888
1983
|
}
|
|
1889
|
-
for (const { name:
|
|
1984
|
+
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
1890
1985
|
if (AST11.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
1891
1986
|
continue;
|
|
1892
1987
|
}
|
|
@@ -1894,7 +1989,7 @@ var no_nested_components_default = createRule({
|
|
|
1894
1989
|
messageId: "nestedComponent",
|
|
1895
1990
|
node: component,
|
|
1896
1991
|
data: {
|
|
1897
|
-
name:
|
|
1992
|
+
name: name5
|
|
1898
1993
|
}
|
|
1899
1994
|
});
|
|
1900
1995
|
}
|
|
@@ -1987,7 +2082,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1987
2082
|
...listeners,
|
|
1988
2083
|
"Program:exit"(node) {
|
|
1989
2084
|
const components = ctx.getAllComponents(node);
|
|
1990
|
-
for (const { name:
|
|
2085
|
+
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
1991
2086
|
if ((flag & ERComponentFlag.PureComponent) === 0n) {
|
|
1992
2087
|
continue;
|
|
1993
2088
|
}
|
|
@@ -1998,7 +2093,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1998
2093
|
messageId: "noRedundantShouldComponentUpdate",
|
|
1999
2094
|
node: member,
|
|
2000
2095
|
data: {
|
|
2001
|
-
componentName:
|
|
2096
|
+
componentName: name5
|
|
2002
2097
|
}
|
|
2003
2098
|
});
|
|
2004
2099
|
}
|
|
@@ -2337,9 +2432,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2337
2432
|
[Symbol.for("rule_features")]: RULE_FEATURES40
|
|
2338
2433
|
},
|
|
2339
2434
|
messages: {
|
|
2340
|
-
|
|
2341
|
-
noUnstableContextValueWithFunction: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. Consider wrapping it in a useCallback hook.",
|
|
2342
|
-
noUnstableContextValueWithIdentifier: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. Consider wrapping it in a useMemo hook."
|
|
2435
|
+
unstableContextValue: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}"
|
|
2343
2436
|
},
|
|
2344
2437
|
schema: []
|
|
2345
2438
|
},
|
|
@@ -2379,12 +2472,13 @@ var no_unstable_context_value_default = createRule({
|
|
|
2379
2472
|
for (const { node: component } of components) {
|
|
2380
2473
|
for (const construction of constructions.get(component) ?? []) {
|
|
2381
2474
|
const { kind, node: constructionNode } = construction;
|
|
2382
|
-
const
|
|
2475
|
+
const suggestion = kind.startsWith("Function") ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
2383
2476
|
context.report({
|
|
2384
|
-
messageId,
|
|
2477
|
+
messageId: "unstableContextValue",
|
|
2385
2478
|
node: constructionNode,
|
|
2386
2479
|
data: {
|
|
2387
|
-
type: AST11.toReadableNodeType(constructionNode)
|
|
2480
|
+
type: AST11.toReadableNodeType(constructionNode),
|
|
2481
|
+
suggestion
|
|
2388
2482
|
}
|
|
2389
2483
|
});
|
|
2390
2484
|
}
|
|
@@ -2424,8 +2518,8 @@ var no_unstable_default_props_default = createRule({
|
|
|
2424
2518
|
if (props == null) {
|
|
2425
2519
|
continue;
|
|
2426
2520
|
}
|
|
2427
|
-
const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name:
|
|
2428
|
-
return declarators.get(component)?.filter((d) => d.init.name ===
|
|
2521
|
+
const properties = match(props).with({ type: AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: AST_NODE_TYPES.Identifier }, ({ name: name5 }) => {
|
|
2522
|
+
return declarators.get(component)?.filter((d) => d.init.name === name5).flatMap((d) => d.id.properties) ?? [];
|
|
2429
2523
|
}).otherwise(() => []);
|
|
2430
2524
|
for (const prop of properties) {
|
|
2431
2525
|
if (prop.type !== AST_NODE_TYPES.Property || prop.value.type !== AST_NODE_TYPES.AssignmentPattern) {
|
|
@@ -2783,7 +2877,7 @@ var no_unused_state_default = createRule({
|
|
|
2783
2877
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2784
2878
|
return;
|
|
2785
2879
|
}
|
|
2786
|
-
if (
|
|
2880
|
+
if (node.init == null || !AST11.isThisExpression(node.init) || node.id.type !== AST_NODE_TYPES.ObjectPattern) {
|
|
2787
2881
|
return;
|
|
2788
2882
|
}
|
|
2789
2883
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -2823,9 +2917,9 @@ var no_use_context_default = createRule({
|
|
|
2823
2917
|
name: RULE_NAME44,
|
|
2824
2918
|
create(context) {
|
|
2825
2919
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
2826
|
-
const
|
|
2920
|
+
const settings4 = getSettingsFromContext(context);
|
|
2827
2921
|
const useContextAlias = /* @__PURE__ */ new Set();
|
|
2828
|
-
if (compare(
|
|
2922
|
+
if (compare(settings4.version, "19.0.0", "<")) {
|
|
2829
2923
|
return {};
|
|
2830
2924
|
}
|
|
2831
2925
|
return {
|
|
@@ -2851,7 +2945,7 @@ var no_use_context_default = createRule({
|
|
|
2851
2945
|
});
|
|
2852
2946
|
},
|
|
2853
2947
|
ImportDeclaration(node) {
|
|
2854
|
-
if (node.source.value !==
|
|
2948
|
+
if (node.source.value !== settings4.importSource) {
|
|
2855
2949
|
return;
|
|
2856
2950
|
}
|
|
2857
2951
|
const isUseImported = node.specifiers.some(isMatching({ local: { type: AST_NODE_TYPES.Identifier, name: "use" } }));
|
|
@@ -2900,7 +2994,7 @@ function trimLikeReact(text) {
|
|
|
2900
2994
|
}
|
|
2901
2995
|
function checkAndReport(node, context, allowExpressions) {
|
|
2902
2996
|
function fix(fixer) {
|
|
2903
|
-
if (
|
|
2997
|
+
if (node.parent.type !== AST_NODE_TYPES.JSXElement && node.parent.type !== AST_NODE_TYPES.JSXFragment) {
|
|
2904
2998
|
if (node.children.length === 0) {
|
|
2905
2999
|
return null;
|
|
2906
3000
|
}
|
|
@@ -2923,10 +3017,24 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2923
3017
|
return;
|
|
2924
3018
|
}
|
|
2925
3019
|
if (JSX7.isBuiltInElement(node.parent)) {
|
|
2926
|
-
context.report({
|
|
3020
|
+
context.report({
|
|
3021
|
+
messageId: "uselessFragment",
|
|
3022
|
+
node,
|
|
3023
|
+
data: {
|
|
3024
|
+
reason: "placed inside a built-in component"
|
|
3025
|
+
},
|
|
3026
|
+
fix
|
|
3027
|
+
});
|
|
2927
3028
|
}
|
|
2928
3029
|
if (node.children.length === 0) {
|
|
2929
|
-
context.report({
|
|
3030
|
+
context.report({
|
|
3031
|
+
messageId: "uselessFragment",
|
|
3032
|
+
node,
|
|
3033
|
+
data: {
|
|
3034
|
+
reason: "contains less than two children"
|
|
3035
|
+
},
|
|
3036
|
+
fix
|
|
3037
|
+
});
|
|
2930
3038
|
return;
|
|
2931
3039
|
}
|
|
2932
3040
|
const isChildElement = AST11.isOneOf([AST_NODE_TYPES.JSXElement, AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
@@ -2937,11 +3045,25 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2937
3045
|
}
|
|
2938
3046
|
// <Foo><>hello, world</></Foo>
|
|
2939
3047
|
case (!allowExpressions && isChildElement): {
|
|
2940
|
-
context.report({
|
|
3048
|
+
context.report({
|
|
3049
|
+
messageId: "uselessFragment",
|
|
3050
|
+
node,
|
|
3051
|
+
data: {
|
|
3052
|
+
reason: "contains less than two children"
|
|
3053
|
+
},
|
|
3054
|
+
fix
|
|
3055
|
+
});
|
|
2941
3056
|
return;
|
|
2942
3057
|
}
|
|
2943
3058
|
case (!allowExpressions && !isChildElement && node.children.length === 1): {
|
|
2944
|
-
context.report({
|
|
3059
|
+
context.report({
|
|
3060
|
+
messageId: "uselessFragment",
|
|
3061
|
+
node,
|
|
3062
|
+
data: {
|
|
3063
|
+
reason: "contains less than two children"
|
|
3064
|
+
},
|
|
3065
|
+
fix
|
|
3066
|
+
});
|
|
2945
3067
|
return;
|
|
2946
3068
|
}
|
|
2947
3069
|
}
|
|
@@ -2950,7 +3072,14 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2950
3072
|
switch (true) {
|
|
2951
3073
|
case nonPaddingChildren.length === 0:
|
|
2952
3074
|
case (nonPaddingChildren.length === 1 && firstNonPaddingChild?.type !== AST_NODE_TYPES.JSXExpressionContainer): {
|
|
2953
|
-
context.report({
|
|
3075
|
+
context.report({
|
|
3076
|
+
messageId: "uselessFragment",
|
|
3077
|
+
node,
|
|
3078
|
+
data: {
|
|
3079
|
+
reason: "contains less than two children"
|
|
3080
|
+
},
|
|
3081
|
+
fix
|
|
3082
|
+
});
|
|
2954
3083
|
return;
|
|
2955
3084
|
}
|
|
2956
3085
|
}
|
|
@@ -2961,12 +3090,11 @@ var no_useless_fragment_default = createRule({
|
|
|
2961
3090
|
type: "problem",
|
|
2962
3091
|
defaultOptions: [...defaultOptions],
|
|
2963
3092
|
docs: {
|
|
2964
|
-
description: "disallow
|
|
3093
|
+
description: "disallow useless fragments"
|
|
2965
3094
|
},
|
|
2966
3095
|
fixable: "code",
|
|
2967
3096
|
messages: {
|
|
2968
|
-
|
|
2969
|
-
noUselessFragmentInBuiltIn: "A fragment placed inside a built-in component is unnecessary."
|
|
3097
|
+
uselessFragment: "A fragment {{reason}} is useless."
|
|
2970
3098
|
},
|
|
2971
3099
|
schema: [{
|
|
2972
3100
|
type: "object",
|
|
@@ -3272,7 +3400,7 @@ var use_jsx_vars_default = createRule({
|
|
|
3272
3400
|
meta: {
|
|
3273
3401
|
type: "problem",
|
|
3274
3402
|
docs: {
|
|
3275
|
-
description: "
|
|
3403
|
+
description: "marks variables used in JSX as used",
|
|
3276
3404
|
[Symbol.for("rule_features")]: RULE_FEATURES50
|
|
3277
3405
|
},
|
|
3278
3406
|
messages: {
|
|
@@ -3306,10 +3434,10 @@ var use_jsx_vars_default = createRule({
|
|
|
3306
3434
|
defaultOptions: []
|
|
3307
3435
|
});
|
|
3308
3436
|
|
|
3309
|
-
// src/
|
|
3310
|
-
var
|
|
3437
|
+
// src/plugin.ts
|
|
3438
|
+
var plugin = {
|
|
3311
3439
|
meta: {
|
|
3312
|
-
name,
|
|
3440
|
+
name: name4,
|
|
3313
3441
|
version
|
|
3314
3442
|
},
|
|
3315
3443
|
rules: {
|
|
@@ -3374,4 +3502,31 @@ var index_default = {
|
|
|
3374
3502
|
}
|
|
3375
3503
|
};
|
|
3376
3504
|
|
|
3505
|
+
// src/index.ts
|
|
3506
|
+
function makeConfig(config) {
|
|
3507
|
+
return {
|
|
3508
|
+
...config,
|
|
3509
|
+
plugins: {
|
|
3510
|
+
"react-x": plugin
|
|
3511
|
+
}
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
function makeLegacyConfig({ rules: rules4 }) {
|
|
3515
|
+
return {
|
|
3516
|
+
plugins: ["react-x"],
|
|
3517
|
+
rules: rules4
|
|
3518
|
+
};
|
|
3519
|
+
}
|
|
3520
|
+
var index_default = {
|
|
3521
|
+
...plugin,
|
|
3522
|
+
configs: {
|
|
3523
|
+
["recommended"]: makeConfig(recommended_exports),
|
|
3524
|
+
["recommended-legacy"]: makeLegacyConfig(recommended_exports),
|
|
3525
|
+
["recommended-type-checked"]: makeConfig(recommended_type_checked_exports),
|
|
3526
|
+
["recommended-type-checked-legacy"]: makeLegacyConfig(recommended_type_checked_exports),
|
|
3527
|
+
["recommended-typescript"]: makeConfig(recommended_typescript_exports),
|
|
3528
|
+
["recommended-typescript-legacy"]: makeLegacyConfig(recommended_typescript_exports)
|
|
3529
|
+
}
|
|
3530
|
+
};
|
|
3531
|
+
|
|
3377
3532
|
export { index_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.26.3-beta.
|
|
3
|
+
"version": "1.26.3-beta.21",
|
|
4
4
|
"description": "A set of composable linting rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,27 +42,27 @@
|
|
|
42
42
|
"./package.json"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
46
|
-
"@typescript-eslint/type-utils": "^8.
|
|
47
|
-
"@typescript-eslint/types": "^8.
|
|
48
|
-
"@typescript-eslint/utils": "^8.
|
|
45
|
+
"@typescript-eslint/scope-manager": "^8.24.1",
|
|
46
|
+
"@typescript-eslint/type-utils": "^8.24.1",
|
|
47
|
+
"@typescript-eslint/types": "^8.24.1",
|
|
48
|
+
"@typescript-eslint/utils": "^8.24.1",
|
|
49
49
|
"compare-versions": "^6.1.1",
|
|
50
50
|
"is-immutable-type": "^5.0.1",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.6.2",
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
58
|
-
"@eslint-react/var": "1.26.3-beta.
|
|
53
|
+
"@eslint-react/ast": "1.26.3-beta.21",
|
|
54
|
+
"@eslint-react/core": "1.26.3-beta.21",
|
|
55
|
+
"@eslint-react/eff": "1.26.3-beta.21",
|
|
56
|
+
"@eslint-react/jsx": "1.26.3-beta.21",
|
|
57
|
+
"@eslint-react/shared": "1.26.3-beta.21",
|
|
58
|
+
"@eslint-react/var": "1.26.3-beta.21"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@types/react": "^19.0.
|
|
62
|
-
"@types/react-dom": "^19.0.
|
|
61
|
+
"@types/react": "^19.0.10",
|
|
62
|
+
"@types/react-dom": "^19.0.4",
|
|
63
63
|
"ts-api-utils": "^2.0.1",
|
|
64
64
|
"tsup": "^8.3.6",
|
|
65
|
-
"@
|
|
65
|
+
"@local/configs": "0.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
68
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
@@ -90,6 +90,6 @@
|
|
|
90
90
|
"scripts": {
|
|
91
91
|
"build": "tsup --dts-resolve",
|
|
92
92
|
"lint:publish": "publint",
|
|
93
|
-
"lint:
|
|
93
|
+
"lint:ts": "tsc --noEmit"
|
|
94
94
|
}
|
|
95
95
|
}
|