Skip to content

Commit

Permalink
Add support for react-hooks (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: Shinigami92 <chrissi92@hotmail.de>
  • Loading branch information
azat-io and Shinigami92 committed Apr 26, 2023
1 parent 5e0578a commit e51d5d7
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -76,6 +76,7 @@
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-promise": "~6.1.1",
"eslint-plugin-react": "~7.32.2",
"eslint-plugin-react-hooks": "~4.6.0",
"eslint-plugin-sonarjs": "~0.19.0",
"eslint-plugin-spellcheck": "~0.0.20",
"eslint-plugin-unicorn": "~46.0.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -59,6 +59,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
name: 'React',
module: 'eslint-plugin-react',
},
'react-hooks': {
name: 'ReactHooks',
module: 'eslint-plugin-react-hooks',
},
sonarjs: {
name: 'SonarJS',
prefix: 'sonarjs',
Expand Down
6 changes: 6 additions & 0 deletions src/config/extends/eslint-plugin-react-hooks.d.ts
@@ -0,0 +1,6 @@
/**
* Eslint ReactHooks extensions.
*
* @see [Eslint ReactHooks extensions](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
*/
export type ReactHooksExtensions = 'plugin:react-hooks/recommended';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -11,6 +11,7 @@ import type { NodeExtensions } from './eslint-plugin-node';
import type { PrettierExtensions } from './eslint-plugin-prettier';
import type { PromiseExtensions } from './eslint-plugin-promise';
import type { ReactExtensions } from './eslint-plugin-react';
import type { ReactHooksExtensions } from './eslint-plugin-react-hooks';
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
import type { UnicornExtensions } from './eslint-plugin-unicorn';
import type { VitestExtensions } from './eslint-plugin-vitest';
Expand All @@ -36,6 +37,7 @@ export type KnownExtensions = LiteralUnion<
| PrettierExtensions
| PromiseExtensions
| ReactExtensions
| ReactHooksExtensions
| SonarjsExtensions
| TypescriptEslintExtensions
| UnicornExtensions
Expand Down
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -9,6 +9,7 @@ import type { NRules } from './n';
import type { NodeRules } from './node';
import type { PromiseRules } from './promise';
import type { ReactRules } from './react';
import type { ReactHooksRules } from './react-hooks';
import type { RuleConfig } from './rule-config';
import type { SonarJSRules } from './sonarjs';
import type { SpellcheckRules } from './spellcheck';
Expand All @@ -35,6 +36,7 @@ export type Rules = Partial<
NodeRules &
NRules &
PromiseRules &
ReactHooksRules &
ReactRules &
SonarJSRules &
SpellcheckRules &
Expand Down
35 changes: 35 additions & 0 deletions src/rules/react-hooks/exhaustive-deps.d.ts
@@ -0,0 +1,35 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface ExhaustiveDepsOption {
additionalHooks?: string;
enableDangerousAutofixThisMayCauseInfiniteLoops?: boolean;
}

/**
* Options.
*/
export type ExhaustiveDepsOptions = [ExhaustiveDepsOption?];

/**
* Verifies the list of dependencies for Hooks like useEffect and similar.
*
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
*/
export type ExhaustiveDepsRuleConfig = RuleConfig<ExhaustiveDepsOptions>;

/**
* Verifies the list of dependencies for Hooks like useEffect and similar.
*
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
*/
export interface ExhaustiveDepsRule {
/**
* Verifies the list of dependencies for Hooks like useEffect and similar.
*
* @see [exhaustive-deps](https://github.com/facebook/react/issues/14920)
*/
'react-hooks/exhaustive-deps': ExhaustiveDepsRuleConfig;
}
7 changes: 7 additions & 0 deletions src/rules/react-hooks/index.d.ts
@@ -0,0 +1,7 @@
import type { ExhaustiveDepsRule } from './exhaustive-deps';
import type { RulesOfHooksRule } from './rules-of-hooks';

/**
* All ReactHooks rules.
*/
export type ReactHooksRules = RulesOfHooksRule & ExhaustiveDepsRule;
22 changes: 22 additions & 0 deletions src/rules/react-hooks/rules-of-hooks.d.ts
@@ -0,0 +1,22 @@
import type { RuleConfig } from '../rule-config';

/**
* Enforces the Rules of Hooks.
*
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
*/
export type RulesOfHooksRuleConfig = RuleConfig<[]>;

/**
* Enforces the Rules of Hooks.
*
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
*/
export interface RulesOfHooksRule {
/**
* Enforces the Rules of Hooks.
*
* @see [rules-of-hooks](https://reactjs.org/docs/hooks-rules.html)
*/
'react-hooks/rules-of-hooks': RulesOfHooksRuleConfig;
}

0 comments on commit e51d5d7

Please sign in to comment.