Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit e51d5d7

Browse files
azat-ioShinigami92
andauthored
Add support for react-hooks (#194)
Co-authored-by: Shinigami92 <[email protected]>
1 parent 5e0578a commit e51d5d7

File tree

9 files changed

+91
-0
lines changed

9 files changed

+91
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"eslint-plugin-prettier": "~4.2.1",
7777
"eslint-plugin-promise": "~6.1.1",
7878
"eslint-plugin-react": "~7.32.2",
79+
"eslint-plugin-react-hooks": "~4.6.0",
7980
"eslint-plugin-sonarjs": "~0.19.0",
8081
"eslint-plugin-spellcheck": "~0.0.20",
8182
"eslint-plugin-unicorn": "~46.0.0",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/generate-rule-files/src/plugins-map.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
5959
name: 'React',
6060
module: 'eslint-plugin-react',
6161
},
62+
'react-hooks': {
63+
name: 'ReactHooks',
64+
module: 'eslint-plugin-react-hooks',
65+
},
6266
sonarjs: {
6367
name: 'SonarJS',
6468
prefix: 'sonarjs',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Eslint ReactHooks extensions.
3+
*
4+
* @see [Eslint ReactHooks extensions](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
5+
*/
6+
export type ReactHooksExtensions = 'plugin:react-hooks/recommended';

src/config/extends/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { NodeExtensions } from './eslint-plugin-node';
1111
import type { PrettierExtensions } from './eslint-plugin-prettier';
1212
import type { PromiseExtensions } from './eslint-plugin-promise';
1313
import type { ReactExtensions } from './eslint-plugin-react';
14+
import type { ReactHooksExtensions } from './eslint-plugin-react-hooks';
1415
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
1516
import type { UnicornExtensions } from './eslint-plugin-unicorn';
1617
import type { VitestExtensions } from './eslint-plugin-vitest';
@@ -36,6 +37,7 @@ export type KnownExtensions = LiteralUnion<
3637
| PrettierExtensions
3738
| PromiseExtensions
3839
| ReactExtensions
40+
| ReactHooksExtensions
3941
| SonarjsExtensions
4042
| TypescriptEslintExtensions
4143
| UnicornExtensions

src/rules/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { NRules } from './n';
99
import type { NodeRules } from './node';
1010
import type { PromiseRules } from './promise';
1111
import type { ReactRules } from './react';
12+
import type { ReactHooksRules } from './react-hooks';
1213
import type { RuleConfig } from './rule-config';
1314
import type { SonarJSRules } from './sonarjs';
1415
import type { SpellcheckRules } from './spellcheck';
@@ -35,6 +36,7 @@ export type Rules = Partial<
3536
NodeRules &
3637
NRules &
3738
PromiseRules &
39+
ReactHooksRules &
3840
ReactRules &
3941
SonarJSRules &
4042
SpellcheckRules &
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export interface ExhaustiveDepsOption {
7+
additionalHooks?: string;
8+
enableDangerousAutofixThisMayCauseInfiniteLoops?: boolean;
9+
}
10+
11+
/**
12+
* Options.
13+
*/
14+
export type ExhaustiveDepsOptions = [ExhaustiveDepsOption?];
15+
16+
/**
17+
* Verifies the list of dependencies for Hooks like useEffect and similar.
18+
*
19+
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
20+
*/
21+
export type ExhaustiveDepsRuleConfig = RuleConfig<ExhaustiveDepsOptions>;
22+
23+
/**
24+
* Verifies the list of dependencies for Hooks like useEffect and similar.
25+
*
26+
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
27+
*/
28+
export interface ExhaustiveDepsRule {
29+
/**
30+
* Verifies the list of dependencies for Hooks like useEffect and similar.
31+
*
32+
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
33+
*/
34+
'react-hooks/exhaustive-deps': ExhaustiveDepsRuleConfig;
35+
}

src/rules/react-hooks/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ExhaustiveDepsRule } from './exhaustive-deps';
2+
import type { RulesOfHooksRule } from './rules-of-hooks';
3+
4+
/**
5+
* All ReactHooks rules.
6+
*/
7+
export type ReactHooksRules = RulesOfHooksRule & ExhaustiveDepsRule;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Enforces the Rules of Hooks.
5+
*
6+
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
7+
*/
8+
export type RulesOfHooksRuleConfig = RuleConfig<[]>;
9+
10+
/**
11+
* Enforces the Rules of Hooks.
12+
*
13+
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
14+
*/
15+
export interface RulesOfHooksRule {
16+
/**
17+
* Enforces the Rules of Hooks.
18+
*
19+
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
20+
*/
21+
'react-hooks/rules-of-hooks': RulesOfHooksRuleConfig;
22+
}

0 commit comments

Comments
 (0)