eslint-config-standard-react icon indicating copy to clipboard operation
eslint-config-standard-react copied to clipboard

add eslint-plugin-react-hooks & accompanying rules

Open cwonrails opened this issue 6 years ago • 11 comments

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.

cwonrails avatar Sep 29 '19 16:09 cwonrails

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.

MatanBobi avatar Sep 30 '19 13:09 MatanBobi

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!

feross avatar Oct 01 '19 04:10 feross

can we add this?

grzegorz-jakubiak avatar Feb 12 '20 11:02 grzegorz-jakubiak

I'm also glad to update the PR if that's a blocker for merging.

cwonrails avatar Feb 13 '20 19:02 cwonrails

It would be awesome to get this merged.

sQVe avatar Mar 19 '20 12:03 sQVe

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!

framerate avatar Jun 08 '20 04:06 framerate

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.

orpheus avatar Jun 08 '20 13:06 orpheus

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.

hoobdeebla avatar Jul 22 '20 15:07 hoobdeebla

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.

cwonrails avatar Aug 31 '20 13:08 cwonrails

@feross any reasons not to merge this? Thanks

vesparny avatar Sep 08 '20 08:09 vesparny

Related PR: https://github.com/standard/eslint-config-standard-react/pull/67

theoludwig avatar Aug 13 '21 15:08 theoludwig

added in #75

LinusU avatar Dec 15 '22 11:12 LinusU