Skip to content

Commit 82c636b

Browse files
committed
[eprh] Prepare for 7.0.0
For 7.0.0: Slim down presets to just 3 configurations: - `recommended-legacy`: legacy config with all recommended rules - `recommended`: flat config with all recommended rules, and - `recommended-experimental`: flat config with all recommended rules plus new bleeding edge experimental compiler rules Removed: - `recommended-latest` - `recommended-latest-legacy` - `flat/recommended`
1 parent 9724e3e commit 82c636b

File tree

7 files changed

+57
-49
lines changed

7 files changed

+57
-49
lines changed

fixtures/eslint-v6/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",

fixtures/eslint-v7/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",

fixtures/eslint-v8/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",

packages/eslint-plugin-react-hooks/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.0.0
2+
3+
- **Breaking:** Slim down presets to just 3 configurations, and all compiler rules are enabled by default. Removed `recommended-latest-legacy` and `flat/recommended` configs. The plugin now provides `recommended-legacy` (legacy config with all recommended rules), `recommended` (flat config with all recommended rules), and `recommended-latest` (flat config with all recommended rules plus new bleeding edge experimental compiler rules). ([@poteto](https://github.com/poteto) in [#34757](https://github.com/facebook/react/pull/34757))
4+
15
## 6.1.1
26

37
**Note:** 6.1.0 accidentally allowed use of `recommended` without flat config, causing errors when used with ESLint v9's `defineConfig()` helper. This has been fixed in 6.1.1.

packages/eslint-plugin-react-hooks/README.md

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ The official ESLint plugin for [React](https://react.dev) which enforces the [Ru
44

55
## Installation
66

7-
**Note: If you're using Create React App, please use `react-scripts` >= 3 instead of adding it directly.**
8-
97
Assuming you already have ESLint installed, run:
108

119
```sh
@@ -18,71 +16,40 @@ yarn add eslint-plugin-react-hooks --dev
1816

1917
### Flat Config (eslint.config.js|ts)
2018

21-
#### >= 6.0.0
22-
23-
For users of 6.0 and beyond, add the `recommended` config.
19+
Add the `recommended` config for all recommended rules:
2420

2521
```js
2622
// eslint.config.js
2723
import reactHooks from 'eslint-plugin-react-hooks';
2824
import { defineConfig } from 'eslint/config';
2925

3026
export default defineConfig([
31-
{
32-
files: ["src/**/*.{js,jsx,ts,tsx}"],
33-
plugins: {
34-
'react-hooks': reactHooks,
35-
},
36-
extends: ['react-hooks/recommended'],
37-
},
27+
reactHooks.configs.flat.recommended,
3828
]);
3929
```
4030

41-
#### 5.2.0
42-
43-
For users of 5.2.0 (the first version with flat config support), add the `recommended-latest` config.
31+
If you want to try bleeding edge experimental compiler rules, use `recommended-latest`.
4432

4533
```js
34+
// eslint.config.js
4635
import reactHooks from 'eslint-plugin-react-hooks';
4736
import { defineConfig } from 'eslint/config';
4837

4938
export default defineConfig([
50-
{
51-
files: ["src/**/*.{js,jsx,ts,tsx}"],
52-
plugins: {
53-
'react-hooks': reactHooks,
54-
},
55-
extends: ['react-hooks/recommended-latest'],
56-
},
39+
reactHooks.configs.flat['recommended-latest'],
5740
]);
5841
```
5942

6043
### Legacy Config (.eslintrc)
6144

62-
#### >= 5.2.0
63-
64-
If you are still using ESLint below 9.0.0, you can use `recommended-legacy` for accessing a legacy version of the recommended config.
45+
If you are still using ESLint below 9.0.0, you can use `recommended-legacy` for accessing a legacy version of the recommended config with all recommended rules.
6546

6647
```js
6748
{
68-
"extends": [
69-
// ...
70-
"plugin:react-hooks/recommended-legacy"
71-
]
49+
"extends": ["plugin:react-hooks/recommended-legacy"],
50+
// ...
7251
}
73-
```
74-
75-
#### < 5.2.0
76-
77-
If you're using a version earlier than 5.2.0, the legacy config was simply `recommended`.
7852

79-
```js
80-
{
81-
"extends": [
82-
// ...
83-
"plugin:react-hooks/recommended"
84-
]
85-
}
8653
```
8754

8855
### Custom Configuration
@@ -92,16 +59,34 @@ If you want more fine-grained configuration, you can instead choose to enable sp
9259
#### Flat Config (eslint.config.js|ts)
9360

9461
```js
95-
import * as reactHooks from 'eslint-plugin-react-hooks';
62+
import reactHooks from 'eslint-plugin-react-hooks';
9663

9764
export default [
9865
{
9966
files: ['**/*.{js,jsx}'],
10067
plugins: { 'react-hooks': reactHooks },
10168
// ...
10269
rules: {
70+
// Core hooks rules
10371
'react-hooks/rules-of-hooks': 'error',
10472
'react-hooks/exhaustive-deps': 'warn',
73+
74+
// React Compiler rules
75+
'react-hooks/config': 'error',
76+
'react-hooks/error-boundaries': 'error',
77+
'react-hooks/component-hook-factories': 'error',
78+
'react-hooks/gating': 'error',
79+
'react-hooks/globals': 'error',
80+
'react-hooks/immutability': 'error',
81+
'react-hooks/preserve-manual-memoization': 'error',
82+
'react-hooks/purity': 'error',
83+
'react-hooks/refs': 'error',
84+
'react-hooks/set-state-in-effect': 'error',
85+
'react-hooks/set-state-in-render': 'error',
86+
'react-hooks/static-components': 'error',
87+
'react-hooks/unsupported-syntax': 'warn',
88+
'react-hooks/use-memo': 'error',
89+
'react-hooks/incompatible-library': 'warn',
10590
}
10691
},
10792
];
@@ -116,8 +101,26 @@ export default [
116101
],
117102
"rules": {
118103
// ...
104+
// Core hooks rules
119105
"react-hooks/rules-of-hooks": "error",
120-
"react-hooks/exhaustive-deps": "warn"
106+
"react-hooks/exhaustive-deps": "warn",
107+
108+
// React Compiler rules
109+
"react-hooks/config": "error",
110+
"react-hooks/error-boundaries": "error",
111+
"react-hooks/component-hook-factories": "error",
112+
"react-hooks/gating": "error",
113+
"react-hooks/globals": "error",
114+
"react-hooks/immutability": "error",
115+
"react-hooks/preserve-manual-memoization": "error",
116+
"react-hooks/purity": "error",
117+
"react-hooks/refs": "error",
118+
"react-hooks/set-state-in-effect": "error",
119+
"react-hooks/set-state-in-render": "error",
120+
"react-hooks/static-components": "error",
121+
"react-hooks/unsupported-syntax": "warn",
122+
"react-hooks/use-memo": "error",
123+
"react-hooks/incompatible-library": "warn"
121124
}
122125
}
123126
```

packages/eslint-plugin-react-hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eslint-plugin-react-hooks",
33
"description": "ESLint rules for React Hooks",
4-
"version": "5.2.0",
4+
"version": "7.0.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/facebook/react.git",

packages/eslint-plugin-react-hooks/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ const allRuleConfigs: Linter.RulesRecord = {
4444
const plugins = ['react-hooks'];
4545

4646
type ReactHooksFlatConfig = {
47-
plugins: Record<string, any>;
47+
plugins: {react: any};
4848
rules: Linter.RulesRecord;
4949
};
5050

5151
const configs = {
5252
'recommended-legacy': {
5353
plugins,
54-
rules: basicRuleConfigs,
54+
rules: allRuleConfigs,
5555
},
5656
'recommended-latest-legacy': {
5757
plugins,
@@ -75,6 +75,7 @@ const configs = {
7575
const plugin = {
7676
meta: {
7777
name: 'eslint-plugin-react-hooks',
78+
version: '7.0.0',
7879
},
7980
rules,
8081
configs,

0 commit comments

Comments
 (0)