eslint-plugin-react-hooks 5.2.0 → 6.0.0-canary-e5dd82a7-20250401
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 +45 -29
- package/cjs/eslint-plugin-react-hooks.d.ts +26 -28
- package/cjs/eslint-plugin-react-hooks.development.js +55771 -2434
- package/cjs/eslint-plugin-react-hooks.production.js +55602 -2434
- package/package.json +15 -4
package/README.md
CHANGED
|
@@ -18,25 +18,14 @@ npm install eslint-plugin-react-hooks --save-dev
|
|
|
18
18
|
yarn add eslint-plugin-react-hooks --dev
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
###
|
|
22
|
-
|
|
23
|
-
If you are still using ESLint below 9.0.0, please continue to use `recommended-legacy`. To avoid breaking changes, we still support `recommended` as well, but note that this will be changed to alias the flat recommended config in v6.
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
{
|
|
27
|
-
"extends": [
|
|
28
|
-
// ...
|
|
29
|
-
"plugin:react-hooks/recommended-legacy"
|
|
30
|
-
]
|
|
31
|
-
}
|
|
32
|
-
```
|
|
21
|
+
### Flat Config (eslint.config.js|ts)
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
#### 5.2.0
|
|
35
24
|
|
|
36
|
-
For
|
|
25
|
+
For users of 5.2.0 (the first version with flat config support), add the `recommended-latest` config.
|
|
37
26
|
|
|
38
27
|
```js
|
|
39
|
-
import reactHooks from 'eslint-plugin-react-hooks';
|
|
28
|
+
import * as reactHooks from 'eslint-plugin-react-hooks';
|
|
40
29
|
|
|
41
30
|
export default [
|
|
42
31
|
// ...
|
|
@@ -44,30 +33,42 @@ export default [
|
|
|
44
33
|
];
|
|
45
34
|
```
|
|
46
35
|
|
|
47
|
-
###
|
|
36
|
+
### Legacy Config (.eslintrc)
|
|
48
37
|
|
|
49
|
-
|
|
38
|
+
#### >= 5.2.0
|
|
50
39
|
|
|
51
|
-
|
|
40
|
+
If you are still using ESLint below 9.0.0, you can use `recommended-legacy` for accessing a legacy version of the recommended config.
|
|
52
41
|
|
|
53
42
|
```js
|
|
54
43
|
{
|
|
55
|
-
"
|
|
44
|
+
"extends": [
|
|
56
45
|
// ...
|
|
57
|
-
"react-hooks"
|
|
58
|
-
]
|
|
59
|
-
|
|
46
|
+
"plugin:react-hooks/recommended-legacy"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### < 5.2.0
|
|
52
|
+
|
|
53
|
+
If you're using a version earlier than 5.2.0, the legacy config was simply `recommended`.
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
{
|
|
57
|
+
"extends": [
|
|
60
58
|
// ...
|
|
61
|
-
"react-hooks/
|
|
62
|
-
|
|
63
|
-
}
|
|
59
|
+
"plugin:react-hooks/recommended"
|
|
60
|
+
]
|
|
64
61
|
}
|
|
65
62
|
```
|
|
66
63
|
|
|
67
|
-
|
|
64
|
+
### Custom Configuration
|
|
65
|
+
|
|
66
|
+
If you want more fine-grained configuration, you can instead add a snippet like this to your ESLint configuration file:
|
|
67
|
+
|
|
68
|
+
#### Flat Config (eslint.config.js|ts)
|
|
68
69
|
|
|
69
70
|
```js
|
|
70
|
-
import reactHooks from 'eslint-plugin-react-hooks';
|
|
71
|
+
import * as reactHooks from 'eslint-plugin-react-hooks';
|
|
71
72
|
|
|
72
73
|
export default [
|
|
73
74
|
{
|
|
@@ -82,6 +83,21 @@ export default [
|
|
|
82
83
|
];
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
#### Legacy Config (.eslintrc)
|
|
87
|
+
```js
|
|
88
|
+
{
|
|
89
|
+
"plugins": [
|
|
90
|
+
// ...
|
|
91
|
+
"react-hooks"
|
|
92
|
+
],
|
|
93
|
+
"rules": {
|
|
94
|
+
// ...
|
|
95
|
+
"react-hooks/rules-of-hooks": "error",
|
|
96
|
+
"react-hooks/exhaustive-deps": "warn"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
85
101
|
## Advanced Configuration
|
|
86
102
|
|
|
87
103
|
`exhaustive-deps` can be configured to validate dependencies of custom Hooks with the `additionalHooks` option.
|
|
@@ -89,10 +105,10 @@ This option accepts a regex to match the names of custom Hooks that have depende
|
|
|
89
105
|
|
|
90
106
|
```js
|
|
91
107
|
{
|
|
92
|
-
|
|
108
|
+
rules: {
|
|
93
109
|
// ...
|
|
94
110
|
"react-hooks/exhaustive-deps": ["warn", {
|
|
95
|
-
|
|
111
|
+
additionalHooks: "(useMyCustomHook|useMyOtherCustomHook)"
|
|
96
112
|
}]
|
|
97
113
|
}
|
|
98
114
|
}
|
|
@@ -2,27 +2,6 @@ import * as estree from 'estree';
|
|
|
2
2
|
import { Rule, ESLint } from 'eslint';
|
|
3
3
|
|
|
4
4
|
declare const rules: {
|
|
5
|
-
'rules-of-hooks': {
|
|
6
|
-
meta: {
|
|
7
|
-
type: "problem";
|
|
8
|
-
docs: {
|
|
9
|
-
description: string;
|
|
10
|
-
recommended: true;
|
|
11
|
-
url: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
create(context: Rule.RuleContext): {
|
|
15
|
-
onCodePathSegmentStart: (segment: Rule.CodePathSegment) => number;
|
|
16
|
-
onCodePathSegmentEnd: () => Rule.CodePathSegment | undefined;
|
|
17
|
-
onCodePathStart: () => number;
|
|
18
|
-
onCodePathEnd(codePath: Rule.CodePath, codePathNode: Rule.Node): void;
|
|
19
|
-
CallExpression(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
|
20
|
-
Identifier(node: estree.Identifier & Rule.NodeParentExtension): void;
|
|
21
|
-
'CallExpression:exit'(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
|
22
|
-
FunctionDeclaration(node: estree.FunctionDeclaration & Rule.NodeParentExtension): void;
|
|
23
|
-
ArrowFunctionExpression(node: estree.ArrowFunctionExpression & Rule.NodeParentExtension): void;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
5
|
'exhaustive-deps': {
|
|
27
6
|
meta: {
|
|
28
7
|
type: "suggestion";
|
|
@@ -51,9 +30,30 @@ declare const rules: {
|
|
|
51
30
|
CallExpression: (node: estree.CallExpression) => void;
|
|
52
31
|
};
|
|
53
32
|
};
|
|
33
|
+
'react-compiler': Rule.RuleModule;
|
|
34
|
+
'rules-of-hooks': {
|
|
35
|
+
meta: {
|
|
36
|
+
type: "problem";
|
|
37
|
+
docs: {
|
|
38
|
+
description: string;
|
|
39
|
+
recommended: true;
|
|
40
|
+
url: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
create(context: Rule.RuleContext): {
|
|
44
|
+
onCodePathSegmentStart: (segment: Rule.CodePathSegment) => number;
|
|
45
|
+
onCodePathSegmentEnd: () => Rule.CodePathSegment | undefined;
|
|
46
|
+
onCodePathStart: () => number;
|
|
47
|
+
onCodePathEnd(codePath: Rule.CodePath, codePathNode: Rule.Node): void;
|
|
48
|
+
CallExpression(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
|
49
|
+
Identifier(node: estree.Identifier & Rule.NodeParentExtension): void;
|
|
50
|
+
'CallExpression:exit'(node: estree.CallExpression & Rule.NodeParentExtension): void;
|
|
51
|
+
FunctionDeclaration(node: estree.FunctionDeclaration & Rule.NodeParentExtension): void;
|
|
52
|
+
ArrowFunctionExpression(node: estree.ArrowFunctionExpression & Rule.NodeParentExtension): void;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
54
55
|
};
|
|
55
56
|
declare const configs: {
|
|
56
|
-
/** Legacy recommended config, to be used with rc-based configurations */
|
|
57
57
|
'recommended-legacy': {
|
|
58
58
|
plugins: string[];
|
|
59
59
|
rules: {
|
|
@@ -61,18 +61,16 @@ declare const configs: {
|
|
|
61
61
|
'react-hooks/exhaustive-deps': "warn";
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
/**
|
|
65
|
-
* 'recommended' is currently aliased to the legacy / rc recommended config) to maintain backwards compatibility.
|
|
66
|
-
* This is deprecated and in v6, it will switch to alias the flat recommended config.
|
|
67
|
-
*/
|
|
68
64
|
recommended: {
|
|
69
|
-
|
|
65
|
+
name: string;
|
|
66
|
+
plugins: {
|
|
67
|
+
readonly 'react-hooks': ESLint.Plugin;
|
|
68
|
+
};
|
|
70
69
|
rules: {
|
|
71
70
|
'react-hooks/rules-of-hooks': "error";
|
|
72
71
|
'react-hooks/exhaustive-deps': "warn";
|
|
73
72
|
};
|
|
74
73
|
};
|
|
75
|
-
/** Latest recommended config, to be used with flat configurations */
|
|
76
74
|
'recommended-latest': {
|
|
77
75
|
name: string;
|
|
78
76
|
plugins: {
|