From 95c0e358713b50722c0334cb0620ef002070bde0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Marohni=C4=87?= Date: Tue, 4 Feb 2020 22:18:42 +0100 Subject: [PATCH] Add recommended config for eslint-plugin-react-hooks (#16872) Now the extending `plugin:react-hooks/recommended` adds this plugin and configures both of its rules. --- packages/eslint-plugin-react-hooks/README.md | 11 +++++++++++ packages/eslint-plugin-react-hooks/src/index.js | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/eslint-plugin-react-hooks/README.md b/packages/eslint-plugin-react-hooks/README.md index bda6fe8fdc83a..d3e9265894d2f 100644 --- a/packages/eslint-plugin-react-hooks/README.md +++ b/packages/eslint-plugin-react-hooks/README.md @@ -34,6 +34,17 @@ Then add it to your ESLint configuration: } ``` +You can achieve the configuratin above by simply extending the recommended configuration: + +```js +{ + "extends": [ + // ... + "plugin:react-hooks/recommended" + ] +} +``` + ## Valid and Invalid Examples Please refer to the [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation and the [Hooks FAQ](https://reactjs.org/docs/hooks-faq.html#what-exactly-do-the-lint-rules-enforce) to learn more about this rule. diff --git a/packages/eslint-plugin-react-hooks/src/index.js b/packages/eslint-plugin-react-hooks/src/index.js index 606a6dff4e253..ff2f396923311 100644 --- a/packages/eslint-plugin-react-hooks/src/index.js +++ b/packages/eslint-plugin-react-hooks/src/index.js @@ -14,3 +14,15 @@ export const rules = { 'rules-of-hooks': RuleOfHooks, 'exhaustive-deps': ExhaustiveDeps, }; + +export const configs = { + recommended: { + plugins: [ + 'react-hooks', + ], + rules: { + 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/exhaustive-deps': 'warn', + }, + }, +};