eslint-plugin-react-x 1.26.3-next.2 → 1.26.3-next.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.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var JSX7 = require('@eslint-react/jsx');
|
|
4
3
|
var shared = require('@eslint-react/shared');
|
|
4
|
+
var JSX7 = require('@eslint-react/jsx');
|
|
5
5
|
var AST11 = require('@eslint-react/ast');
|
|
6
6
|
var core = require('@eslint-react/core');
|
|
7
7
|
var eff = require('@eslint-react/eff');
|
|
@@ -40,9 +40,104 @@ var AST11__namespace = /*#__PURE__*/_interopNamespace(AST11);
|
|
|
40
40
|
var VAR__namespace = /*#__PURE__*/_interopNamespace(VAR);
|
|
41
41
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
42
42
|
|
|
43
|
+
var __defProp = Object.defineProperty;
|
|
44
|
+
var __export = (target, all) => {
|
|
45
|
+
for (var name5 in all)
|
|
46
|
+
__defProp(target, name5, { get: all[name5], enumerable: true });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/configs/recommended.ts
|
|
50
|
+
var recommended_exports = {};
|
|
51
|
+
__export(recommended_exports, {
|
|
52
|
+
name: () => name,
|
|
53
|
+
rules: () => rules,
|
|
54
|
+
settings: () => settings
|
|
55
|
+
});
|
|
56
|
+
var name = "react-x/recommended";
|
|
57
|
+
var rules = {
|
|
58
|
+
"react-x/ensure-forward-ref-using-ref": "warn",
|
|
59
|
+
"react-x/no-access-state-in-setstate": "error",
|
|
60
|
+
"react-x/no-array-index-key": "warn",
|
|
61
|
+
"react-x/no-children-count": "warn",
|
|
62
|
+
"react-x/no-children-for-each": "warn",
|
|
63
|
+
"react-x/no-children-map": "warn",
|
|
64
|
+
"react-x/no-children-only": "warn",
|
|
65
|
+
"react-x/no-children-to-array": "warn",
|
|
66
|
+
"react-x/no-clone-element": "warn",
|
|
67
|
+
"react-x/no-comment-textnodes": "warn",
|
|
68
|
+
"react-x/no-component-will-mount": "error",
|
|
69
|
+
"react-x/no-component-will-receive-props": "error",
|
|
70
|
+
"react-x/no-component-will-update": "error",
|
|
71
|
+
"react-x/no-context-provider": "warn",
|
|
72
|
+
"react-x/no-create-ref": "error",
|
|
73
|
+
"react-x/no-default-props": "error",
|
|
74
|
+
"react-x/no-direct-mutation-state": "error",
|
|
75
|
+
"react-x/no-duplicate-jsx-props": "warn",
|
|
76
|
+
"react-x/no-duplicate-key": "warn",
|
|
77
|
+
"react-x/no-forward-ref": "warn",
|
|
78
|
+
"react-x/no-implicit-key": "warn",
|
|
79
|
+
"react-x/no-missing-key": "error",
|
|
80
|
+
"react-x/no-nested-components": "error",
|
|
81
|
+
"react-x/no-prop-types": "error",
|
|
82
|
+
"react-x/no-redundant-should-component-update": "error",
|
|
83
|
+
"react-x/no-set-state-in-component-did-mount": "warn",
|
|
84
|
+
"react-x/no-set-state-in-component-did-update": "warn",
|
|
85
|
+
"react-x/no-set-state-in-component-will-update": "warn",
|
|
86
|
+
"react-x/no-string-refs": "error",
|
|
87
|
+
"react-x/no-unsafe-component-will-mount": "warn",
|
|
88
|
+
"react-x/no-unsafe-component-will-receive-props": "warn",
|
|
89
|
+
"react-x/no-unsafe-component-will-update": "warn",
|
|
90
|
+
"react-x/no-unstable-context-value": "warn",
|
|
91
|
+
"react-x/no-unstable-default-props": "warn",
|
|
92
|
+
"react-x/no-unused-class-component-members": "warn",
|
|
93
|
+
"react-x/no-unused-state": "warn",
|
|
94
|
+
"react-x/no-use-context": "warn",
|
|
95
|
+
"react-x/use-jsx-vars": "warn"
|
|
96
|
+
};
|
|
97
|
+
var settings = {
|
|
98
|
+
"react-x": shared.DEFAULT_ESLINT_REACT_SETTINGS
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/configs/recommended-type-checked.ts
|
|
102
|
+
var recommended_type_checked_exports = {};
|
|
103
|
+
__export(recommended_type_checked_exports, {
|
|
104
|
+
name: () => name3,
|
|
105
|
+
rules: () => rules3,
|
|
106
|
+
settings: () => settings3
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// src/configs/recommended-typescript.ts
|
|
110
|
+
var recommended_typescript_exports = {};
|
|
111
|
+
__export(recommended_typescript_exports, {
|
|
112
|
+
name: () => name2,
|
|
113
|
+
rules: () => rules2,
|
|
114
|
+
settings: () => settings2
|
|
115
|
+
});
|
|
116
|
+
var name2 = "react-x/recommended-typescript";
|
|
117
|
+
var rules2 = {
|
|
118
|
+
...rules,
|
|
119
|
+
"react-x/dom/no-unknown-property": "off",
|
|
120
|
+
"react-x/no-duplicate-jsx-props": "off",
|
|
121
|
+
"react-x/use-jsx-vars": "off"
|
|
122
|
+
};
|
|
123
|
+
var settings2 = {
|
|
124
|
+
...settings
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/configs/recommended-type-checked.ts
|
|
128
|
+
var name3 = "react-x/recommended-type-checked";
|
|
129
|
+
var rules3 = {
|
|
130
|
+
...rules2,
|
|
131
|
+
"react-x/no-leaked-conditional-rendering": "warn"
|
|
132
|
+
// "react-x/prefer-read-only-props": "warn",
|
|
133
|
+
};
|
|
134
|
+
var settings3 = {
|
|
135
|
+
...settings2
|
|
136
|
+
};
|
|
137
|
+
|
|
43
138
|
// package.json
|
|
44
|
-
var
|
|
45
|
-
var version = "1.26.3-next.
|
|
139
|
+
var name4 = "eslint-plugin-react-x";
|
|
140
|
+
var version = "1.26.3-next.21";
|
|
46
141
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
142
|
|
|
48
143
|
// src/utils/get-associated-tokens.ts
|
|
@@ -279,7 +374,7 @@ var no_access_state_in_setstate_default = createRule({
|
|
|
279
374
|
if (setState == null || hasThisState) {
|
|
280
375
|
return;
|
|
281
376
|
}
|
|
282
|
-
if (
|
|
377
|
+
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
283
378
|
return;
|
|
284
379
|
}
|
|
285
380
|
const hasState = node.id.properties.some(
|
|
@@ -313,8 +408,8 @@ var iteratorFunctionIndexParamPosition = /* @__PURE__ */ new Map([
|
|
|
313
408
|
["reduceRight", 2],
|
|
314
409
|
["some", 1]
|
|
315
410
|
]);
|
|
316
|
-
function isReactChildrenMethod(
|
|
317
|
-
return reactChildrenMethod.some((method) => method ===
|
|
411
|
+
function isReactChildrenMethod(name5) {
|
|
412
|
+
return reactChildrenMethod.some((method) => method === name5);
|
|
318
413
|
}
|
|
319
414
|
function isUsingReactChildren(node, context) {
|
|
320
415
|
const { importSource = "react" } = shared.unsafeDecodeSettings(context.settings);
|
|
@@ -342,8 +437,8 @@ function getMapIndexParamName(node, context) {
|
|
|
342
437
|
if (callee.property.type !== types.AST_NODE_TYPES.Identifier) {
|
|
343
438
|
return eff._;
|
|
344
439
|
}
|
|
345
|
-
const { name:
|
|
346
|
-
if (!iteratorFunctionIndexParamPosition.has(
|
|
440
|
+
const { name: name5 } = callee.property;
|
|
441
|
+
if (!iteratorFunctionIndexParamPosition.has(name5)) {
|
|
347
442
|
return eff._;
|
|
348
443
|
}
|
|
349
444
|
const callbackArg = node.arguments[isUsingReactChildren(node, context) ? 1 : 0];
|
|
@@ -354,7 +449,7 @@ function getMapIndexParamName(node, context) {
|
|
|
354
449
|
return eff._;
|
|
355
450
|
}
|
|
356
451
|
const { params } = callbackArg;
|
|
357
|
-
const indexParamPosition = iteratorFunctionIndexParamPosition.get(
|
|
452
|
+
const indexParamPosition = iteratorFunctionIndexParamPosition.get(name5);
|
|
358
453
|
if (indexParamPosition == null) {
|
|
359
454
|
return eff._;
|
|
360
455
|
}
|
|
@@ -380,7 +475,7 @@ var no_array_index_key_default = createRule({
|
|
|
380
475
|
create(context) {
|
|
381
476
|
const indexParamNames = [];
|
|
382
477
|
function isArrayIndex(node) {
|
|
383
|
-
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some((
|
|
478
|
+
return node.type === types.AST_NODE_TYPES.Identifier && indexParamNames.some((name5) => name5 != null && name5 === node.name);
|
|
384
479
|
}
|
|
385
480
|
function isCreateOrCloneElementCall(node) {
|
|
386
481
|
return core.isCreateElementCall(node, context) || core.isCloneElementCall(node, context);
|
|
@@ -389,7 +484,7 @@ var no_array_index_key_default = createRule({
|
|
|
389
484
|
switch (node.type) {
|
|
390
485
|
// key={bar}
|
|
391
486
|
case types.AST_NODE_TYPES.Identifier: {
|
|
392
|
-
if (indexParamNames.some((
|
|
487
|
+
if (indexParamNames.some((name5) => name5 != null && name5 === node.name)) {
|
|
393
488
|
return [{
|
|
394
489
|
messageId: "noArrayIndexKey",
|
|
395
490
|
node
|
|
@@ -699,7 +794,7 @@ var no_class_component_default = createRule({
|
|
|
699
794
|
...listeners,
|
|
700
795
|
"Program:exit"(node) {
|
|
701
796
|
const components = ctx.getAllComponents(node);
|
|
702
|
-
for (const { name:
|
|
797
|
+
for (const { name: name5 = "anonymous", node: component } of components.values()) {
|
|
703
798
|
if (component.body.body.some((m) => core.isComponentDidCatch(m) || core.isGetDerivedStateFromError(m))) {
|
|
704
799
|
continue;
|
|
705
800
|
}
|
|
@@ -707,7 +802,7 @@ var no_class_component_default = createRule({
|
|
|
707
802
|
messageId: "noClassComponent",
|
|
708
803
|
node: component,
|
|
709
804
|
data: {
|
|
710
|
-
name:
|
|
805
|
+
name: name5
|
|
711
806
|
}
|
|
712
807
|
});
|
|
713
808
|
}
|
|
@@ -1025,8 +1120,8 @@ var no_context_provider_default = createRule({
|
|
|
1025
1120
|
}
|
|
1026
1121
|
return {
|
|
1027
1122
|
JSXElement(node) {
|
|
1028
|
-
const [
|
|
1029
|
-
if (
|
|
1123
|
+
const [name5, ...rest] = JSX7__namespace.getElementName(node).split(".").reverse();
|
|
1124
|
+
if (name5 !== "Provider") return;
|
|
1030
1125
|
const contextName = rest.reverse().join(".");
|
|
1031
1126
|
context.report({
|
|
1032
1127
|
messageId: "noContextProvider",
|
|
@@ -1223,12 +1318,12 @@ var no_duplicate_jsx_props_default = createRule({
|
|
|
1223
1318
|
if (attr.type === types.AST_NODE_TYPES.JSXSpreadAttribute) {
|
|
1224
1319
|
continue;
|
|
1225
1320
|
}
|
|
1226
|
-
const
|
|
1227
|
-
if (typeof
|
|
1321
|
+
const name5 = attr.name.name;
|
|
1322
|
+
if (typeof name5 !== "string") {
|
|
1228
1323
|
continue;
|
|
1229
1324
|
}
|
|
1230
|
-
if (!props.includes(
|
|
1231
|
-
props.push(
|
|
1325
|
+
if (!props.includes(name5)) {
|
|
1326
|
+
props.push(name5);
|
|
1232
1327
|
continue;
|
|
1233
1328
|
}
|
|
1234
1329
|
context.report({
|
|
@@ -1693,8 +1788,8 @@ var no_missing_key_default = createRule({
|
|
|
1693
1788
|
[Symbol.for("rule_features")]: RULE_FEATURES29
|
|
1694
1789
|
},
|
|
1695
1790
|
messages: {
|
|
1696
|
-
|
|
1697
|
-
|
|
1791
|
+
missingKey: "Missing 'key' for element when rendering list.",
|
|
1792
|
+
unexpectedFragmentSyntax: "Use fragment component instead of '<>' because it does not support `key`."
|
|
1698
1793
|
},
|
|
1699
1794
|
schema: []
|
|
1700
1795
|
},
|
|
@@ -1707,7 +1802,7 @@ var no_missing_key_default = createRule({
|
|
|
1707
1802
|
const initialScope = context.sourceCode.getScope(node);
|
|
1708
1803
|
if (!JSX7__namespace.hasAttribute("key", node.openingElement.attributes, initialScope)) {
|
|
1709
1804
|
return {
|
|
1710
|
-
messageId: "
|
|
1805
|
+
messageId: "missingKey",
|
|
1711
1806
|
node
|
|
1712
1807
|
};
|
|
1713
1808
|
}
|
|
@@ -1715,7 +1810,7 @@ var no_missing_key_default = createRule({
|
|
|
1715
1810
|
}
|
|
1716
1811
|
case types.AST_NODE_TYPES.JSXFragment: {
|
|
1717
1812
|
return {
|
|
1718
|
-
messageId: "
|
|
1813
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1719
1814
|
node
|
|
1720
1815
|
};
|
|
1721
1816
|
}
|
|
@@ -1768,7 +1863,7 @@ var no_missing_key_default = createRule({
|
|
|
1768
1863
|
for (const element of elements) {
|
|
1769
1864
|
if (!JSX7__namespace.hasAttribute("key", element.openingElement.attributes, initialScope)) {
|
|
1770
1865
|
context.report({
|
|
1771
|
-
messageId: "
|
|
1866
|
+
messageId: "missingKey",
|
|
1772
1867
|
node: element
|
|
1773
1868
|
});
|
|
1774
1869
|
}
|
|
@@ -1810,7 +1905,7 @@ var no_missing_key_default = createRule({
|
|
|
1810
1905
|
}
|
|
1811
1906
|
if (node.parent.type === types.AST_NODE_TYPES.ArrayExpression) {
|
|
1812
1907
|
context.report({
|
|
1813
|
-
messageId: "
|
|
1908
|
+
messageId: "unexpectedFragmentSyntax",
|
|
1814
1909
|
node
|
|
1815
1910
|
});
|
|
1816
1911
|
}
|
|
@@ -1860,11 +1955,11 @@ var no_nested_components_default = createRule({
|
|
|
1860
1955
|
const isClassComponent11 = (node2) => {
|
|
1861
1956
|
return AST11__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
|
|
1862
1957
|
};
|
|
1863
|
-
for (const { name:
|
|
1958
|
+
for (const { name: name5, node: component } of functionComponents) {
|
|
1864
1959
|
if (core.isDirectValueOfRenderPropertyLoose(component)) {
|
|
1865
1960
|
continue;
|
|
1866
1961
|
}
|
|
1867
|
-
if (
|
|
1962
|
+
if (name5 === eff._) {
|
|
1868
1963
|
continue;
|
|
1869
1964
|
}
|
|
1870
1965
|
const isInsideProperty = component.parent.type === types.AST_NODE_TYPES.Property;
|
|
@@ -1875,7 +1970,7 @@ var no_nested_components_default = createRule({
|
|
|
1875
1970
|
messageId: "nestedComponentInProps",
|
|
1876
1971
|
node: component,
|
|
1877
1972
|
data: {
|
|
1878
|
-
name:
|
|
1973
|
+
name: name5
|
|
1879
1974
|
}
|
|
1880
1975
|
});
|
|
1881
1976
|
}
|
|
@@ -1886,19 +1981,19 @@ var no_nested_components_default = createRule({
|
|
|
1886
1981
|
messageId: "nestedComponentInProps",
|
|
1887
1982
|
node: component,
|
|
1888
1983
|
data: {
|
|
1889
|
-
name:
|
|
1984
|
+
name: name5
|
|
1890
1985
|
}
|
|
1891
1986
|
});
|
|
1892
1987
|
continue;
|
|
1893
1988
|
}
|
|
1894
1989
|
const parentComponent = AST11__namespace.findParentNode(component, isFunctionComponent);
|
|
1895
|
-
const
|
|
1896
|
-
if (
|
|
1990
|
+
const isParentComponentNotDirectValueOfRenderProperty = parentComponent != null && !core.isDirectValueOfRenderPropertyLoose(parentComponent);
|
|
1991
|
+
if (isParentComponentNotDirectValueOfRenderProperty) {
|
|
1897
1992
|
context.report({
|
|
1898
1993
|
messageId: isInsideProperty ? "nestedComponentInProps" : "nestedComponent",
|
|
1899
1994
|
node: component,
|
|
1900
1995
|
data: {
|
|
1901
|
-
name:
|
|
1996
|
+
name: name5
|
|
1902
1997
|
}
|
|
1903
1998
|
});
|
|
1904
1999
|
continue;
|
|
@@ -1908,12 +2003,12 @@ var no_nested_components_default = createRule({
|
|
|
1908
2003
|
messageId: "nestedComponent",
|
|
1909
2004
|
node: component,
|
|
1910
2005
|
data: {
|
|
1911
|
-
name:
|
|
2006
|
+
name: name5
|
|
1912
2007
|
}
|
|
1913
2008
|
});
|
|
1914
2009
|
}
|
|
1915
2010
|
}
|
|
1916
|
-
for (const { name:
|
|
2011
|
+
for (const { name: name5 = "unknown", node: component } of classComponents) {
|
|
1917
2012
|
if (AST11__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
|
|
1918
2013
|
continue;
|
|
1919
2014
|
}
|
|
@@ -1921,7 +2016,7 @@ var no_nested_components_default = createRule({
|
|
|
1921
2016
|
messageId: "nestedComponent",
|
|
1922
2017
|
node: component,
|
|
1923
2018
|
data: {
|
|
1924
|
-
name:
|
|
2019
|
+
name: name5
|
|
1925
2020
|
}
|
|
1926
2021
|
});
|
|
1927
2022
|
}
|
|
@@ -2014,7 +2109,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2014
2109
|
...listeners,
|
|
2015
2110
|
"Program:exit"(node) {
|
|
2016
2111
|
const components = ctx.getAllComponents(node);
|
|
2017
|
-
for (const { name:
|
|
2112
|
+
for (const { name: name5 = "PureComponent", node: component, flag } of components.values()) {
|
|
2018
2113
|
if ((flag & core.ERComponentFlag.PureComponent) === 0n) {
|
|
2019
2114
|
continue;
|
|
2020
2115
|
}
|
|
@@ -2025,7 +2120,7 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
2025
2120
|
messageId: "noRedundantShouldComponentUpdate",
|
|
2026
2121
|
node: member,
|
|
2027
2122
|
data: {
|
|
2028
|
-
componentName:
|
|
2123
|
+
componentName: name5
|
|
2029
2124
|
}
|
|
2030
2125
|
});
|
|
2031
2126
|
}
|
|
@@ -2364,9 +2459,7 @@ var no_unstable_context_value_default = createRule({
|
|
|
2364
2459
|
[Symbol.for("rule_features")]: RULE_FEATURES40
|
|
2365
2460
|
},
|
|
2366
2461
|
messages: {
|
|
2367
|
-
|
|
2368
|
-
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.",
|
|
2369
|
-
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."
|
|
2462
|
+
unstableContextValue: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}"
|
|
2370
2463
|
},
|
|
2371
2464
|
schema: []
|
|
2372
2465
|
},
|
|
@@ -2406,12 +2499,13 @@ var no_unstable_context_value_default = createRule({
|
|
|
2406
2499
|
for (const { node: component } of components) {
|
|
2407
2500
|
for (const construction of constructions.get(component) ?? []) {
|
|
2408
2501
|
const { kind, node: constructionNode } = construction;
|
|
2409
|
-
const
|
|
2502
|
+
const suggestion = kind.startsWith("Function") ? "Consider wrapping it in a useCallback hook." : "Consider wrapping it in a useMemo hook.";
|
|
2410
2503
|
context.report({
|
|
2411
|
-
messageId,
|
|
2504
|
+
messageId: "unstableContextValue",
|
|
2412
2505
|
node: constructionNode,
|
|
2413
2506
|
data: {
|
|
2414
|
-
type: AST11__namespace.toReadableNodeType(constructionNode)
|
|
2507
|
+
type: AST11__namespace.toReadableNodeType(constructionNode),
|
|
2508
|
+
suggestion
|
|
2415
2509
|
}
|
|
2416
2510
|
});
|
|
2417
2511
|
}
|
|
@@ -2451,8 +2545,8 @@ var no_unstable_default_props_default = createRule({
|
|
|
2451
2545
|
if (props == null) {
|
|
2452
2546
|
continue;
|
|
2453
2547
|
}
|
|
2454
|
-
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name:
|
|
2455
|
-
return declarators.get(component)?.filter((d) => d.init.name ===
|
|
2548
|
+
const properties = tsPattern.match(props).with({ type: types.AST_NODE_TYPES.ObjectPattern }, ({ properties: properties2 }) => properties2).with({ type: types.AST_NODE_TYPES.Identifier }, ({ name: name5 }) => {
|
|
2549
|
+
return declarators.get(component)?.filter((d) => d.init.name === name5).flatMap((d) => d.id.properties) ?? [];
|
|
2456
2550
|
}).otherwise(() => []);
|
|
2457
2551
|
for (const prop of properties) {
|
|
2458
2552
|
if (prop.type !== types.AST_NODE_TYPES.Property || prop.value.type !== types.AST_NODE_TYPES.AssignmentPattern) {
|
|
@@ -2810,7 +2904,7 @@ var no_unused_state_default = createRule({
|
|
|
2810
2904
|
if (!currentClass.body.body.includes(currentMethod)) {
|
|
2811
2905
|
return;
|
|
2812
2906
|
}
|
|
2813
|
-
if (
|
|
2907
|
+
if (node.init == null || !AST11__namespace.isThisExpression(node.init) || node.id.type !== types.AST_NODE_TYPES.ObjectPattern) {
|
|
2814
2908
|
return;
|
|
2815
2909
|
}
|
|
2816
2910
|
const hasState = node.id.properties.some((prop) => {
|
|
@@ -2850,9 +2944,9 @@ var no_use_context_default = createRule({
|
|
|
2850
2944
|
name: RULE_NAME44,
|
|
2851
2945
|
create(context) {
|
|
2852
2946
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
2853
|
-
const
|
|
2947
|
+
const settings4 = shared.getSettingsFromContext(context);
|
|
2854
2948
|
const useContextAlias = /* @__PURE__ */ new Set();
|
|
2855
|
-
if (compareVersions.compare(
|
|
2949
|
+
if (compareVersions.compare(settings4.version, "19.0.0", "<")) {
|
|
2856
2950
|
return {};
|
|
2857
2951
|
}
|
|
2858
2952
|
return {
|
|
@@ -2878,7 +2972,7 @@ var no_use_context_default = createRule({
|
|
|
2878
2972
|
});
|
|
2879
2973
|
},
|
|
2880
2974
|
ImportDeclaration(node) {
|
|
2881
|
-
if (node.source.value !==
|
|
2975
|
+
if (node.source.value !== settings4.importSource) {
|
|
2882
2976
|
return;
|
|
2883
2977
|
}
|
|
2884
2978
|
const isUseImported = node.specifiers.some(tsPattern.isMatching({ local: { type: types.AST_NODE_TYPES.Identifier, name: "use" } }));
|
|
@@ -2927,7 +3021,7 @@ function trimLikeReact(text) {
|
|
|
2927
3021
|
}
|
|
2928
3022
|
function checkAndReport(node, context, allowExpressions) {
|
|
2929
3023
|
function fix(fixer) {
|
|
2930
|
-
if (
|
|
3024
|
+
if (node.parent.type !== types.AST_NODE_TYPES.JSXElement && node.parent.type !== types.AST_NODE_TYPES.JSXFragment) {
|
|
2931
3025
|
if (node.children.length === 0) {
|
|
2932
3026
|
return null;
|
|
2933
3027
|
}
|
|
@@ -2950,10 +3044,24 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2950
3044
|
return;
|
|
2951
3045
|
}
|
|
2952
3046
|
if (JSX7__namespace.isBuiltInElement(node.parent)) {
|
|
2953
|
-
context.report({
|
|
3047
|
+
context.report({
|
|
3048
|
+
messageId: "uselessFragment",
|
|
3049
|
+
node,
|
|
3050
|
+
data: {
|
|
3051
|
+
reason: "placed inside a built-in component"
|
|
3052
|
+
},
|
|
3053
|
+
fix
|
|
3054
|
+
});
|
|
2954
3055
|
}
|
|
2955
3056
|
if (node.children.length === 0) {
|
|
2956
|
-
context.report({
|
|
3057
|
+
context.report({
|
|
3058
|
+
messageId: "uselessFragment",
|
|
3059
|
+
node,
|
|
3060
|
+
data: {
|
|
3061
|
+
reason: "contains less than two children"
|
|
3062
|
+
},
|
|
3063
|
+
fix
|
|
3064
|
+
});
|
|
2957
3065
|
return;
|
|
2958
3066
|
}
|
|
2959
3067
|
const isChildElement = AST11__namespace.isOneOf([types.AST_NODE_TYPES.JSXElement, types.AST_NODE_TYPES.JSXFragment])(node.parent);
|
|
@@ -2964,11 +3072,25 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2964
3072
|
}
|
|
2965
3073
|
// <Foo><>hello, world</></Foo>
|
|
2966
3074
|
case (!allowExpressions && isChildElement): {
|
|
2967
|
-
context.report({
|
|
3075
|
+
context.report({
|
|
3076
|
+
messageId: "uselessFragment",
|
|
3077
|
+
node,
|
|
3078
|
+
data: {
|
|
3079
|
+
reason: "contains less than two children"
|
|
3080
|
+
},
|
|
3081
|
+
fix
|
|
3082
|
+
});
|
|
2968
3083
|
return;
|
|
2969
3084
|
}
|
|
2970
3085
|
case (!allowExpressions && !isChildElement && node.children.length === 1): {
|
|
2971
|
-
context.report({
|
|
3086
|
+
context.report({
|
|
3087
|
+
messageId: "uselessFragment",
|
|
3088
|
+
node,
|
|
3089
|
+
data: {
|
|
3090
|
+
reason: "contains less than two children"
|
|
3091
|
+
},
|
|
3092
|
+
fix
|
|
3093
|
+
});
|
|
2972
3094
|
return;
|
|
2973
3095
|
}
|
|
2974
3096
|
}
|
|
@@ -2977,7 +3099,14 @@ function checkAndReport(node, context, allowExpressions) {
|
|
|
2977
3099
|
switch (true) {
|
|
2978
3100
|
case nonPaddingChildren.length === 0:
|
|
2979
3101
|
case (nonPaddingChildren.length === 1 && firstNonPaddingChild?.type !== types.AST_NODE_TYPES.JSXExpressionContainer): {
|
|
2980
|
-
context.report({
|
|
3102
|
+
context.report({
|
|
3103
|
+
messageId: "uselessFragment",
|
|
3104
|
+
node,
|
|
3105
|
+
data: {
|
|
3106
|
+
reason: "contains less than two children"
|
|
3107
|
+
},
|
|
3108
|
+
fix
|
|
3109
|
+
});
|
|
2981
3110
|
return;
|
|
2982
3111
|
}
|
|
2983
3112
|
}
|
|
@@ -2988,12 +3117,11 @@ var no_useless_fragment_default = createRule({
|
|
|
2988
3117
|
type: "problem",
|
|
2989
3118
|
defaultOptions: [...defaultOptions],
|
|
2990
3119
|
docs: {
|
|
2991
|
-
description: "disallow
|
|
3120
|
+
description: "disallow useless fragments"
|
|
2992
3121
|
},
|
|
2993
3122
|
fixable: "code",
|
|
2994
3123
|
messages: {
|
|
2995
|
-
|
|
2996
|
-
noUselessFragmentInBuiltIn: "A fragment placed inside a built-in component is unnecessary."
|
|
3124
|
+
uselessFragment: "A fragment {{reason}} is useless."
|
|
2997
3125
|
},
|
|
2998
3126
|
schema: [{
|
|
2999
3127
|
type: "object",
|
|
@@ -3299,7 +3427,7 @@ var use_jsx_vars_default = createRule({
|
|
|
3299
3427
|
meta: {
|
|
3300
3428
|
type: "problem",
|
|
3301
3429
|
docs: {
|
|
3302
|
-
description: "
|
|
3430
|
+
description: "marks variables used in JSX as used",
|
|
3303
3431
|
[Symbol.for("rule_features")]: RULE_FEATURES50
|
|
3304
3432
|
},
|
|
3305
3433
|
messages: {
|
|
@@ -3333,10 +3461,10 @@ var use_jsx_vars_default = createRule({
|
|
|
3333
3461
|
defaultOptions: []
|
|
3334
3462
|
});
|
|
3335
3463
|
|
|
3336
|
-
// src/
|
|
3337
|
-
var
|
|
3464
|
+
// src/plugin.ts
|
|
3465
|
+
var plugin = {
|
|
3338
3466
|
meta: {
|
|
3339
|
-
name,
|
|
3467
|
+
name: name4,
|
|
3340
3468
|
version
|
|
3341
3469
|
},
|
|
3342
3470
|
rules: {
|
|
@@ -3401,4 +3529,31 @@ var index_default = {
|
|
|
3401
3529
|
}
|
|
3402
3530
|
};
|
|
3403
3531
|
|
|
3532
|
+
// src/index.ts
|
|
3533
|
+
function makeConfig(config) {
|
|
3534
|
+
return {
|
|
3535
|
+
...config,
|
|
3536
|
+
plugins: {
|
|
3537
|
+
"react-x": plugin
|
|
3538
|
+
}
|
|
3539
|
+
};
|
|
3540
|
+
}
|
|
3541
|
+
function makeLegacyConfig({ rules: rules4 }) {
|
|
3542
|
+
return {
|
|
3543
|
+
plugins: ["react-x"],
|
|
3544
|
+
rules: rules4
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
var index_default = {
|
|
3548
|
+
...plugin,
|
|
3549
|
+
configs: {
|
|
3550
|
+
["recommended"]: makeConfig(recommended_exports),
|
|
3551
|
+
["recommended-legacy"]: makeLegacyConfig(recommended_exports),
|
|
3552
|
+
["recommended-type-checked"]: makeConfig(recommended_type_checked_exports),
|
|
3553
|
+
["recommended-type-checked-legacy"]: makeLegacyConfig(recommended_type_checked_exports),
|
|
3554
|
+
["recommended-typescript"]: makeConfig(recommended_typescript_exports),
|
|
3555
|
+
["recommended-typescript-legacy"]: makeLegacyConfig(recommended_typescript_exports)
|
|
3556
|
+
}
|
|
3557
|
+
};
|
|
3558
|
+
|
|
3404
3559
|
module.exports = index_default;
|