Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eslint-plugin-react-hooks & accompanying rules #63

Closed
wants to merge 2 commits into from

Conversation

cwonrails
Copy link

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 #62 that does not check in node_modules as requested by @feross in #62 (comment).

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.

@MatanBobi
Copy link

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.

@feross
Copy link
Member

feross commented Oct 1, 2019

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!

@grzegorz-jakubiak
Copy link

can we add this?

@cwonrails
Copy link
Author

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

@sQVe
Copy link

sQVe commented Mar 19, 2020

It would be awesome to get this merged.

@framerate
Copy link

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!

@orpheus
Copy link

orpheus commented Jun 8, 2020

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.

@hoobdeebla
Copy link

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.

@cwonrails
Copy link
Author

cwonrails commented Aug 31, 2020

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.

@vesparny
Copy link

vesparny commented Sep 8, 2020

@feross any reasons not to merge this?
Thanks

@@ -1,7 +1,7 @@
{
"name": "eslint-config-standard-react",
"description": "JavaScript Standard Style React/JSX support - ESLint Shareable Config",
"version": "9.2.0",
"version": "10.0.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Version bump is usually done by the maintainer on the release commit so you may want to revert this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change.

@@ -9,12 +9,13 @@

"settings": {
"react": {
"version": "detect"
"version": "latest"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assume detect is correct as we can't assume the developer is always on the latest React release?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this

Copy link
Member

@feross feross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes are inline

@@ -9,12 +9,13 @@

"settings": {
"react": {
"version": "detect"
"version": "latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this

"react/react-in-jsx-scope": "error"
"react/react-in-jsx-scope": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All rules in standard are errors. We don't do warnings. Please change this to "error"

@@ -1,7 +1,7 @@
{
"name": "eslint-config-standard-react",
"description": "JavaScript Standard Style React/JSX support - ESLint Shareable Config",
"version": "9.2.0",
"version": "10.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change.

"peerDependencies": {
"eslint": ">=6.2.2",
"eslint-plugin-react": ">=7.6.1"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert all version changes and keep this PR focused on adding support for eslint-plugin-react-hooks only.

@theoludwig
Copy link
Member

Related PR: #67

@LinusU
Copy link
Member

LinusU commented Dec 15, 2022

added in #75

@LinusU LinusU closed this Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet