Skip to content

Commit

Permalink
Add recommended config for eslint-plugin-react-hooks (#16872)
Browse files Browse the repository at this point in the history
Now the extending `plugin:react-hooks/recommended` adds this plugin and
configures both of its rules.
  • Loading branch information
silvenon committed Feb 17, 2020
1 parent 9def56e commit 6324c9f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/eslint-plugin-react-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const CLIEngine = require('eslint').CLIEngine;
// console.log(require.resolve('eslint-plugin-react-hooks'))

describe('react-hooks', () => {
test('recommended config', () => {
const cli = new CLIEngine({
useEslintrc: false,
baseConfig: {
extends: [`plugin:react-hooks/recommended`],
}
});
const config = cli.getConfigForFile(__filename);
expect(config).toEqual(expect.objectContaining({
plugins: ['react-hooks'],
rules: {
'react-hooks/rules-of-hooks': ['error'],
'react-hooks/exhaustive-deps': ['warn'],
},
}));
});
});
10 changes: 10 additions & 0 deletions packages/eslint-plugin-react-hooks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ 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',
},
},
};

0 comments on commit 6324c9f

Please sign in to comment.