Skip to content

Commit 5308724

Browse files
wakamshaclaude
andauthored
feat(eslint-config)!: enable recommended react-hooks rules from v6 (#424)
* feat(eslint-config)!: enable recommended react-hooks rules from v6 Spread `reactHooks.configs.flat.recommended.rules` into the flat React config and add `extends: ['plugin:react-hooks/recommended']` to the eslintrc rule set. Switch the flat config's `languageOptions` to `react.configs.flat?.recommended.languageOptions` so JSX parser options are propagated correctly. BREAKING CHANGE: 13 new error-level react-hooks rules are now enabled by default (component-hook-factories, config, error-boundaries, gating, globals, immutability, preserve-manual-memoization, purity, refs, set-state-in-effect, set-state-in-render, static-components, use-memo), plus 2 new warn-level rules (incompatible-library, unsupported-syntax). Downstream consumers may see new lint errors on existing React code and should either fix the violations or explicitly override these rules. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: fix ci --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1410a04 commit 5308724

File tree

10 files changed

+288
-2
lines changed

10 files changed

+288
-2
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ name: test
33
on:
44
pull_request:
55
branches:
6-
- '*'
6+
- "*"
77

88
jobs:
99
test:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v6
13+
with:
14+
ref: ${{ github.event.pull_request.head.sha }}
1315

1416
- name: Initialize
1517
uses: ./.github/actions/restore-node

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ typings/
6666

6767
# Visual Studio Code
6868
.vscode/*
69+
70+
# Claude settings
71+
.claude/settings.local.json

packages/eslint-config/configs/flat/react.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const reactHooksRuleSet = {
2121
'react-hooks': reactHooks,
2222
},
2323
rules: {
24+
...reactHooks.configs.flat.recommended.rules,
2425
...reactHooksRuleSetBase.rules,
2526
},
2627
};
@@ -38,7 +39,7 @@ const jsxA11yRuleSet = {
3839
export default [
3940
{
4041
languageOptions: {
41-
...react.configs.recommended.languageOptions,
42+
...react.configs.flat?.recommended.languageOptions,
4243
},
4344

4445
settings: {

packages/eslint-config/rules/react-hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
plugins: ['react-hooks'],
3+
extends: ['plugin:react-hooks/recommended'],
34

45
rules: {
56
// Verify the list of the dependencies for Hooks like useEffect and similar.

packages/eslint-config/tests/snapshot-test/eslintrc/next/__snapshots__/snapshot.test.js.snap

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,12 +2244,57 @@ exports[`should match ESLint configuration snapshot: next 1`] = `
22442244
"radix": [
22452245
2,
22462246
],
2247+
"react-hooks/component-hook-factories": [
2248+
2,
2249+
],
2250+
"react-hooks/config": [
2251+
2,
2252+
],
2253+
"react-hooks/error-boundaries": [
2254+
2,
2255+
],
22472256
"react-hooks/exhaustive-deps": [
22482257
2,
22492258
],
2259+
"react-hooks/gating": [
2260+
2,
2261+
],
2262+
"react-hooks/globals": [
2263+
2,
2264+
],
2265+
"react-hooks/immutability": [
2266+
2,
2267+
],
2268+
"react-hooks/incompatible-library": [
2269+
1,
2270+
],
2271+
"react-hooks/preserve-manual-memoization": [
2272+
2,
2273+
],
2274+
"react-hooks/purity": [
2275+
2,
2276+
],
2277+
"react-hooks/refs": [
2278+
2,
2279+
],
22502280
"react-hooks/rules-of-hooks": [
22512281
2,
22522282
],
2283+
"react-hooks/set-state-in-effect": [
2284+
2,
2285+
],
2286+
"react-hooks/set-state-in-render": [
2287+
2,
2288+
],
2289+
"react-hooks/static-components": [
2290+
2,
2291+
],
2292+
"react-hooks/unsupported-syntax": [
2293+
1,
2294+
],
2295+
"react-hooks/use-memo": [
2296+
2,
2297+
],
22532298
"react/boolean-prop-naming": [
22542299
0,
22552300
{

packages/eslint-config/tests/snapshot-test/eslintrc/react/__snapshots__/snapshot.test.js.snap

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,12 +2181,57 @@ exports[`should match ESLint configuration snapshot: react 1`] = `
21812181
"radix": [
21822182
2,
21832183
],
2184+
"react-hooks/component-hook-factories": [
2185+
2,
2186+
],
2187+
"react-hooks/config": [
2188+
2,
2189+
],
2190+
"react-hooks/error-boundaries": [
2191+
2,
2192+
],
21842193
"react-hooks/exhaustive-deps": [
21852194
2,
21862195
],
2196+
"react-hooks/gating": [
2197+
2,
2198+
],
2199+
"react-hooks/globals": [
2200+
2,
2201+
],
2202+
"react-hooks/immutability": [
2203+
2,
2204+
],
2205+
"react-hooks/incompatible-library": [
2206+
1,
2207+
],
2208+
"react-hooks/preserve-manual-memoization": [
2209+
2,
2210+
],
2211+
"react-hooks/purity": [
2212+
2,
2213+
],
2214+
"react-hooks/refs": [
2215+
2,
2216+
],
21872217
"react-hooks/rules-of-hooks": [
21882218
2,
21892219
],
2220+
"react-hooks/set-state-in-effect": [
2221+
2,
2222+
],
2223+
"react-hooks/set-state-in-render": [
2224+
2,
2225+
],
2226+
"react-hooks/static-components": [
2227+
2,
2228+
],
2229+
"react-hooks/unsupported-syntax": [
2230+
1,
2231+
],
2232+
"react-hooks/use-memo": [
2233+
2,
2234+
],
21902235
"react/boolean-prop-naming": [
21912236
0,
21922237
{

packages/eslint-config/tests/snapshot-test/eslintrc/storybook/__snapshots__/snapshot.test.js.snap

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,12 +1938,57 @@ exports[`should match ESLint configuration snapshot: storybook 1`] = `
19381938
"radix": [
19391939
2,
19401940
],
1941+
"react-hooks/component-hook-factories": [
1942+
2,
1943+
],
1944+
"react-hooks/config": [
1945+
2,
1946+
],
1947+
"react-hooks/error-boundaries": [
1948+
2,
1949+
],
19411950
"react-hooks/exhaustive-deps": [
19421951
2,
19431952
],
1953+
"react-hooks/gating": [
1954+
2,
1955+
],
1956+
"react-hooks/globals": [
1957+
2,
1958+
],
1959+
"react-hooks/immutability": [
1960+
2,
1961+
],
1962+
"react-hooks/incompatible-library": [
1963+
1,
1964+
],
1965+
"react-hooks/preserve-manual-memoization": [
1966+
2,
1967+
],
1968+
"react-hooks/purity": [
1969+
2,
1970+
],
1971+
"react-hooks/refs": [
1972+
2,
1973+
],
19441974
"react-hooks/rules-of-hooks": [
19451975
0,
19461976
],
1977+
"react-hooks/set-state-in-effect": [
1978+
2,
1979+
],
1980+
"react-hooks/set-state-in-render": [
1981+
2,
1982+
],
1983+
"react-hooks/static-components": [
1984+
2,
1985+
],
1986+
"react-hooks/unsupported-syntax": [
1987+
1,
1988+
],
1989+
"react-hooks/use-memo": [
1990+
2,
1991+
],
19471992
"react/boolean-prop-naming": [
19481993
0,
19491994
{

packages/eslint-config/tests/snapshot-test/flat/next/__snapshots__/snapshot.test.js.snap

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ exports[`ESLint Configuration Snapshot Tests should match ESLint Flat Configurat
7474
"parseForESLint": [Function],
7575
},
7676
"parserOptions": {
77+
"ecmaFeatures": {
78+
"jsx": true,
79+
},
7780
"ecmaVersion": "latest",
7881
"projectService": true,
7982
"sourceType": "module",
@@ -2468,12 +2471,57 @@ exports[`ESLint Configuration Snapshot Tests should match ESLint Flat Configurat
24682471
2,
24692472
"always",
24702473
],
2474+
"react-hooks/component-hook-factories": [
2475+
2,
2476+
],
2477+
"react-hooks/config": [
2478+
2,
2479+
],
2480+
"react-hooks/error-boundaries": [
2481+
2,
2482+
],
24712483
"react-hooks/exhaustive-deps": [
24722484
2,
24732485
],
2486+
"react-hooks/gating": [
2487+
2,
2488+
],
2489+
"react-hooks/globals": [
2490+
2,
2491+
],
2492+
"react-hooks/immutability": [
2493+
2,
2494+
],
2495+
"react-hooks/incompatible-library": [
2496+
1,
2497+
],
2498+
"react-hooks/preserve-manual-memoization": [
2499+
2,
2500+
],
2501+
"react-hooks/purity": [
2502+
2,
2503+
],
2504+
"react-hooks/refs": [
2505+
2,
2506+
],
24742507
"react-hooks/rules-of-hooks": [
24752508
2,
24762509
],
2510+
"react-hooks/set-state-in-effect": [
2511+
2,
2512+
],
2513+
"react-hooks/set-state-in-render": [
2514+
2,
2515+
],
2516+
"react-hooks/static-components": [
2517+
2,
2518+
],
2519+
"react-hooks/unsupported-syntax": [
2520+
1,
2521+
],
2522+
"react-hooks/use-memo": [
2523+
2,
2524+
],
24772525
"react/boolean-prop-naming": [
24782526
0,
24792527
{

packages/eslint-config/tests/snapshot-test/flat/react/__snapshots__/snapshot.test.js.snap

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ exports[`ESLint Configuration Snapshot Tests should match ESLint Configuration s
7474
"parseForESLint": [Function],
7575
},
7676
"parserOptions": {
77+
"ecmaFeatures": {
78+
"jsx": true,
79+
},
7780
"ecmaVersion": "latest",
7881
"projectService": true,
7982
"sourceType": "module",
@@ -2405,12 +2408,57 @@ exports[`ESLint Configuration Snapshot Tests should match ESLint Configuration s
24052408
2,
24062409
"always",
24072410
],
2411+
"react-hooks/component-hook-factories": [
2412+
2,
2413+
],
2414+
"react-hooks/config": [
2415+
2,
2416+
],
2417+
"react-hooks/error-boundaries": [
2418+
2,
2419+
],
24082420
"react-hooks/exhaustive-deps": [
24092421
2,
24102422
],
2423+
"react-hooks/gating": [
2424+
2,
2425+
],
2426+
"react-hooks/globals": [
2427+
2,
2428+
],
2429+
"react-hooks/immutability": [
2430+
2,
2431+
],
2432+
"react-hooks/incompatible-library": [
2433+
1,
2434+
],
2435+
"react-hooks/preserve-manual-memoization": [
2436+
2,
2437+
],
2438+
"react-hooks/purity": [
2439+
2,
2440+
],
2441+
"react-hooks/refs": [
2442+
2,
2443+
],
24112444
"react-hooks/rules-of-hooks": [
24122445
2,
24132446
],
2447+
"react-hooks/set-state-in-effect": [
2448+
2,
2449+
],
2450+
"react-hooks/set-state-in-render": [
2451+
2,
2452+
],
2453+
"react-hooks/static-components": [
2454+
2,
2455+
],
2456+
"react-hooks/unsupported-syntax": [
2457+
1,
2458+
],
2459+
"react-hooks/use-memo": [
2460+
2,
2461+
],
24142462
"react/boolean-prop-naming": [
24152463
0,
24162464
{

0 commit comments

Comments
 (0)