Skip to content

Commit 7568e71

Browse files
authored
[eprh] Prepare for 7.0.0 (#34757)
For 7.0.0: Slim down presets to just 2 configurations: - `recommended`: legacy and flat config with all recommended rules, and - `recommended-latest`: legacy and flat config with all recommended rules plus new bleeding edge experimental compiler rules Removed: - `recommended-latest-legacy` - `flat/recommended` Please see the README for new install instructions. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34757). * #34783 * #34782 * __->__ #34757
1 parent 9724e3e commit 7568e71

File tree

8 files changed

+60
-74
lines changed

8 files changed

+60
-74
lines changed

ReactVersions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const canaryChannelLabel = 'canary';
3333
const rcNumber = 0;
3434

3535
const stablePackages = {
36-
'eslint-plugin-react-hooks': '6.2.0',
36+
'eslint-plugin-react-hooks': '7.0.0',
3737
'jest-react': '0.18.0',
3838
react: ReactVersion,
3939
'react-art': ReactVersion,

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"],
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"],
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"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 7.0.0
2+
3+
This release slims down presets to just 2 configurations (`recommended` and `recommended-latest`), and all compiler rules are enabled by default.
4+
5+
- **Breaking:** Removed `recommended-latest-legacy` and `flat/recommended` configs. The plugin now provides `recommended` (legacy and flat configs with all recommended rules), and `recommended-latest` (legacy and flat configs 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))
6+
17
## 6.1.1
28

39
**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, the `recommended` preset can also be used to enable all recommended rules.
6546

6647
```js
6748
{
68-
"extends": [
69-
// ...
70-
"plugin:react-hooks/recommended-legacy"
71-
]
49+
"extends": ["plugin:react-hooks/recommended"],
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 & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,55 +44,32 @@ 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 = {
52-
'recommended-legacy': {
53-
plugins,
54-
rules: basicRuleConfigs,
55-
},
56-
'recommended-latest-legacy': {
52+
recommended: {
5753
plugins,
5854
rules: allRuleConfigs,
5955
},
60-
'flat/recommended': {
61-
plugins,
62-
rules: basicRuleConfigs,
63-
},
6456
'recommended-latest': {
6557
plugins,
6658
rules: allRuleConfigs,
6759
},
68-
recommended: {
69-
plugins,
70-
rules: basicRuleConfigs,
71-
},
7260
flat: {} as Record<string, ReactHooksFlatConfig>,
7361
};
7462

7563
const plugin = {
7664
meta: {
7765
name: 'eslint-plugin-react-hooks',
66+
version: '7.0.0',
7867
},
7968
rules,
8069
configs,
8170
};
8271

8372
Object.assign(configs.flat, {
84-
'recommended-legacy': {
85-
plugins: {'react-hooks': plugin},
86-
rules: configs['recommended-legacy'].rules,
87-
},
88-
'recommended-latest-legacy': {
89-
plugins: {'react-hooks': plugin},
90-
rules: configs['recommended-latest-legacy'].rules,
91-
},
92-
'flat/recommended': {
93-
plugins: {'react-hooks': plugin},
94-
rules: configs['flat/recommended'].rules,
95-
},
9673
'recommended-latest': {
9774
plugins: {'react-hooks': plugin},
9875
rules: configs['recommended-latest'].rules,

0 commit comments

Comments
 (0)