eslint-plugin-react-x 1.22.2-beta.7 → 1.22.2-beta.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 +40 -51
- package/dist/index.mjs +41 -52
- package/package.json +8 -8
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.22.2-beta.
|
|
45
|
+
var version = "1.22.2-beta.9";
|
|
46
46
|
var createRule = shared.createRuleForPlugin("x");
|
|
47
47
|
|
|
48
48
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -1123,15 +1123,13 @@ var no_duplicate_key_default = createRule({
|
|
|
1123
1123
|
},
|
|
1124
1124
|
name: RULE_NAME24,
|
|
1125
1125
|
create(context) {
|
|
1126
|
+
if (!context.sourceCode.getText().includes("key=")) return {};
|
|
1126
1127
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1127
1128
|
function isKeyValueEqual(a, b) {
|
|
1128
1129
|
const aValue = a.value;
|
|
1129
1130
|
const bValue = b.value;
|
|
1130
1131
|
if (aValue === null || bValue === null) return false;
|
|
1131
|
-
return
|
|
1132
|
-
context.sourceCode.getScope(aValue),
|
|
1133
|
-
context.sourceCode.getScope(bValue)
|
|
1134
|
-
]);
|
|
1132
|
+
return AST11__namespace.isNodeEqual(aValue, bValue);
|
|
1135
1133
|
}
|
|
1136
1134
|
return {
|
|
1137
1135
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1730,7 +1728,7 @@ var no_nested_components_default = createRule({
|
|
|
1730
1728
|
}
|
|
1731
1729
|
}
|
|
1732
1730
|
for (const { name: name2, node: component } of classComponents) {
|
|
1733
|
-
if (eff.O.isNone(AST11__namespace.traverseUp(component, (
|
|
1731
|
+
if (eff.O.isNone(AST11__namespace.traverseUp(component, eff.or(isClassComponent11, isFunctionComponent)))) {
|
|
1734
1732
|
continue;
|
|
1735
1733
|
}
|
|
1736
1734
|
context.report({
|
|
@@ -1860,22 +1858,19 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1860
1858
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
1861
1859
|
function getReportDescriptor(node) {
|
|
1862
1860
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
AST11__namespace.
|
|
1861
|
+
return eff.F.pipe(
|
|
1862
|
+
eff.O.Do,
|
|
1863
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1864
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidMount)),
|
|
1865
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1866
|
+
eff.O.filter(
|
|
1867
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1868
|
+
),
|
|
1869
|
+
eff.O.map(() => ({
|
|
1870
|
+
messageId: "noSetStateInComponentDidMount",
|
|
1871
|
+
node
|
|
1872
|
+
}))
|
|
1866
1873
|
);
|
|
1867
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
1868
|
-
const parentClass = maybeParentClass.value;
|
|
1869
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
1870
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidMount);
|
|
1871
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
1872
|
-
const parentMethod = maybeParentMethod.value;
|
|
1873
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
1874
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
1875
|
-
return eff.O.some({
|
|
1876
|
-
messageId: "noSetStateInComponentDidMount",
|
|
1877
|
-
node
|
|
1878
|
-
});
|
|
1879
1874
|
}
|
|
1880
1875
|
return {
|
|
1881
1876
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
@@ -1907,22 +1902,19 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1907
1902
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
1908
1903
|
function getReportDescriptor(node) {
|
|
1909
1904
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
AST11__namespace.
|
|
1905
|
+
return eff.F.pipe(
|
|
1906
|
+
eff.O.Do,
|
|
1907
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1908
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentDidUpdate)),
|
|
1909
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1910
|
+
eff.O.filter(
|
|
1911
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1912
|
+
),
|
|
1913
|
+
eff.O.map(() => ({
|
|
1914
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
1915
|
+
node
|
|
1916
|
+
}))
|
|
1913
1917
|
);
|
|
1914
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
1915
|
-
const parentClass = maybeParentClass.value;
|
|
1916
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
1917
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentDidUpdate);
|
|
1918
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
1919
|
-
const parentMethod = maybeParentMethod.value;
|
|
1920
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
1921
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
1922
|
-
return eff.O.some({
|
|
1923
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
1924
|
-
node
|
|
1925
|
-
});
|
|
1926
1918
|
}
|
|
1927
1919
|
return {
|
|
1928
1920
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
|
@@ -1954,22 +1946,19 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1954
1946
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1955
1947
|
function getReportDescriptor(node) {
|
|
1956
1948
|
if (!core.isThisSetState(node)) return eff.O.none();
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
AST11__namespace.
|
|
1949
|
+
return eff.F.pipe(
|
|
1950
|
+
eff.O.Do,
|
|
1951
|
+
eff.O.bind("clazz", () => AST11__namespace.traverseUpGuard(node, core.isClassComponent)),
|
|
1952
|
+
eff.O.bind("method", ({ clazz }) => AST11__namespace.traverseUpStop(node, clazz, isComponentWillUpdate3)),
|
|
1953
|
+
eff.O.bind("upperScope", () => eff.O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1954
|
+
eff.O.filter(
|
|
1955
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1956
|
+
),
|
|
1957
|
+
eff.O.map(() => ({
|
|
1958
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
1959
|
+
node
|
|
1960
|
+
}))
|
|
1960
1961
|
);
|
|
1961
|
-
if (eff.O.isNone(maybeParentClass)) return eff.O.none();
|
|
1962
|
-
const parentClass = maybeParentClass.value;
|
|
1963
|
-
if (!core.isClassComponent(parentClass)) return eff.O.none();
|
|
1964
|
-
const maybeParentMethod = AST11__namespace.traverseUp(node, isComponentWillUpdate3);
|
|
1965
|
-
if (eff.O.isNone(maybeParentMethod)) return eff.O.none();
|
|
1966
|
-
const parentMethod = maybeParentMethod.value;
|
|
1967
|
-
if (parentMethod.parent !== parentClass.body) return eff.O.none();
|
|
1968
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return eff.O.none();
|
|
1969
|
-
return eff.O.some({
|
|
1970
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
1971
|
-
node
|
|
1972
|
-
});
|
|
1973
1962
|
}
|
|
1974
1963
|
return {
|
|
1975
1964
|
CallExpression: eff.F.flow(getReportDescriptor, eff.O.map(context.report))
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F, O, isString, isNullable } from '@eslint-react/eff';
|
|
1
|
+
import { F, O, isString, or, isNullable } from '@eslint-react/eff';
|
|
2
2
|
import * as JSX7 from '@eslint-react/jsx';
|
|
3
3
|
import { createRuleForPlugin, normalizeSettings, decodeSettings, unsafeReadSettings } from '@eslint-react/shared';
|
|
4
4
|
import * as AST11 from '@eslint-react/ast';
|
|
@@ -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.22.2-beta.
|
|
18
|
+
var version = "1.22.2-beta.9";
|
|
19
19
|
var createRule = createRuleForPlugin("x");
|
|
20
20
|
|
|
21
21
|
// src/rules/avoid-shorthand-boolean.ts
|
|
@@ -1096,15 +1096,13 @@ var no_duplicate_key_default = createRule({
|
|
|
1096
1096
|
},
|
|
1097
1097
|
name: RULE_NAME24,
|
|
1098
1098
|
create(context) {
|
|
1099
|
+
if (!context.sourceCode.getText().includes("key=")) return {};
|
|
1099
1100
|
const keyedEntries = /* @__PURE__ */ new Map();
|
|
1100
1101
|
function isKeyValueEqual(a, b) {
|
|
1101
1102
|
const aValue = a.value;
|
|
1102
1103
|
const bValue = b.value;
|
|
1103
1104
|
if (aValue === null || bValue === null) return false;
|
|
1104
|
-
return
|
|
1105
|
-
context.sourceCode.getScope(aValue),
|
|
1106
|
-
context.sourceCode.getScope(bValue)
|
|
1107
|
-
]);
|
|
1105
|
+
return AST11.isNodeEqual(aValue, bValue);
|
|
1108
1106
|
}
|
|
1109
1107
|
return {
|
|
1110
1108
|
"JSXAttribute[name.name='key']"(node) {
|
|
@@ -1703,7 +1701,7 @@ var no_nested_components_default = createRule({
|
|
|
1703
1701
|
}
|
|
1704
1702
|
}
|
|
1705
1703
|
for (const { name: name2, node: component } of classComponents) {
|
|
1706
|
-
if (O.isNone(AST11.traverseUp(component, (
|
|
1704
|
+
if (O.isNone(AST11.traverseUp(component, or(isClassComponent11, isFunctionComponent)))) {
|
|
1707
1705
|
continue;
|
|
1708
1706
|
}
|
|
1709
1707
|
context.report({
|
|
@@ -1833,22 +1831,19 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
1833
1831
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
1834
1832
|
function getReportDescriptor(node) {
|
|
1835
1833
|
if (!isThisSetState(node)) return O.none();
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
AST11.
|
|
1834
|
+
return F.pipe(
|
|
1835
|
+
O.Do,
|
|
1836
|
+
O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
|
|
1837
|
+
O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentDidMount)),
|
|
1838
|
+
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1839
|
+
O.filter(
|
|
1840
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1841
|
+
),
|
|
1842
|
+
O.map(() => ({
|
|
1843
|
+
messageId: "noSetStateInComponentDidMount",
|
|
1844
|
+
node
|
|
1845
|
+
}))
|
|
1839
1846
|
);
|
|
1840
|
-
if (O.isNone(maybeParentClass)) return O.none();
|
|
1841
|
-
const parentClass = maybeParentClass.value;
|
|
1842
|
-
if (!isClassComponent(parentClass)) return O.none();
|
|
1843
|
-
const maybeParentMethod = AST11.traverseUp(node, isComponentDidMount);
|
|
1844
|
-
if (O.isNone(maybeParentMethod)) return O.none();
|
|
1845
|
-
const parentMethod = maybeParentMethod.value;
|
|
1846
|
-
if (parentMethod.parent !== parentClass.body) return O.none();
|
|
1847
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
|
|
1848
|
-
return O.some({
|
|
1849
|
-
messageId: "noSetStateInComponentDidMount",
|
|
1850
|
-
node
|
|
1851
|
-
});
|
|
1852
1847
|
}
|
|
1853
1848
|
return {
|
|
1854
1849
|
CallExpression: F.flow(getReportDescriptor, O.map(context.report))
|
|
@@ -1880,22 +1875,19 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
1880
1875
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
1881
1876
|
function getReportDescriptor(node) {
|
|
1882
1877
|
if (!isThisSetState(node)) return O.none();
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
AST11.
|
|
1878
|
+
return F.pipe(
|
|
1879
|
+
O.Do,
|
|
1880
|
+
O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
|
|
1881
|
+
O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentDidUpdate)),
|
|
1882
|
+
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1883
|
+
O.filter(
|
|
1884
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1885
|
+
),
|
|
1886
|
+
O.map(() => ({
|
|
1887
|
+
messageId: "noSetStateInComponentDidUpdate",
|
|
1888
|
+
node
|
|
1889
|
+
}))
|
|
1886
1890
|
);
|
|
1887
|
-
if (O.isNone(maybeParentClass)) return O.none();
|
|
1888
|
-
const parentClass = maybeParentClass.value;
|
|
1889
|
-
if (!isClassComponent(parentClass)) return O.none();
|
|
1890
|
-
const maybeParentMethod = AST11.traverseUp(node, isComponentDidUpdate);
|
|
1891
|
-
if (O.isNone(maybeParentMethod)) return O.none();
|
|
1892
|
-
const parentMethod = maybeParentMethod.value;
|
|
1893
|
-
if (parentMethod.parent !== parentClass.body) return O.none();
|
|
1894
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
|
|
1895
|
-
return O.some({
|
|
1896
|
-
messageId: "noSetStateInComponentDidUpdate",
|
|
1897
|
-
node
|
|
1898
|
-
});
|
|
1899
1891
|
}
|
|
1900
1892
|
return {
|
|
1901
1893
|
CallExpression: F.flow(getReportDescriptor, O.map(context.report))
|
|
@@ -1927,22 +1919,19 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
1927
1919
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
1928
1920
|
function getReportDescriptor(node) {
|
|
1929
1921
|
if (!isThisSetState(node)) return O.none();
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
AST11.
|
|
1922
|
+
return F.pipe(
|
|
1923
|
+
O.Do,
|
|
1924
|
+
O.bind("clazz", () => AST11.traverseUpGuard(node, isClassComponent)),
|
|
1925
|
+
O.bind("method", ({ clazz }) => AST11.traverseUpStop(node, clazz, isComponentWillUpdate3)),
|
|
1926
|
+
O.bind("upperScope", () => O.fromNullable(context.sourceCode.getScope(node).upper)),
|
|
1927
|
+
O.filter(
|
|
1928
|
+
({ clazz, method, upperScope }) => method.parent === clazz.body && upperScope === context.sourceCode.getScope(method)
|
|
1929
|
+
),
|
|
1930
|
+
O.map(() => ({
|
|
1931
|
+
messageId: "noSetStateInComponentWillUpdate",
|
|
1932
|
+
node
|
|
1933
|
+
}))
|
|
1933
1934
|
);
|
|
1934
|
-
if (O.isNone(maybeParentClass)) return O.none();
|
|
1935
|
-
const parentClass = maybeParentClass.value;
|
|
1936
|
-
if (!isClassComponent(parentClass)) return O.none();
|
|
1937
|
-
const maybeParentMethod = AST11.traverseUp(node, isComponentWillUpdate3);
|
|
1938
|
-
if (O.isNone(maybeParentMethod)) return O.none();
|
|
1939
|
-
const parentMethod = maybeParentMethod.value;
|
|
1940
|
-
if (parentMethod.parent !== parentClass.body) return O.none();
|
|
1941
|
-
if (context.sourceCode.getScope(node).upper !== context.sourceCode.getScope(parentMethod)) return O.none();
|
|
1942
|
-
return O.some({
|
|
1943
|
-
messageId: "noSetStateInComponentWillUpdate",
|
|
1944
|
-
node
|
|
1945
|
-
});
|
|
1946
1935
|
}
|
|
1947
1936
|
return {
|
|
1948
1937
|
CallExpression: F.flow(getReportDescriptor, O.map(context.report))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "1.22.2-beta.
|
|
3
|
+
"version": "1.22.2-beta.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",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"string-ts": "^2.2.0",
|
|
50
50
|
"ts-api-utils": "^2.0.0",
|
|
51
51
|
"ts-pattern": "^5.6.0",
|
|
52
|
-
"@eslint-react/ast": "1.22.2-beta.
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/jsx": "1.22.2-beta.
|
|
56
|
-
"@eslint-react/types": "1.22.2-beta.
|
|
57
|
-
"@eslint-react/shared": "1.22.2-beta.
|
|
58
|
-
"@eslint-react/var": "1.22.2-beta.
|
|
52
|
+
"@eslint-react/ast": "1.22.2-beta.9",
|
|
53
|
+
"@eslint-react/core": "1.22.2-beta.9",
|
|
54
|
+
"@eslint-react/eff": "1.22.2-beta.9",
|
|
55
|
+
"@eslint-react/jsx": "1.22.2-beta.9",
|
|
56
|
+
"@eslint-react/types": "1.22.2-beta.9",
|
|
57
|
+
"@eslint-react/shared": "1.22.2-beta.9",
|
|
58
|
+
"@eslint-react/var": "1.22.2-beta.9"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.0.2",
|