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

Proposal of recommended config in eslint-plugin-react-hooks #16872

Closed
maximandrews opened this issue Sep 24, 2019 · 7 comments
Closed

Proposal of recommended config in eslint-plugin-react-hooks #16872

maximandrews opened this issue Sep 24, 2019 · 7 comments
Labels
Resolution: Stale Automatically closed due to inactivity

Comments

@maximandrews
Copy link

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
If you are using eslint-plugin-react-hooks you need to put rules configuration manually. What if in the next version you will add some more rules?
Should everyone who use it after future release add all the new rules to config manually?

What is the expected behavior?
I propose instead of instructing on every new rule to create recommended config as in eslint-plugin-react, as follows:

export default {
  rules: {
    'rules-of-hooks': RuleOfHooks,
    'exhaustive-deps': ExhaustiveDeps
  },
  configs: {
    recommended: {
      plugins: [ 'react-hooks' ],
      parserOptions: {
        ecmaFeatures: { jsx: true }
      },
      rules: {
        'react-hooks/rules-of-hooks': 'error',
        'react-hooks/exhaustive-deps': 'warn'
      }
    }
  }
};

Also, to instruct to extend instead:

extends: [
  'eslint:recommended',
  'plugin:react/recommended',
  'plugin:react-hooks/recommended'
],
@sargant
Copy link

sargant commented Sep 27, 2019

I would also very much like this. Is it a matter of just putting the above in a PR, or would comprehensive tests also be needed?

I'd expect the documentation should also be updated to recommend using this instead of manual rules.

@einarq
Copy link
Contributor

einarq commented Sep 28, 2019

Does anyone know why the recommendation is to set exhaustive-deps to warn instead of error?
Won't incorrect deps usually lead to stale props, missed renders, too many renders, etc?
I'm trying to make sure everyone on my team enable and follow this rule, but "warn" only helps if people actually notice. Why not recommend "error" instead?

@silvenon
Copy link

silvenon commented Oct 3, 2019

I'm also struggling to understand this decision. Not adding a dependency seems like an extremely rare situation that warrants an eslint-disable comment.

@linvain
Copy link

linvain commented Oct 17, 2019

eslint-plugin-import does include recommended config as well:

"extends": [
  "eslint:recommended",
  "plugin:import/recommended",
  "plugin:react/recommended",
  "plugin:react-hooks/recommended" // proposal
]

@silvenon
Copy link

Actually I found out why react-hooks/exhaustive-deps is recommended as warn: because it might not always be right, i.e. might not always correctly detect all the necessary dependencies. This decision makes sense to me now.

@stale
Copy link

stale bot commented Jan 16, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 16, 2020
@stale
Copy link

stale bot commented Jan 24, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 24, 2020
silvenon added a commit to silvenon/react that referenced this issue Feb 4, 2020
Now the extending `plugin:react-hooks/recommended` adds this plugin and
configures both of its rules.
silvenon added a commit to silvenon/react that referenced this issue Feb 5, 2020
Now the extending `plugin:react-hooks/recommended` adds this plugin and
configures both of its rules.
silvenon added a commit to silvenon/react that referenced this issue Feb 17, 2020
Now the extending `plugin:react-hooks/recommended` adds this plugin and
configures both of its rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants