Registry Mirror
Skip to content

File tree

‎fixtures/eslint-v6/.eslintrc.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",
77
"ecmaFeatures": {
88
"jsx": true
99
}
10-
},
11-
"rules": {
12-
"react-hooks/exhaustive-deps": "error"
1310
}
1411
}

‎fixtures/eslint-v6/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,27 @@ function useHookInLoops() {
141141
useHook4();
142142
}
143143
}
144+
145+
/**
146+
* Compiler Rules
147+
*/
148+
// Invalid: component factory
149+
function InvalidComponentFactory() {
150+
const DynamicComponent = () => <div>Hello</div>;
151+
// eslint-disable-next-line react-hooks/static-components
152+
return <DynamicComponent />;
153+
}
154+
155+
// Invalid: mutating globals
156+
function InvalidGlobals() {
157+
// eslint-disable-next-line react-hooks/immutability
158+
window.myGlobal = 42;
159+
return <div>Done</div>;
160+
}
161+
162+
// Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+
function InvalidUseMemo({items}) {
164+
// eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+
const sorted = useMemo(() => [...items].sort(), []);
166+
return <div>{sorted.length}</div>;
167+
}

‎fixtures/eslint-v7/.eslintrc.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",
77
"ecmaFeatures": {
88
"jsx": true
99
}
10-
},
11-
"rules": {
12-
"react-hooks/exhaustive-deps": "error"
1310
}
1411
}

‎fixtures/eslint-v7/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,27 @@ function useHookInLoops() {
141141
useHook4();
142142
}
143143
}
144+
145+
/**
146+
* Compiler Rules
147+
*/
148+
// Invalid: component factory
149+
function InvalidComponentFactory() {
150+
const DynamicComponent = () => <div>Hello</div>;
151+
// eslint-disable-next-line react-hooks/static-components
152+
return <DynamicComponent />;
153+
}
154+
155+
// Invalid: mutating globals
156+
function InvalidGlobals() {
157+
// eslint-disable-next-line react-hooks/immutability
158+
window.myGlobal = 42;
159+
return <div>Done</div>;
160+
}
161+
162+
// Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+
function InvalidUseMemo({items}) {
164+
// eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+
const sorted = useMemo(() => [...items].sort(), []);
166+
return <div>{sorted.length}</div>;
167+
}

‎fixtures/eslint-v8/.eslintrc.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
{
22
"root": true,
3-
"extends": ["plugin:react-hooks/recommended-legacy"],
3+
"extends": ["plugin:react-hooks/recommended-latest-legacy"],
44
"parserOptions": {
55
"ecmaVersion": 2020,
66
"sourceType": "module",
77
"ecmaFeatures": {
88
"jsx": true
99
}
10-
},
11-
"rules": {
12-
"react-hooks/exhaustive-deps": "error"
1310
}
1411
}

‎fixtures/eslint-v8/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,27 @@ function useHookInLoops() {
141141
useHook4();
142142
}
143143
}
144+
145+
/**
146+
* Compiler Rules
147+
*/
148+
// Invalid: component factory
149+
function InvalidComponentFactory() {
150+
const DynamicComponent = () => <div>Hello</div>;
151+
// eslint-disable-next-line react-hooks/static-components
152+
return <DynamicComponent />;
153+
}
154+
155+
// Invalid: mutating globals
156+
function InvalidGlobals() {
157+
// eslint-disable-next-line react-hooks/immutability
158+
window.myGlobal = 42;
159+
return <div>Done</div>;
160+
}
161+
162+
// Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+
function InvalidUseMemo({items}) {
164+
// eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+
const sorted = useMemo(() => [...items].sort(), []);
166+
return <div>{sorted.length}</div>;
167+
}

‎fixtures/eslint-v9/eslint.config.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {defineConfig} from 'eslint/config';
22
import reactHooks from 'eslint-plugin-react-hooks';
33

4-
console.log(reactHooks.configs['recommended-latest']);
5-
64
export default defineConfig([
75
{
86
languageOptions: {

‎fixtures/eslint-v9/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,27 @@ function useHookInLoops() {
141141
useHook4();
142142
}
143143
}
144+
145+
/**
146+
* Compiler Rules
147+
*/
148+
// Invalid: component factory
149+
function InvalidComponentFactory() {
150+
const DynamicComponent = () => <div>Hello</div>;
151+
// eslint-disable-next-line react-hooks/static-components
152+
return <DynamicComponent />;
153+
}
154+
155+
// Invalid: mutating globals
156+
function InvalidGlobals() {
157+
// eslint-disable-next-line react-hooks/immutability
158+
window.myGlobal = 42;
159+
return <div>Done</div>;
160+
}
161+
162+
// Invalid: useMemo with wrong deps - triggers preserve-manual-memoization
163+
function InvalidUseMemo({items}) {
164+
// eslint-disable-next-line react-hooks/preserve-manual-memoization, react-hooks/exhaustive-deps
165+
const sorted = useMemo(() => [...items].sort(), []);
166+
return <div>{sorted.length}</div>;
167+
}

0 commit comments

Comments
 (0)