add eslint-plugin-react-hooks & accompanying rules
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update [ ] Bug fix [x] New feature [ ] Other, please explain:
What changes did you make? (Give an overview)
This is a cleaned-up version of https://github.com/standard/eslint-config-standard-react/pull/62 that does not check in node_modules as requested by @feross in https://github.com/standard/eslint-config-standard-react/pull/62#issuecomment-533818035.
Added eslint-plugin-react-hooks to package.json and added the associated rules to eslintrc.json.
Is there anything you'd like reviewers to focus on?
In the original PR @MatanBobi referenced the discussion in the original issue about the "react-hooks/exhaustive-deps" rule being set to "warn" (Facebook's suggested setting) potentially being incompatible with the Standard approach. While this PR went with"warn" I can gladly change it to "error" as suggested by @orpheus.
Thanks for taking care of that @cwonrails, didn't get the time for that. Regarding the warn vs error, Dan Abramov stated in one of his comments he doesn't believe this rule should block compiling: https://twitter.com/dan_abramov/status/1103767047555739666?s=20
So I'm not so sure if this should be an error.
I'm not going to be able to take a look at this for a little while, but will get to it when I can. Thanks!
can we add this?
I'm also glad to update the PR if that's a blocker for merging.
It would be awesome to get this merged.
I'm looking for any feedback on this (maybe it got handled elsewhere?). Since hooks are a big part of my workflow I need to use the eslint-plugin-react-hooks and need to know if standard is going to support it.
Thanks!
I ended up removing standard and just using eslint to extend stardard. Here's my eslint config:
module.exports = {
env: {
browser: true,
es6: true,
node: true,
jest: true
},
extends: [
'standard'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: 'module'
},
parser: 'babel-eslint',
plugins: [
'react',
'react-hooks'
],
rules: {
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error'
}
}
Take what you want from that, but other than installing the plugins, it's a simple setup.
For this PR, eslint-plugin-react-hooks should be added as a peerDependency in addition to a devDependency, yes? Without the plugin as a peerDependency, the new rules won't work. The users of this config would need to manually npm install --save-dev eslint-plugin-react-hooks instead of running npx install-peerdeps --dev eslint-config-standard-react to install the hooks plugin if it is not indicated as such. Also, since this adds a new peerDependency, wouldn't it necessitate a semver-major? npm update won't install peerDependencies in any case.
Just updated this PR. Changes: bumped all dependencies, set react version to latest in .eslintrc.json, and added eslint-plugin-react-hooks as a peerDependency as suggested by hoobdeebla.
@feross any reasons not to merge this? Thanks
Related PR: https://github.com/standard/eslint-config-standard-react/pull/67
added in #75