eslint-plugin-react-x 2.8.4-next.2 โ 2.9.0-beta.0
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 +111 -0
- package/dist/index.js +198 -197
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -38,4 +38,115 @@ export default defineConfig(
|
|
|
38
38
|
|
|
39
39
|
## Rules
|
|
40
40
|
|
|
41
|
+
### JSX
|
|
42
|
+
|
|
43
|
+
- [`jsx-dollar`](https://eslint-react.xyz/docs/rules/jsx-dollar) - Prevents unnecessary `$` symbols before JSX expressions (๐ง Fixable)
|
|
44
|
+
- [`jsx-key-before-spread`](https://eslint-react.xyz/docs/rules/jsx-key-before-spread) - Enforces `key` prop placement before spread props (๐งช Experimental)
|
|
45
|
+
- [`jsx-no-comment-textnodes`](https://eslint-react.xyz/docs/rules/jsx-no-comment-textnodes) - Prevents comment strings (e.g., beginning with `//` or `/*`) from being accidentally inserted into a JSX element's text nodes
|
|
46
|
+
- [`jsx-no-duplicate-props`](https://eslint-react.xyz/docs/rules/jsx-no-duplicate-props) - Disallows duplicate props in JSX elements
|
|
47
|
+
- [`jsx-no-iife`](https://eslint-react.xyz/docs/rules/jsx-no-iife) - Disallows immediately-invoked function expressions in JSX (๐งช Experimental)
|
|
48
|
+
- [`jsx-no-undef`](https://eslint-react.xyz/docs/rules/jsx-no-undef) - Prevents using variables in JSX that are not defined in the scope
|
|
49
|
+
- [`jsx-shorthand-boolean`](https://eslint-react.xyz/docs/rules/jsx-shorthand-boolean) - Enforces shorthand syntax for boolean props (๐ง Fixable, โ๏ธ Configurable)
|
|
50
|
+
- [`jsx-shorthand-fragment`](https://eslint-react.xyz/docs/rules/jsx-shorthand-fragment) - Enforces shorthand syntax for fragment elements (๐ง Fixable, โ๏ธ Configurable)
|
|
51
|
+
- [`jsx-uses-react`](https://eslint-react.xyz/docs/rules/jsx-uses-react) - Marks React variables as used when JSX is present
|
|
52
|
+
- [`jsx-uses-vars`](https://eslint-react.xyz/docs/rules/jsx-uses-vars) - Marks JSX element variables as used
|
|
53
|
+
|
|
54
|
+
### Key
|
|
55
|
+
|
|
56
|
+
- [`no-array-index-key`](https://eslint-react.xyz/docs/rules/no-array-index-key) - Disallows using an item's index in the array as its key
|
|
57
|
+
- [`no-create-ref`](https://eslint-react.xyz/docs/rules/no-create-ref) - Disallows `createRef` in function components
|
|
58
|
+
- [`no-duplicate-key`](https://eslint-react.xyz/docs/rules/no-duplicate-key) - Prevents duplicate `key` props on sibling elements when rendering lists
|
|
59
|
+
- [`no-implicit-key`](https://eslint-react.xyz/docs/rules/no-implicit-key) - Prevents `key` from not being explicitly specified (e.g., spreading `key` from objects) (๐งช Experimental)
|
|
60
|
+
- [`no-missing-key`](https://eslint-react.xyz/docs/rules/no-missing-key) - Disallows missing `key` on items in list rendering
|
|
61
|
+
- [`no-unnecessary-key`](https://eslint-react.xyz/docs/rules/no-unnecessary-key) - Disallows unnecessary `key` props on nested child elements when rendering lists (๐งช Experimental)
|
|
62
|
+
|
|
63
|
+
### Ref
|
|
64
|
+
|
|
65
|
+
- [`no-create-ref`](https://eslint-react.xyz/docs/rules/no-create-ref) - Disallows `createRef` in function components
|
|
66
|
+
- [`no-forward-ref`](https://eslint-react.xyz/docs/rules/no-forward-ref) - Replaces usage of `forwardRef` with passing `ref` as a prop (๐ Codemod, `React` >=19.0.0)
|
|
67
|
+
- [`no-unnecessary-use-ref`](https://eslint-react.xyz/docs/rules/no-unnecessary-use-ref) - Disallows unnecessary usage of `useRef` (๐งช Experimental)
|
|
68
|
+
- [`no-useless-forward-ref`](https://eslint-react.xyz/docs/rules/no-useless-forward-ref) - Disallows useless `forwardRef` calls on components that don't use `ref`s
|
|
69
|
+
|
|
70
|
+
### Props
|
|
71
|
+
|
|
72
|
+
- [`no-children-prop`](https://eslint-react.xyz/docs/rules/no-children-prop) - Disallows passing `children` as a prop
|
|
73
|
+
- [`no-default-props`](https://eslint-react.xyz/docs/rules/no-default-props) - Disallows the `defaultProps` property in favor of ES6 default parameters
|
|
74
|
+
- [`no-prop-types`](https://eslint-react.xyz/docs/rules/no-prop-types) - Disallows `propTypes` in favor of TypeScript or another type-checking solution
|
|
75
|
+
- [`no-unstable-default-props`](https://eslint-react.xyz/docs/rules/no-unstable-default-props) - Prevents using referential-type values as default props in object destructuring (โ๏ธ Configurable)
|
|
76
|
+
- [`no-unused-props`](https://eslint-react.xyz/docs/rules/no-unused-props) - Warns about component props that are defined but never used (๐ญ Type Checking, ๐งช Experimental)
|
|
77
|
+
- [`prefer-destructuring-assignment`](https://eslint-react.xyz/docs/rules/prefer-destructuring-assignment) - Enforces destructuring assignment for component props and context
|
|
78
|
+
- [`prefer-read-only-props`](https://eslint-react.xyz/docs/rules/prefer-read-only-props) - Enforces read-only props in components (๐ญ Type Checking, ๐งช Experimental)
|
|
79
|
+
|
|
80
|
+
### Context
|
|
81
|
+
|
|
82
|
+
- [`no-context-provider`](https://eslint-react.xyz/docs/rules/no-context-provider) - Replaces usage of `<Context.Provider>` with `<Context>` (๐ Codemod, `React` >=19.0.0)
|
|
83
|
+
- [`no-unstable-context-value`](https://eslint-react.xyz/docs/rules/no-unstable-context-value) - Prevents non-stable values (i.e., object literals) from being used as a value for `Context.Provider`
|
|
84
|
+
- [`no-use-context`](https://eslint-react.xyz/docs/rules/no-use-context) - Replaces usage of `useContext` with `use` (๐ Codemod, `React` >=19.0.0)
|
|
85
|
+
- [`prefer-destructuring-assignment`](https://eslint-react.xyz/docs/rules/prefer-destructuring-assignment) - Enforces destructuring assignment for component props and context
|
|
86
|
+
|
|
87
|
+
### Structure
|
|
88
|
+
|
|
89
|
+
- [`no-nested-component-definitions`](https://eslint-react.xyz/docs/rules/no-nested-component-definitions) - Disallows nesting component definitions inside other components
|
|
90
|
+
- [`no-nested-lazy-component-declarations`](https://eslint-react.xyz/docs/rules/no-nested-lazy-component-declarations) - Disallows nesting lazy component declarations inside other components
|
|
91
|
+
|
|
92
|
+
### Rendering
|
|
93
|
+
|
|
94
|
+
- [`no-leaked-conditional-rendering`](https://eslint-react.xyz/docs/rules/no-leaked-conditional-rendering) - Prevents problematic leaked values from being rendered
|
|
95
|
+
|
|
96
|
+
### Optimization
|
|
97
|
+
|
|
98
|
+
- [`no-unnecessary-use-callback`](https://eslint-react.xyz/docs/rules/no-unnecessary-use-callback) - Disallows unnecessary usage of `useCallback` (๐งช Experimental)
|
|
99
|
+
- [`no-unnecessary-use-memo`](https://eslint-react.xyz/docs/rules/no-unnecessary-use-memo) - Disallows unnecessary usage of `useMemo` (๐งช Experimental)
|
|
100
|
+
- [`no-unstable-context-value`](https://eslint-react.xyz/docs/rules/no-unstable-context-value) - Prevents non-stable values (i.e., object literals) from being used as a value for `Context.Provider`
|
|
101
|
+
- [`no-unstable-default-props`](https://eslint-react.xyz/docs/rules/no-unstable-default-props) - Prevents using referential-type values as default props in object destructuring (โ๏ธ Configurable)
|
|
102
|
+
- [`prefer-use-state-lazy-initialization`](https://eslint-react.xyz/docs/rules/prefer-use-state-lazy-initialization) - Enforces wrapping function calls made inside `useState` in an `initializer function`
|
|
103
|
+
|
|
104
|
+
### Legacy Element APIs
|
|
105
|
+
|
|
106
|
+
- [`no-clone-element`](https://eslint-react.xyz/docs/rules/no-clone-element) - Disallows `cloneElement`
|
|
107
|
+
|
|
108
|
+
### Legacy Children APIs
|
|
109
|
+
|
|
110
|
+
- [`no-children-count`](https://eslint-react.xyz/docs/rules/no-children-count) - Disallows the use of `Children.count` from the `react` package
|
|
111
|
+
- [`no-children-for-each`](https://eslint-react.xyz/docs/rules/no-children-for-each) - Disallows the use of `Children.forEach` from the `react` package
|
|
112
|
+
- [`no-children-map`](https://eslint-react.xyz/docs/rules/no-children-map) - Disallows the use of `Children.map` from the `react` package
|
|
113
|
+
- [`no-children-only`](https://eslint-react.xyz/docs/rules/no-children-only) - Disallows the use of `Children.only` from the `react` package
|
|
114
|
+
- [`no-children-to-array`](https://eslint-react.xyz/docs/rules/no-children-to-array) - Disallows the use of `Children.toArray` from the `react` package
|
|
115
|
+
|
|
116
|
+
### Legacy Component APIs
|
|
117
|
+
|
|
118
|
+
- [`no-access-state-in-setstate`](https://eslint-react.xyz/docs/rules/no-access-state-in-setstate) - Disallows accessing `this.state` inside `setState` calls
|
|
119
|
+
- [`no-class-component`](https://eslint-react.xyz/docs/rules/no-class-component) - Disallows class components except for error boundaries
|
|
120
|
+
- [`no-component-will-mount`](https://eslint-react.xyz/docs/rules/no-component-will-mount) - Replaces usage of `componentWillMount` with `UNSAFE_componentWillMount` (๐ Codemod, `React` >=16.3.0)
|
|
121
|
+
- [`no-component-will-receive-props`](https://eslint-react.xyz/docs/rules/no-component-will-receive-props) - Replaces usage of `componentWillReceiveProps` with `UNSAFE_componentWillReceiveProps` (๐ Codemod)
|
|
122
|
+
- [`no-component-will-update`](https://eslint-react.xyz/docs/rules/no-component-will-update) - Replaces usage of `componentWillUpdate` with `UNSAFE_componentWillUpdate` (๐ Codemod)
|
|
123
|
+
- [`no-direct-mutation-state`](https://eslint-react.xyz/docs/rules/no-direct-mutation-state) - Disallows direct mutation of `this.state`
|
|
124
|
+
- [`no-redundant-should-component-update`](https://eslint-react.xyz/docs/rules/no-redundant-should-component-update) - Disallows `shouldComponentUpdate` when extending `React.PureComponent`
|
|
125
|
+
- [`no-set-state-in-component-did-mount`](https://eslint-react.xyz/docs/rules/no-set-state-in-component-did-mount) - Disallows calling `this.setState` in `componentDidMount` outside functions such as callbacks
|
|
126
|
+
- [`no-set-state-in-component-did-update`](https://eslint-react.xyz/docs/rules/no-set-state-in-component-did-update) - Disallows calling `this.setState` in `componentDidUpdate` outside functions such as callbacks
|
|
127
|
+
- [`no-set-state-in-component-will-update`](https://eslint-react.xyz/docs/rules/no-set-state-in-component-will-update) - Disallows calling `this.setState` in `componentWillUpdate` outside functions such as callbacks
|
|
128
|
+
- [`no-string-refs`](https://eslint-react.xyz/docs/rules/no-string-refs) - Replaces string refs with callback refs (๐ Codemod, `React` >=16.3.0)
|
|
129
|
+
- [`no-unsafe-component-will-mount`](https://eslint-react.xyz/docs/rules/no-unsafe-component-will-mount) - Warns about the use of `UNSAFE_componentWillMount` in class components
|
|
130
|
+
- [`no-unsafe-component-will-receive-props`](https://eslint-react.xyz/docs/rules/no-unsafe-component-will-receive-props) - Warns about the use of `UNSAFE_componentWillReceiveProps` in class components
|
|
131
|
+
- [`no-unsafe-component-will-update`](https://eslint-react.xyz/docs/rules/no-unsafe-component-will-update) - Warns about the use of `UNSAFE_componentWillUpdate` in class components
|
|
132
|
+
- [`no-unused-class-component-members`](https://eslint-react.xyz/docs/rules/no-unused-class-component-members) - Warns about unused class component methods and properties
|
|
133
|
+
- [`no-unused-state`](https://eslint-react.xyz/docs/rules/no-unused-state) - Warns about unused class component state
|
|
134
|
+
|
|
135
|
+
### RSC
|
|
136
|
+
|
|
137
|
+
<Callout type="info">
|
|
138
|
+
RSC rules target [React Server Components](https://react.dev/reference/rsc/server-components), [React Server Functions](https://react.dev/reference/rsc/server-functions) and RSC [Directives](https://react.dev/reference/rsc/directives).
|
|
139
|
+
</Callout>
|
|
140
|
+
|
|
141
|
+
- [`rsc-no-misused-use-server`](https://eslint-react.xyz/docs/rules/rsc-no-misused-use-server) - Disallows non-async [React Server Functions](https://react.dev/reference/rsc/server-functions) (๐ง Fixable, ๐งช Experimental)
|
|
142
|
+
|
|
143
|
+
### Miscellaneous
|
|
144
|
+
|
|
145
|
+
- [`no-missing-component-display-name`](https://eslint-react.xyz/docs/rules/no-missing-component-display-name) - Enforces that all components have a `displayName` that can be used in DevTools
|
|
146
|
+
- [`no-missing-context-display-name`](https://eslint-react.xyz/docs/rules/no-missing-context-display-name) - Enforces that all contexts have a `displayName` that can be used in DevTools (๐ง Fixable)
|
|
147
|
+
- [`no-misused-capture-owner-stack`](https://eslint-react.xyz/docs/rules/no-misused-capture-owner-stack) - Prevents incorrect usage of `captureOwnerStack` (๐งช Experimental)
|
|
148
|
+
- [`no-unnecessary-use-prefix`](https://eslint-react.xyz/docs/rules/no-unnecessary-use-prefix) - Enforces that a function with the `use` prefix uses at least one Hook inside it
|
|
149
|
+
- [`no-useless-fragment`](https://eslint-react.xyz/docs/rules/no-useless-fragment) - Disallows useless fragment elements (๐ง Fixable, โ๏ธ Configurable)
|
|
150
|
+
- [`prefer-namespace-import`](https://eslint-react.xyz/docs/rules/prefer-namespace-import) - Enforces importing React via a namespace import
|
|
151
|
+
|
|
41
152
|
<https://eslint-react.xyz/docs/rules/overview#core-rules>
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,8 @@ const rules$8 = {
|
|
|
47
47
|
"react-x/no-unnecessary-use-memo": "off",
|
|
48
48
|
"react-x/no-unnecessary-use-ref": "off",
|
|
49
49
|
"react-x/no-unused-props": "off",
|
|
50
|
-
"react-x/prefer-read-only-props": "off"
|
|
50
|
+
"react-x/prefer-read-only-props": "off",
|
|
51
|
+
"react-x/rsc-no-misused-use-server": "off"
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
//#endregion
|
|
@@ -66,7 +67,7 @@ const rules$7 = {
|
|
|
66
67
|
//#endregion
|
|
67
68
|
//#region package.json
|
|
68
69
|
var name$6 = "eslint-plugin-react-x";
|
|
69
|
-
var version = "2.
|
|
70
|
+
var version = "2.9.0-beta.0";
|
|
70
71
|
|
|
71
72
|
//#endregion
|
|
72
73
|
//#region src/utils/create-rule.ts
|
|
@@ -1845,99 +1846,9 @@ function create$28(context) {
|
|
|
1845
1846
|
});
|
|
1846
1847
|
}
|
|
1847
1848
|
|
|
1848
|
-
//#endregion
|
|
1849
|
-
//#region src/rules/no-non-async-server-functions.ts
|
|
1850
|
-
const RULE_NAME$27 = "no-non-async-server-functions";
|
|
1851
|
-
var no_non_async_server_functions_default = createRule({
|
|
1852
|
-
meta: {
|
|
1853
|
-
type: "problem",
|
|
1854
|
-
docs: { description: "Disallows non-async [React Server Functions](https://react.dev/reference/rsc/server-functions)." },
|
|
1855
|
-
fixable: "code",
|
|
1856
|
-
messages: { default: "Server functions must be async." },
|
|
1857
|
-
schema: []
|
|
1858
|
-
},
|
|
1859
|
-
name: RULE_NAME$27,
|
|
1860
|
-
create: create$27,
|
|
1861
|
-
defaultOptions: []
|
|
1862
|
-
});
|
|
1863
|
-
function create$27(context) {
|
|
1864
|
-
if (!context.sourceCode.text.includes("use server")) return {};
|
|
1865
|
-
const hasFileLevelUseServerDirective = ast.getFileDirectives(context.sourceCode.ast).some((d) => d.value === "use server");
|
|
1866
|
-
/**
|
|
1867
|
-
* Check if `node` is an async function, and report if not
|
|
1868
|
-
* @param node The function node to check
|
|
1869
|
-
* @returns Whether a report was made
|
|
1870
|
-
*/
|
|
1871
|
-
function getAsyncFix(node) {
|
|
1872
|
-
if (node.type === AST_NODE_TYPES.FunctionDeclaration || node.type === AST_NODE_TYPES.FunctionExpression) {
|
|
1873
|
-
const fnToken = context.sourceCode.getFirstToken(node);
|
|
1874
|
-
if (fnToken != null) return (fixer) => fixer.insertTextBefore(fnToken, "async ");
|
|
1875
|
-
return null;
|
|
1876
|
-
}
|
|
1877
|
-
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return (fixer) => fixer.insertTextBefore(node, "async ");
|
|
1878
|
-
return null;
|
|
1879
|
-
}
|
|
1880
|
-
function reportNonAsyncFunction(node) {
|
|
1881
|
-
if (!ast.isFunction(node)) return false;
|
|
1882
|
-
if (!node.async) {
|
|
1883
|
-
context.report({
|
|
1884
|
-
messageId: "default",
|
|
1885
|
-
node,
|
|
1886
|
-
fix: getAsyncFix(node)
|
|
1887
|
-
});
|
|
1888
|
-
return true;
|
|
1889
|
-
}
|
|
1890
|
-
return false;
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Check non-exported local functions for 'use server' directives, and report if they are not async
|
|
1894
|
-
* @param node The function node to check
|
|
1895
|
-
*/
|
|
1896
|
-
function checkLocalServerFunction(node) {
|
|
1897
|
-
if (ast.getFunctionDirectives(node).some((d) => d.value === "use server")) reportNonAsyncFunction(node);
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* Find function declarations from exports and check them
|
|
1901
|
-
* @param id The identifier of the exported function
|
|
1902
|
-
* @param node The export declaration node
|
|
1903
|
-
*/
|
|
1904
|
-
function findAndCheckExportedFunctionDeclarations(id, node) {
|
|
1905
|
-
const variableNode = getVariableDefinitionNode(findVariable(id.name, context.sourceCode.getScope(node)), 0);
|
|
1906
|
-
if (variableNode == null) return;
|
|
1907
|
-
reportNonAsyncFunction(variableNode);
|
|
1908
|
-
}
|
|
1909
|
-
return {
|
|
1910
|
-
ArrowFunctionExpression(node) {
|
|
1911
|
-
checkLocalServerFunction(node);
|
|
1912
|
-
},
|
|
1913
|
-
ExportDefaultDeclaration(node) {
|
|
1914
|
-
if (!hasFileLevelUseServerDirective) return;
|
|
1915
|
-
const decl = node.declaration;
|
|
1916
|
-
if (reportNonAsyncFunction(decl)) return;
|
|
1917
|
-
if (ast.isIdentifier(decl)) findAndCheckExportedFunctionDeclarations(decl, node);
|
|
1918
|
-
},
|
|
1919
|
-
ExportNamedDeclaration(node) {
|
|
1920
|
-
if (!hasFileLevelUseServerDirective) return;
|
|
1921
|
-
if (node.declaration != null) {
|
|
1922
|
-
const decl = node.declaration;
|
|
1923
|
-
if (reportNonAsyncFunction(decl)) return;
|
|
1924
|
-
if (decl.type === AST_NODE_TYPES.VariableDeclaration) for (const declarator of decl.declarations) reportNonAsyncFunction(declarator.init);
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
if (node.source == null && node.specifiers.length > 0) for (const spec of node.specifiers) findAndCheckExportedFunctionDeclarations(spec.local, node);
|
|
1928
|
-
},
|
|
1929
|
-
FunctionDeclaration(node) {
|
|
1930
|
-
checkLocalServerFunction(node);
|
|
1931
|
-
},
|
|
1932
|
-
FunctionExpression(node) {
|
|
1933
|
-
checkLocalServerFunction(node);
|
|
1934
|
-
}
|
|
1935
|
-
};
|
|
1936
|
-
}
|
|
1937
|
-
|
|
1938
1849
|
//#endregion
|
|
1939
1850
|
//#region src/rules/no-prop-types.ts
|
|
1940
|
-
const RULE_NAME$
|
|
1851
|
+
const RULE_NAME$27 = "no-prop-types";
|
|
1941
1852
|
var no_prop_types_default = createRule({
|
|
1942
1853
|
meta: {
|
|
1943
1854
|
type: "problem",
|
|
@@ -1945,11 +1856,11 @@ var no_prop_types_default = createRule({
|
|
|
1945
1856
|
messages: { default: "[Deprecated] Use TypeScript or another type-checking solution instead." },
|
|
1946
1857
|
schema: []
|
|
1947
1858
|
},
|
|
1948
|
-
name: RULE_NAME$
|
|
1949
|
-
create: create$
|
|
1859
|
+
name: RULE_NAME$27,
|
|
1860
|
+
create: create$27,
|
|
1950
1861
|
defaultOptions: []
|
|
1951
1862
|
});
|
|
1952
|
-
function create$
|
|
1863
|
+
function create$27(context) {
|
|
1953
1864
|
if (!context.sourceCode.text.includes("propTypes")) return {};
|
|
1954
1865
|
return {
|
|
1955
1866
|
AssignmentExpression(node) {
|
|
@@ -1977,7 +1888,7 @@ function create$26(context) {
|
|
|
1977
1888
|
|
|
1978
1889
|
//#endregion
|
|
1979
1890
|
//#region src/rules/no-redundant-should-component-update.ts
|
|
1980
|
-
const RULE_NAME$
|
|
1891
|
+
const RULE_NAME$26 = "no-redundant-should-component-update";
|
|
1981
1892
|
function isShouldComponentUpdate(node) {
|
|
1982
1893
|
return ast.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
|
|
1983
1894
|
}
|
|
@@ -1988,11 +1899,11 @@ var no_redundant_should_component_update_default = createRule({
|
|
|
1988
1899
|
messages: { default: "'{{componentName}}' does not need 'shouldComponentUpdate' when extending 'React.PureComponent'." },
|
|
1989
1900
|
schema: []
|
|
1990
1901
|
},
|
|
1991
|
-
name: RULE_NAME$
|
|
1992
|
-
create: create$
|
|
1902
|
+
name: RULE_NAME$26,
|
|
1903
|
+
create: create$26,
|
|
1993
1904
|
defaultOptions: []
|
|
1994
1905
|
});
|
|
1995
|
-
function create$
|
|
1906
|
+
function create$26(context) {
|
|
1996
1907
|
if (!context.sourceCode.text.includes("shouldComponentUpdate")) return {};
|
|
1997
1908
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
1998
1909
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2010,7 +1921,7 @@ function create$25(context) {
|
|
|
2010
1921
|
|
|
2011
1922
|
//#endregion
|
|
2012
1923
|
//#region src/rules/no-set-state-in-component-did-mount.ts
|
|
2013
|
-
const RULE_NAME$
|
|
1924
|
+
const RULE_NAME$25 = "no-set-state-in-component-did-mount";
|
|
2014
1925
|
var no_set_state_in_component_did_mount_default = createRule({
|
|
2015
1926
|
meta: {
|
|
2016
1927
|
type: "problem",
|
|
@@ -2018,11 +1929,11 @@ var no_set_state_in_component_did_mount_default = createRule({
|
|
|
2018
1929
|
messages: { default: "Do not call `this.setState` in `componentDidMount` outside functions such as callbacks." },
|
|
2019
1930
|
schema: []
|
|
2020
1931
|
},
|
|
2021
|
-
name: RULE_NAME$
|
|
2022
|
-
create: create$
|
|
1932
|
+
name: RULE_NAME$25,
|
|
1933
|
+
create: create$25,
|
|
2023
1934
|
defaultOptions: []
|
|
2024
1935
|
});
|
|
2025
|
-
function create$
|
|
1936
|
+
function create$25(context) {
|
|
2026
1937
|
if (!context.sourceCode.text.includes("componentDidMount")) return {};
|
|
2027
1938
|
return { CallExpression(node) {
|
|
2028
1939
|
if (!core.isThisSetState(node)) return;
|
|
@@ -2040,7 +1951,7 @@ function create$24(context) {
|
|
|
2040
1951
|
|
|
2041
1952
|
//#endregion
|
|
2042
1953
|
//#region src/rules/no-set-state-in-component-did-update.ts
|
|
2043
|
-
const RULE_NAME$
|
|
1954
|
+
const RULE_NAME$24 = "no-set-state-in-component-did-update";
|
|
2044
1955
|
var no_set_state_in_component_did_update_default = createRule({
|
|
2045
1956
|
meta: {
|
|
2046
1957
|
type: "problem",
|
|
@@ -2048,11 +1959,11 @@ var no_set_state_in_component_did_update_default = createRule({
|
|
|
2048
1959
|
messages: { default: "Do not call `this.setState` in `componentDidUpdate` outside functions such as callbacks." },
|
|
2049
1960
|
schema: []
|
|
2050
1961
|
},
|
|
2051
|
-
name: RULE_NAME$
|
|
2052
|
-
create: create$
|
|
1962
|
+
name: RULE_NAME$24,
|
|
1963
|
+
create: create$24,
|
|
2053
1964
|
defaultOptions: []
|
|
2054
1965
|
});
|
|
2055
|
-
function create$
|
|
1966
|
+
function create$24(context) {
|
|
2056
1967
|
if (!context.sourceCode.text.includes("componentDidUpdate")) return {};
|
|
2057
1968
|
return { CallExpression(node) {
|
|
2058
1969
|
if (!core.isThisSetState(node)) return;
|
|
@@ -2070,7 +1981,7 @@ function create$23(context) {
|
|
|
2070
1981
|
|
|
2071
1982
|
//#endregion
|
|
2072
1983
|
//#region src/rules/no-set-state-in-component-will-update.ts
|
|
2073
|
-
const RULE_NAME$
|
|
1984
|
+
const RULE_NAME$23 = "no-set-state-in-component-will-update";
|
|
2074
1985
|
var no_set_state_in_component_will_update_default = createRule({
|
|
2075
1986
|
meta: {
|
|
2076
1987
|
type: "problem",
|
|
@@ -2078,11 +1989,11 @@ var no_set_state_in_component_will_update_default = createRule({
|
|
|
2078
1989
|
messages: { default: "Do not call `this.setState` in `componentWillUpdate` outside functions such as callbacks." },
|
|
2079
1990
|
schema: []
|
|
2080
1991
|
},
|
|
2081
|
-
name: RULE_NAME$
|
|
2082
|
-
create: create$
|
|
1992
|
+
name: RULE_NAME$23,
|
|
1993
|
+
create: create$23,
|
|
2083
1994
|
defaultOptions: []
|
|
2084
1995
|
});
|
|
2085
|
-
function create$
|
|
1996
|
+
function create$23(context) {
|
|
2086
1997
|
if (!context.sourceCode.text.includes("componentWillUpdate")) return {};
|
|
2087
1998
|
return { CallExpression(node) {
|
|
2088
1999
|
if (!core.isThisSetState(node)) return;
|
|
@@ -2100,7 +2011,7 @@ function create$22(context) {
|
|
|
2100
2011
|
|
|
2101
2012
|
//#endregion
|
|
2102
2013
|
//#region src/rules/no-string-refs.ts
|
|
2103
|
-
const RULE_NAME$
|
|
2014
|
+
const RULE_NAME$22 = "no-string-refs";
|
|
2104
2015
|
var no_string_refs_default = createRule({
|
|
2105
2016
|
meta: {
|
|
2106
2017
|
type: "problem",
|
|
@@ -2109,11 +2020,11 @@ var no_string_refs_default = createRule({
|
|
|
2109
2020
|
messages: { default: "[Deprecated] Use callback refs instead." },
|
|
2110
2021
|
schema: []
|
|
2111
2022
|
},
|
|
2112
|
-
name: RULE_NAME$
|
|
2113
|
-
create: create$
|
|
2023
|
+
name: RULE_NAME$22,
|
|
2024
|
+
create: create$22,
|
|
2114
2025
|
defaultOptions: []
|
|
2115
2026
|
});
|
|
2116
|
-
function create$
|
|
2027
|
+
function create$22(context) {
|
|
2117
2028
|
const state = { isWithinClassComponent: false };
|
|
2118
2029
|
function onClassBodyEnter(node) {
|
|
2119
2030
|
if (core.isClassComponent(node.parent)) state.isWithinClassComponent = true;
|
|
@@ -2158,7 +2069,7 @@ function getJsxAttributeValueText(context, node) {
|
|
|
2158
2069
|
|
|
2159
2070
|
//#endregion
|
|
2160
2071
|
//#region src/rules/no-unnecessary-key.ts
|
|
2161
|
-
const RULE_NAME$
|
|
2072
|
+
const RULE_NAME$21 = "no-unnecessary-key";
|
|
2162
2073
|
var no_unnecessary_key_default = createRule({
|
|
2163
2074
|
meta: {
|
|
2164
2075
|
type: "problem",
|
|
@@ -2166,11 +2077,11 @@ var no_unnecessary_key_default = createRule({
|
|
|
2166
2077
|
messages: { default: "Unnecessary `key` prop on this element. {{reason}}" },
|
|
2167
2078
|
schema: []
|
|
2168
2079
|
},
|
|
2169
|
-
name: RULE_NAME$
|
|
2170
|
-
create: create$
|
|
2080
|
+
name: RULE_NAME$21,
|
|
2081
|
+
create: create$21,
|
|
2171
2082
|
defaultOptions: []
|
|
2172
2083
|
});
|
|
2173
|
-
function create$
|
|
2084
|
+
function create$21(context) {
|
|
2174
2085
|
if (!context.sourceCode.text.includes("key=")) return {};
|
|
2175
2086
|
const jsxConfig = {
|
|
2176
2087
|
...core.getJsxConfigFromContext(context),
|
|
@@ -2219,7 +2130,7 @@ function isArrayMethodCallback(node) {
|
|
|
2219
2130
|
|
|
2220
2131
|
//#endregion
|
|
2221
2132
|
//#region src/rules/no-unnecessary-use-callback.ts
|
|
2222
|
-
const RULE_NAME$
|
|
2133
|
+
const RULE_NAME$20 = "no-unnecessary-use-callback";
|
|
2223
2134
|
var no_unnecessary_use_callback_default = createRule({
|
|
2224
2135
|
meta: {
|
|
2225
2136
|
type: "problem",
|
|
@@ -2230,11 +2141,11 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
2230
2141
|
},
|
|
2231
2142
|
schema: []
|
|
2232
2143
|
},
|
|
2233
|
-
name: RULE_NAME$
|
|
2234
|
-
create: create$
|
|
2144
|
+
name: RULE_NAME$20,
|
|
2145
|
+
create: create$20,
|
|
2235
2146
|
defaultOptions: []
|
|
2236
2147
|
});
|
|
2237
|
-
function create$
|
|
2148
|
+
function create$20(context) {
|
|
2238
2149
|
if (!context.sourceCode.text.includes("useCallback")) return {};
|
|
2239
2150
|
return { VariableDeclarator(node) {
|
|
2240
2151
|
const { id, init } = node;
|
|
@@ -2296,7 +2207,7 @@ function checkForUsageInsideUseEffect$1(sourceCode, node) {
|
|
|
2296
2207
|
|
|
2297
2208
|
//#endregion
|
|
2298
2209
|
//#region src/rules/no-unnecessary-use-memo.ts
|
|
2299
|
-
const RULE_NAME$
|
|
2210
|
+
const RULE_NAME$19 = "no-unnecessary-use-memo";
|
|
2300
2211
|
var no_unnecessary_use_memo_default = createRule({
|
|
2301
2212
|
meta: {
|
|
2302
2213
|
type: "problem",
|
|
@@ -2307,11 +2218,11 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
2307
2218
|
},
|
|
2308
2219
|
schema: []
|
|
2309
2220
|
},
|
|
2310
|
-
name: RULE_NAME$
|
|
2311
|
-
create: create$
|
|
2221
|
+
name: RULE_NAME$19,
|
|
2222
|
+
create: create$19,
|
|
2312
2223
|
defaultOptions: []
|
|
2313
2224
|
});
|
|
2314
|
-
function create$
|
|
2225
|
+
function create$19(context) {
|
|
2315
2226
|
if (!context.sourceCode.text.includes("useMemo")) return {};
|
|
2316
2227
|
return { VariableDeclarator(node) {
|
|
2317
2228
|
const { id, init } = node;
|
|
@@ -2377,7 +2288,7 @@ function checkForUsageInsideUseEffect(sourceCode, node) {
|
|
|
2377
2288
|
|
|
2378
2289
|
//#endregion
|
|
2379
2290
|
//#region src/rules/no-unnecessary-use-prefix.ts
|
|
2380
|
-
const RULE_NAME$
|
|
2291
|
+
const RULE_NAME$18 = "no-unnecessary-use-prefix";
|
|
2381
2292
|
const WELL_KNOWN_HOOKS = ["useMDXComponents"];
|
|
2382
2293
|
function containsUseComments(context, node) {
|
|
2383
2294
|
return context.sourceCode.getCommentsInside(node).some(({ value }) => /use\([\s\S]*?\)/u.test(value) || /use[A-Z0-9]\w*\([\s\S]*?\)/u.test(value));
|
|
@@ -2389,11 +2300,11 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
2389
2300
|
messages: { default: "If your function doesn't call any Hooks, avoid the 'use' prefix. Instead, write it as a regular function without the 'use' prefix." },
|
|
2390
2301
|
schema: []
|
|
2391
2302
|
},
|
|
2392
|
-
name: RULE_NAME$
|
|
2393
|
-
create: create$
|
|
2303
|
+
name: RULE_NAME$18,
|
|
2304
|
+
create: create$18,
|
|
2394
2305
|
defaultOptions: []
|
|
2395
2306
|
});
|
|
2396
|
-
function create$
|
|
2307
|
+
function create$18(context) {
|
|
2397
2308
|
const { ctx, visitor } = core.useHookCollector(context);
|
|
2398
2309
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
2399
2310
|
for (const { id, name, node, hookCalls } of ctx.getAllHooks(program)) {
|
|
@@ -2413,7 +2324,7 @@ function create$17(context) {
|
|
|
2413
2324
|
|
|
2414
2325
|
//#endregion
|
|
2415
2326
|
//#region src/rules/no-unnecessary-use-ref.ts
|
|
2416
|
-
const RULE_NAME$
|
|
2327
|
+
const RULE_NAME$17 = "no-unnecessary-use-ref";
|
|
2417
2328
|
var no_unnecessary_use_ref_default = createRule({
|
|
2418
2329
|
meta: {
|
|
2419
2330
|
type: "problem",
|
|
@@ -2421,11 +2332,11 @@ var no_unnecessary_use_ref_default = createRule({
|
|
|
2421
2332
|
messages: { default: "Unnecessary use of 'useRef'. Instead, co-locate the value inside the effect that uses it." },
|
|
2422
2333
|
schema: []
|
|
2423
2334
|
},
|
|
2424
|
-
name: RULE_NAME$
|
|
2425
|
-
create: create$
|
|
2335
|
+
name: RULE_NAME$17,
|
|
2336
|
+
create: create$17,
|
|
2426
2337
|
defaultOptions: []
|
|
2427
2338
|
});
|
|
2428
|
-
function create$
|
|
2339
|
+
function create$17(context) {
|
|
2429
2340
|
if (!context.sourceCode.text.includes("useRef")) return {};
|
|
2430
2341
|
return { VariableDeclarator(node) {
|
|
2431
2342
|
const { id, init } = node;
|
|
@@ -2451,7 +2362,7 @@ function create$16(context) {
|
|
|
2451
2362
|
|
|
2452
2363
|
//#endregion
|
|
2453
2364
|
//#region src/rules/no-unsafe-component-will-mount.ts
|
|
2454
|
-
const RULE_NAME$
|
|
2365
|
+
const RULE_NAME$16 = "no-unsafe-component-will-mount";
|
|
2455
2366
|
var no_unsafe_component_will_mount_default = createRule({
|
|
2456
2367
|
meta: {
|
|
2457
2368
|
type: "problem",
|
|
@@ -2459,11 +2370,11 @@ var no_unsafe_component_will_mount_default = createRule({
|
|
|
2459
2370
|
messages: { default: "Do not use 'UNSAFE_componentWillMount'." },
|
|
2460
2371
|
schema: []
|
|
2461
2372
|
},
|
|
2462
|
-
name: RULE_NAME$
|
|
2463
|
-
create: create$
|
|
2373
|
+
name: RULE_NAME$16,
|
|
2374
|
+
create: create$16,
|
|
2464
2375
|
defaultOptions: []
|
|
2465
2376
|
});
|
|
2466
|
-
function create$
|
|
2377
|
+
function create$16(context) {
|
|
2467
2378
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillMount")) return {};
|
|
2468
2379
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2469
2380
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2479,7 +2390,7 @@ function create$15(context) {
|
|
|
2479
2390
|
|
|
2480
2391
|
//#endregion
|
|
2481
2392
|
//#region src/rules/no-unsafe-component-will-receive-props.ts
|
|
2482
|
-
const RULE_NAME$
|
|
2393
|
+
const RULE_NAME$15 = "no-unsafe-component-will-receive-props";
|
|
2483
2394
|
var no_unsafe_component_will_receive_props_default = createRule({
|
|
2484
2395
|
meta: {
|
|
2485
2396
|
type: "problem",
|
|
@@ -2487,11 +2398,11 @@ var no_unsafe_component_will_receive_props_default = createRule({
|
|
|
2487
2398
|
messages: { default: "Do not use 'UNSAFE_componentWillReceiveProps'." },
|
|
2488
2399
|
schema: []
|
|
2489
2400
|
},
|
|
2490
|
-
name: RULE_NAME$
|
|
2491
|
-
create: create$
|
|
2401
|
+
name: RULE_NAME$15,
|
|
2402
|
+
create: create$15,
|
|
2492
2403
|
defaultOptions: []
|
|
2493
2404
|
});
|
|
2494
|
-
function create$
|
|
2405
|
+
function create$15(context) {
|
|
2495
2406
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillReceiveProps")) return {};
|
|
2496
2407
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2497
2408
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2507,7 +2418,7 @@ function create$14(context) {
|
|
|
2507
2418
|
|
|
2508
2419
|
//#endregion
|
|
2509
2420
|
//#region src/rules/no-unsafe-component-will-update.ts
|
|
2510
|
-
const RULE_NAME$
|
|
2421
|
+
const RULE_NAME$14 = "no-unsafe-component-will-update";
|
|
2511
2422
|
var no_unsafe_component_will_update_default = createRule({
|
|
2512
2423
|
meta: {
|
|
2513
2424
|
type: "problem",
|
|
@@ -2515,11 +2426,11 @@ var no_unsafe_component_will_update_default = createRule({
|
|
|
2515
2426
|
messages: { default: "Do not use 'UNSAFE_componentWillUpdate'." },
|
|
2516
2427
|
schema: []
|
|
2517
2428
|
},
|
|
2518
|
-
name: RULE_NAME$
|
|
2519
|
-
create: create$
|
|
2429
|
+
name: RULE_NAME$14,
|
|
2430
|
+
create: create$14,
|
|
2520
2431
|
defaultOptions: []
|
|
2521
2432
|
});
|
|
2522
|
-
function create$
|
|
2433
|
+
function create$14(context) {
|
|
2523
2434
|
if (!context.sourceCode.text.includes("UNSAFE_componentWillUpdate")) return {};
|
|
2524
2435
|
const { ctx, visitor } = core.useComponentCollectorLegacy(context);
|
|
2525
2436
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2535,7 +2446,7 @@ function create$13(context) {
|
|
|
2535
2446
|
|
|
2536
2447
|
//#endregion
|
|
2537
2448
|
//#region src/rules/no-unstable-context-value.ts
|
|
2538
|
-
const RULE_NAME$
|
|
2449
|
+
const RULE_NAME$13 = "no-unstable-context-value";
|
|
2539
2450
|
var no_unstable_context_value_default = createRule({
|
|
2540
2451
|
meta: {
|
|
2541
2452
|
type: "problem",
|
|
@@ -2543,11 +2454,11 @@ var no_unstable_context_value_default = createRule({
|
|
|
2543
2454
|
messages: { unstableContextValue: "A/an '{{type}}' passed as the value prop to the context provider should not be constructed. It will change on every render. {{suggestion}}" },
|
|
2544
2455
|
schema: []
|
|
2545
2456
|
},
|
|
2546
|
-
name: RULE_NAME$
|
|
2547
|
-
create: create$
|
|
2457
|
+
name: RULE_NAME$13,
|
|
2458
|
+
create: create$13,
|
|
2548
2459
|
defaultOptions: []
|
|
2549
2460
|
});
|
|
2550
|
-
function create$
|
|
2461
|
+
function create$13(context) {
|
|
2551
2462
|
if (ast.getFileDirectives(context.sourceCode.ast).some((d) => d.value === "use memo")) return {};
|
|
2552
2463
|
const { version } = getSettingsFromContext(context);
|
|
2553
2464
|
const isReact18OrBelow = compare(version, "19.0.0", "<");
|
|
@@ -2595,7 +2506,7 @@ function isContextName(name, isReact18OrBelow) {
|
|
|
2595
2506
|
|
|
2596
2507
|
//#endregion
|
|
2597
2508
|
//#region src/rules/no-unstable-default-props.ts
|
|
2598
|
-
const RULE_NAME$
|
|
2509
|
+
const RULE_NAME$12 = "no-unstable-default-props";
|
|
2599
2510
|
const defaultOptions$2 = [{ safeDefaultProps: [] }];
|
|
2600
2511
|
const schema$1 = [{
|
|
2601
2512
|
type: "object",
|
|
@@ -2612,8 +2523,8 @@ var no_unstable_default_props_default = createRule({
|
|
|
2612
2523
|
messages: { default: "A/an '{{forbiddenType}}' as default prop. This could lead to potential infinite render loop in React. Use a variable instead of '{{forbiddenType}}'." },
|
|
2613
2524
|
schema: schema$1
|
|
2614
2525
|
},
|
|
2615
|
-
name: RULE_NAME$
|
|
2616
|
-
create: create$
|
|
2526
|
+
name: RULE_NAME$12,
|
|
2527
|
+
create: create$12,
|
|
2617
2528
|
defaultOptions: defaultOptions$2
|
|
2618
2529
|
});
|
|
2619
2530
|
function extractIdentifier(node) {
|
|
@@ -2624,7 +2535,7 @@ function extractIdentifier(node) {
|
|
|
2624
2535
|
}
|
|
2625
2536
|
return null;
|
|
2626
2537
|
}
|
|
2627
|
-
function create$
|
|
2538
|
+
function create$12(context, [options]) {
|
|
2628
2539
|
if (ast.getFileDirectives(context.sourceCode.ast).some((d) => d.value === "use memo")) return {};
|
|
2629
2540
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
2630
2541
|
const declarators = /* @__PURE__ */ new WeakMap();
|
|
@@ -2669,7 +2580,7 @@ function create$11(context, [options]) {
|
|
|
2669
2580
|
|
|
2670
2581
|
//#endregion
|
|
2671
2582
|
//#region src/rules/no-unused-class-component-members.ts
|
|
2672
|
-
const RULE_NAME$
|
|
2583
|
+
const RULE_NAME$11 = "no-unused-class-component-members";
|
|
2673
2584
|
const LIFECYCLE_METHODS = new Set([
|
|
2674
2585
|
"componentDidCatch",
|
|
2675
2586
|
"componentDidMount",
|
|
@@ -2700,11 +2611,11 @@ var no_unused_class_component_members_default = createRule({
|
|
|
2700
2611
|
messages: { default: "Unused method or property '{{methodName}}'' of class '{{className}}'." },
|
|
2701
2612
|
schema: []
|
|
2702
2613
|
},
|
|
2703
|
-
name: RULE_NAME$
|
|
2704
|
-
create: create$
|
|
2614
|
+
name: RULE_NAME$11,
|
|
2615
|
+
create: create$11,
|
|
2705
2616
|
defaultOptions: []
|
|
2706
2617
|
});
|
|
2707
|
-
function create$
|
|
2618
|
+
function create$11(context) {
|
|
2708
2619
|
const classStack = [];
|
|
2709
2620
|
const methodStack = [];
|
|
2710
2621
|
const propertyDefs = /* @__PURE__ */ new WeakMap();
|
|
@@ -2785,7 +2696,7 @@ function create$10(context) {
|
|
|
2785
2696
|
|
|
2786
2697
|
//#endregion
|
|
2787
2698
|
//#region src/rules/no-unused-props.ts
|
|
2788
|
-
const RULE_NAME$
|
|
2699
|
+
const RULE_NAME$10 = "no-unused-props";
|
|
2789
2700
|
var no_unused_props_default = createRule({
|
|
2790
2701
|
meta: {
|
|
2791
2702
|
type: "problem",
|
|
@@ -2793,11 +2704,11 @@ var no_unused_props_default = createRule({
|
|
|
2793
2704
|
messages: { default: "Prop `{{name}}` is declared but never used" },
|
|
2794
2705
|
schema: []
|
|
2795
2706
|
},
|
|
2796
|
-
name: RULE_NAME$
|
|
2797
|
-
create: create$
|
|
2707
|
+
name: RULE_NAME$10,
|
|
2708
|
+
create: create$10,
|
|
2798
2709
|
defaultOptions: []
|
|
2799
2710
|
});
|
|
2800
|
-
function create$
|
|
2711
|
+
function create$10(context) {
|
|
2801
2712
|
const services = ESLintUtils.getParserServices(context, false);
|
|
2802
2713
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
2803
2714
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
@@ -2895,7 +2806,7 @@ function reportUnusedProp(context, services, prop) {
|
|
|
2895
2806
|
|
|
2896
2807
|
//#endregion
|
|
2897
2808
|
//#region src/rules/no-unused-state.ts
|
|
2898
|
-
const RULE_NAME$
|
|
2809
|
+
const RULE_NAME$9 = "no-unused-state";
|
|
2899
2810
|
function isKeyLiteral(node, key) {
|
|
2900
2811
|
return match(key).with({ type: AST_NODE_TYPES.Literal }, constTrue).with({
|
|
2901
2812
|
type: AST_NODE_TYPES.TemplateLiteral,
|
|
@@ -2909,11 +2820,11 @@ var no_unused_state_default = createRule({
|
|
|
2909
2820
|
messages: { default: "Unused class component state in '{{className}}'" },
|
|
2910
2821
|
schema: []
|
|
2911
2822
|
},
|
|
2912
|
-
name: RULE_NAME$
|
|
2913
|
-
create: create$
|
|
2823
|
+
name: RULE_NAME$9,
|
|
2824
|
+
create: create$9,
|
|
2914
2825
|
defaultOptions: []
|
|
2915
2826
|
});
|
|
2916
|
-
function create$
|
|
2827
|
+
function create$9(context) {
|
|
2917
2828
|
const classStack = [];
|
|
2918
2829
|
const methodStack = [];
|
|
2919
2830
|
const constructorStack = [];
|
|
@@ -3022,7 +2933,7 @@ function create$8(context) {
|
|
|
3022
2933
|
|
|
3023
2934
|
//#endregion
|
|
3024
2935
|
//#region src/rules/no-use-context.ts
|
|
3025
|
-
const RULE_NAME$
|
|
2936
|
+
const RULE_NAME$8 = "no-use-context";
|
|
3026
2937
|
var no_use_context_default = createRule({
|
|
3027
2938
|
meta: {
|
|
3028
2939
|
type: "problem",
|
|
@@ -3031,11 +2942,11 @@ var no_use_context_default = createRule({
|
|
|
3031
2942
|
messages: { default: "In React 19, 'use' is preferred over 'useContext' because it is more flexible." },
|
|
3032
2943
|
schema: []
|
|
3033
2944
|
},
|
|
3034
|
-
name: RULE_NAME$
|
|
3035
|
-
create: create$
|
|
2945
|
+
name: RULE_NAME$8,
|
|
2946
|
+
create: create$8,
|
|
3036
2947
|
defaultOptions: []
|
|
3037
2948
|
});
|
|
3038
|
-
function create$
|
|
2949
|
+
function create$8(context) {
|
|
3039
2950
|
if (!context.sourceCode.text.includes("useContext")) return {};
|
|
3040
2951
|
const settings = getSettingsFromContext(context);
|
|
3041
2952
|
if (compare(settings.version, "19.0.0", "<")) return {};
|
|
@@ -3100,7 +3011,7 @@ function getCorrelativeTokens(context, node) {
|
|
|
3100
3011
|
|
|
3101
3012
|
//#endregion
|
|
3102
3013
|
//#region src/rules/no-useless-forward-ref.ts
|
|
3103
|
-
const RULE_NAME$
|
|
3014
|
+
const RULE_NAME$7 = "no-useless-forward-ref";
|
|
3104
3015
|
var no_useless_forward_ref_default = createRule({
|
|
3105
3016
|
meta: {
|
|
3106
3017
|
type: "problem",
|
|
@@ -3108,11 +3019,11 @@ var no_useless_forward_ref_default = createRule({
|
|
|
3108
3019
|
messages: { default: "A 'forwardRef' is used with this component but no 'ref' parameter is set." },
|
|
3109
3020
|
schema: []
|
|
3110
3021
|
},
|
|
3111
|
-
name: RULE_NAME$
|
|
3112
|
-
create: create$
|
|
3022
|
+
name: RULE_NAME$7,
|
|
3023
|
+
create: create$7,
|
|
3113
3024
|
defaultOptions: []
|
|
3114
3025
|
});
|
|
3115
|
-
function create$
|
|
3026
|
+
function create$7(context) {
|
|
3116
3027
|
return { CallExpression(node) {
|
|
3117
3028
|
if (!core.isForwardRefCall(context, node)) return;
|
|
3118
3029
|
const [component] = node.arguments;
|
|
@@ -3127,7 +3038,7 @@ function create$6(context) {
|
|
|
3127
3038
|
|
|
3128
3039
|
//#endregion
|
|
3129
3040
|
//#region src/rules/no-useless-fragment.ts
|
|
3130
|
-
const RULE_NAME$
|
|
3041
|
+
const RULE_NAME$6 = "no-useless-fragment";
|
|
3131
3042
|
const defaultOptions$1 = [{
|
|
3132
3043
|
allowEmptyFragment: false,
|
|
3133
3044
|
allowExpressions: true
|
|
@@ -3155,11 +3066,11 @@ var no_useless_fragment_default = createRule({
|
|
|
3155
3066
|
messages: { default: "A fragment {{reason}} is useless." },
|
|
3156
3067
|
schema
|
|
3157
3068
|
},
|
|
3158
|
-
name: RULE_NAME$
|
|
3159
|
-
create: create$
|
|
3069
|
+
name: RULE_NAME$6,
|
|
3070
|
+
create: create$6,
|
|
3160
3071
|
defaultOptions: defaultOptions$1
|
|
3161
3072
|
});
|
|
3162
|
-
function create$
|
|
3073
|
+
function create$6(context, [option]) {
|
|
3163
3074
|
const { allowEmptyFragment = false, allowExpressions = true } = option;
|
|
3164
3075
|
const jsxConfig = {
|
|
3165
3076
|
...core.getJsxConfigFromContext(context),
|
|
@@ -3267,7 +3178,7 @@ function trimLikeReact(text) {
|
|
|
3267
3178
|
|
|
3268
3179
|
//#endregion
|
|
3269
3180
|
//#region src/rules/prefer-destructuring-assignment.ts
|
|
3270
|
-
const RULE_NAME$
|
|
3181
|
+
const RULE_NAME$5 = "prefer-destructuring-assignment";
|
|
3271
3182
|
var prefer_destructuring_assignment_default = createRule({
|
|
3272
3183
|
meta: {
|
|
3273
3184
|
type: "problem",
|
|
@@ -3275,11 +3186,11 @@ var prefer_destructuring_assignment_default = createRule({
|
|
|
3275
3186
|
messages: { default: "Use destructuring assignment for component props." },
|
|
3276
3187
|
schema: []
|
|
3277
3188
|
},
|
|
3278
|
-
name: RULE_NAME$
|
|
3279
|
-
create: create$
|
|
3189
|
+
name: RULE_NAME$5,
|
|
3190
|
+
create: create$5,
|
|
3280
3191
|
defaultOptions: []
|
|
3281
3192
|
});
|
|
3282
|
-
function create$
|
|
3193
|
+
function create$5(context) {
|
|
3283
3194
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
3284
3195
|
return defineRuleListener(visitor, { "Program:exit"(program) {
|
|
3285
3196
|
for (const component of ctx.getAllComponents(program)) {
|
|
@@ -3303,7 +3214,7 @@ function create$4(context) {
|
|
|
3303
3214
|
|
|
3304
3215
|
//#endregion
|
|
3305
3216
|
//#region src/rules/prefer-namespace-import.ts
|
|
3306
|
-
const RULE_NAME$
|
|
3217
|
+
const RULE_NAME$4 = "prefer-namespace-import";
|
|
3307
3218
|
var prefer_namespace_import_default = createRule({
|
|
3308
3219
|
meta: {
|
|
3309
3220
|
type: "problem",
|
|
@@ -3312,11 +3223,11 @@ var prefer_namespace_import_default = createRule({
|
|
|
3312
3223
|
messages: { default: "Prefer importing React as 'import * as React from \"{{importSource}}\"';" },
|
|
3313
3224
|
schema: []
|
|
3314
3225
|
},
|
|
3315
|
-
name: RULE_NAME$
|
|
3316
|
-
create: create$
|
|
3226
|
+
name: RULE_NAME$4,
|
|
3227
|
+
create: create$4,
|
|
3317
3228
|
defaultOptions: []
|
|
3318
3229
|
});
|
|
3319
|
-
function create$
|
|
3230
|
+
function create$4(context) {
|
|
3320
3231
|
const { importSource } = getSettingsFromContext(context);
|
|
3321
3232
|
return { [`ImportDeclaration[source.value="${importSource}"] ImportDefaultSpecifier`](node) {
|
|
3322
3233
|
const hasOtherSpecifiers = node.parent.specifiers.length > 1;
|
|
@@ -3340,7 +3251,7 @@ function create$3(context) {
|
|
|
3340
3251
|
|
|
3341
3252
|
//#endregion
|
|
3342
3253
|
//#region src/rules/prefer-read-only-props.ts
|
|
3343
|
-
const RULE_NAME$
|
|
3254
|
+
const RULE_NAME$3 = "prefer-read-only-props";
|
|
3344
3255
|
var prefer_read_only_props_default = createRule({
|
|
3345
3256
|
meta: {
|
|
3346
3257
|
type: "problem",
|
|
@@ -3348,11 +3259,11 @@ var prefer_read_only_props_default = createRule({
|
|
|
3348
3259
|
messages: { default: "A function component's props should be read-only." },
|
|
3349
3260
|
schema: []
|
|
3350
3261
|
},
|
|
3351
|
-
name: RULE_NAME$
|
|
3352
|
-
create: create$
|
|
3262
|
+
name: RULE_NAME$3,
|
|
3263
|
+
create: create$3,
|
|
3353
3264
|
defaultOptions: []
|
|
3354
3265
|
});
|
|
3355
|
-
function create$
|
|
3266
|
+
function create$3(context) {
|
|
3356
3267
|
const services = ESLintUtils.getParserServices(context, false);
|
|
3357
3268
|
const checker = services.program.getTypeChecker();
|
|
3358
3269
|
const { ctx, visitor } = core.useComponentCollector(context);
|
|
@@ -3393,7 +3304,7 @@ function isClassOrInterfaceReadonlyLoose(checker, type) {
|
|
|
3393
3304
|
|
|
3394
3305
|
//#endregion
|
|
3395
3306
|
//#region src/rules/prefer-use-state-lazy-initialization.ts
|
|
3396
|
-
const RULE_NAME$
|
|
3307
|
+
const RULE_NAME$2 = "prefer-use-state-lazy-initialization";
|
|
3397
3308
|
const ALLOW_LIST = [
|
|
3398
3309
|
"Boolean",
|
|
3399
3310
|
"String",
|
|
@@ -3406,11 +3317,11 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
3406
3317
|
messages: { default: "To prevent re-computation, consider using lazy initial state for useState calls that involve function calls. Ex: 'useState(() => getValue())'." },
|
|
3407
3318
|
schema: []
|
|
3408
3319
|
},
|
|
3409
|
-
name: RULE_NAME$
|
|
3410
|
-
create: create$
|
|
3320
|
+
name: RULE_NAME$2,
|
|
3321
|
+
create: create$2,
|
|
3411
3322
|
defaultOptions: []
|
|
3412
3323
|
});
|
|
3413
|
-
function create$
|
|
3324
|
+
function create$2(context) {
|
|
3414
3325
|
return { CallExpression(node) {
|
|
3415
3326
|
if (!core.isUseStateCall(node)) return;
|
|
3416
3327
|
const [useStateInput] = node.arguments;
|
|
@@ -3437,6 +3348,96 @@ function create$1(context) {
|
|
|
3437
3348
|
} };
|
|
3438
3349
|
}
|
|
3439
3350
|
|
|
3351
|
+
//#endregion
|
|
3352
|
+
//#region src/rules/rsc-no-misused-use-server.ts
|
|
3353
|
+
const RULE_NAME$1 = "rsc-no-misused-use-server";
|
|
3354
|
+
var rsc_no_misused_use_server_default = createRule({
|
|
3355
|
+
meta: {
|
|
3356
|
+
type: "problem",
|
|
3357
|
+
docs: { description: "Checks against misused `'use server'` directive." },
|
|
3358
|
+
fixable: "code",
|
|
3359
|
+
messages: { default: "Server functions must be async." },
|
|
3360
|
+
schema: []
|
|
3361
|
+
},
|
|
3362
|
+
name: RULE_NAME$1,
|
|
3363
|
+
create: create$1,
|
|
3364
|
+
defaultOptions: []
|
|
3365
|
+
});
|
|
3366
|
+
function create$1(context) {
|
|
3367
|
+
if (!context.sourceCode.text.includes("use server")) return {};
|
|
3368
|
+
const hasFileLevelUseServerDirective = ast.getFileDirectives(context.sourceCode.ast).some((d) => d.value === "use server");
|
|
3369
|
+
/**
|
|
3370
|
+
* Check if `node` is an async function, and report if not
|
|
3371
|
+
* @param node The function node to check
|
|
3372
|
+
* @returns Whether a report was made
|
|
3373
|
+
*/
|
|
3374
|
+
function getAsyncFix(node) {
|
|
3375
|
+
if (node.type === AST_NODE_TYPES.FunctionDeclaration || node.type === AST_NODE_TYPES.FunctionExpression) {
|
|
3376
|
+
const fnToken = context.sourceCode.getFirstToken(node);
|
|
3377
|
+
if (fnToken != null) return (fixer) => fixer.insertTextBefore(fnToken, "async ");
|
|
3378
|
+
return null;
|
|
3379
|
+
}
|
|
3380
|
+
if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) return (fixer) => fixer.insertTextBefore(node, "async ");
|
|
3381
|
+
return null;
|
|
3382
|
+
}
|
|
3383
|
+
function reportNonAsyncFunction(node) {
|
|
3384
|
+
if (!ast.isFunction(node)) return false;
|
|
3385
|
+
if (!node.async) {
|
|
3386
|
+
context.report({
|
|
3387
|
+
messageId: "default",
|
|
3388
|
+
node,
|
|
3389
|
+
fix: getAsyncFix(node)
|
|
3390
|
+
});
|
|
3391
|
+
return true;
|
|
3392
|
+
}
|
|
3393
|
+
return false;
|
|
3394
|
+
}
|
|
3395
|
+
/**
|
|
3396
|
+
* Check non-exported local functions for 'use server' directives, and report if they are not async
|
|
3397
|
+
* @param node The function node to check
|
|
3398
|
+
*/
|
|
3399
|
+
function checkLocalServerFunction(node) {
|
|
3400
|
+
if (ast.getFunctionDirectives(node).some((d) => d.value === "use server")) reportNonAsyncFunction(node);
|
|
3401
|
+
}
|
|
3402
|
+
/**
|
|
3403
|
+
* Find function declarations from exports and check them
|
|
3404
|
+
* @param id The identifier of the exported function
|
|
3405
|
+
* @param node The export declaration node
|
|
3406
|
+
*/
|
|
3407
|
+
function findAndCheckExportedFunctionDeclarations(id, node) {
|
|
3408
|
+
const variableNode = getVariableDefinitionNode(findVariable(id.name, context.sourceCode.getScope(node)), 0);
|
|
3409
|
+
if (variableNode == null) return;
|
|
3410
|
+
reportNonAsyncFunction(variableNode);
|
|
3411
|
+
}
|
|
3412
|
+
return {
|
|
3413
|
+
ArrowFunctionExpression(node) {
|
|
3414
|
+
checkLocalServerFunction(node);
|
|
3415
|
+
},
|
|
3416
|
+
ExportDefaultDeclaration(node) {
|
|
3417
|
+
if (!hasFileLevelUseServerDirective) return;
|
|
3418
|
+
const decl = node.declaration;
|
|
3419
|
+
if (reportNonAsyncFunction(decl)) return;
|
|
3420
|
+
if (ast.isIdentifier(decl)) findAndCheckExportedFunctionDeclarations(decl, node);
|
|
3421
|
+
},
|
|
3422
|
+
ExportNamedDeclaration(node) {
|
|
3423
|
+
if (!hasFileLevelUseServerDirective) return;
|
|
3424
|
+
if (node.declaration != null) {
|
|
3425
|
+
const decl = node.declaration;
|
|
3426
|
+
if (reportNonAsyncFunction(decl)) return;
|
|
3427
|
+
if (decl.type === AST_NODE_TYPES.VariableDeclaration) for (const declarator of decl.declarations) reportNonAsyncFunction(declarator.init);
|
|
3428
|
+
return;
|
|
3429
|
+
}
|
|
3430
|
+
if (node.source == null && node.specifiers.length > 0) for (const spec of node.specifiers) findAndCheckExportedFunctionDeclarations(spec.local, node);
|
|
3431
|
+
},
|
|
3432
|
+
FunctionDeclaration(node) {
|
|
3433
|
+
checkLocalServerFunction(node);
|
|
3434
|
+
},
|
|
3435
|
+
FunctionExpression(node) {
|
|
3436
|
+
checkLocalServerFunction(node);
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
}
|
|
3440
|
+
|
|
3440
3441
|
//#endregion
|
|
3441
3442
|
//#region src/rules-removed/no-forbidden-props.ts
|
|
3442
3443
|
const RULE_NAME = "no-forbidden-props";
|
|
@@ -3567,7 +3568,6 @@ const plugin = {
|
|
|
3567
3568
|
"no-nested-component-definitions": no_nested_component_definitions_default,
|
|
3568
3569
|
"no-nested-lazy-component-declarations": no_nested_lazy_component_declarations_default,
|
|
3569
3570
|
"no-prop-types": no_prop_types_default,
|
|
3570
|
-
"no-non-async-server-functions": no_non_async_server_functions_default,
|
|
3571
3571
|
"no-redundant-should-component-update": no_redundant_should_component_update_default,
|
|
3572
3572
|
"no-set-state-in-component-did-mount": no_set_state_in_component_did_mount_default,
|
|
3573
3573
|
"no-set-state-in-component-did-update": no_set_state_in_component_did_update_default,
|
|
@@ -3593,6 +3593,7 @@ const plugin = {
|
|
|
3593
3593
|
"prefer-namespace-import": prefer_namespace_import_default,
|
|
3594
3594
|
"prefer-read-only-props": prefer_read_only_props_default,
|
|
3595
3595
|
"prefer-use-state-lazy-initialization": prefer_use_state_lazy_initialization_default,
|
|
3596
|
+
"rsc-no-misused-use-server": rsc_no_misused_use_server_default,
|
|
3596
3597
|
"no-forbidden-props": no_forbidden_props_default
|
|
3597
3598
|
}
|
|
3598
3599
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0-beta.0",
|
|
4
4
|
"description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"is-immutable-type": "^5.0.1",
|
|
46
46
|
"ts-api-utils": "^2.4.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "2.
|
|
49
|
-
"@eslint-react/core": "2.
|
|
50
|
-
"@eslint-react/shared": "2.
|
|
51
|
-
"@eslint-react/var": "2.
|
|
52
|
-
"@eslint-react/eff": "2.
|
|
48
|
+
"@eslint-react/ast": "2.9.0-beta.0",
|
|
49
|
+
"@eslint-react/core": "2.9.0-beta.0",
|
|
50
|
+
"@eslint-react/shared": "2.9.0-beta.0",
|
|
51
|
+
"@eslint-react/var": "2.9.0-beta.0",
|
|
52
|
+
"@eslint-react/eff": "2.9.0-beta.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.10",
|