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

feat(eslint): add react hooks plugin configuration #363

Merged
merged 1 commit into from
Mar 15, 2022

Conversation

ismay
Copy link
Contributor

@ismay ismay commented Mar 10, 2021

This adds config for the react-hooks eslint plugin. The plugin already ships with CRA, so all I've done is enable it:

Screenshot 2021-03-10 at 11 02 01

I've set exhaustive-deps to warn. Initially there were some false positives for this rule that meant an error wasn't always correct: facebook/react#14920. Though that issue has since been closed, so maybe it's safe to set to error. There are some related issues open: https://github.com/facebook/react/issues?q=is%3Aissue+is%3Aopen+exhaustive, but maybe setting it to error and just expecting the user to disable when necessary is good enough.

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

Not quite sure about this one. Left a comment in the code to explain why.

Comment on lines 19 to 20
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
Copy link
Contributor

@HendrikThePendric HendrikThePendric Mar 10, 2021

Choose a reason for hiding this comment

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

Perhaps the opposite approach makes more sense: we start strict and relax rules once people start complaining?

In a way what you've done here is more user-friendly, but in practice I worry we won't ever get requested to enforce stricter rules. On the other hand if we start of with rules that are too strict we'll see failing checks on GitHub, so we are 100% guaranteed to get feedback on this.

Copy link
Contributor Author

@ismay ismay Mar 10, 2021

Choose a reason for hiding this comment

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

My reasoning was: if the rule is known to have false positives we might break CI for users that aren't doing anything wrong. If we're going to break CI then I feel this update should be a major update.

So I'd go with the minor update first, and then the major version once we're sure it works as expected (basically deprecating first, and then shipping the breaking change).

The rules of hooks error seemed allowed to me in a minor since if that breaks, you're already doing something wrong that has broken your app anyway. Though I guess you could also make the argument that that should be a breaking change.

@stale
Copy link

stale bot commented Mar 2, 2022

Hi!

Due to a lack of activity on this issue over time (180 days) it seems to be stale. If still relevant, please provide information that moves it forward, e.g. additional information, a pull request with suggested changes, or a reason to keep it open.

Any activity will keep it open, otherwise it will be closed automatically in 30 days. Thanks! 🤖

@stale stale bot added the stale label Mar 2, 2022
Copy link
Member

@amcgee amcgee left a comment

Choose a reason for hiding this comment

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

Let's get this in :-)

In practice there are legitimate reasons to ignore the "exhaustive deps" check. In app-runtime we use an error as @HendrikThePendric suggested which requires us to manually disable the check where they know they're breaking the rule. I think this is fine for our tightly-controlled libraries, but for apps (and in particular third party apps) I think we can go either way and starting less-strict will cause fewer adoption pains.

@stale stale bot removed the stale label Mar 15, 2022
@ismay ismay merged commit 3236782 into master Mar 15, 2022
@ismay ismay deleted the add-react-hooks-plugin branch March 15, 2022 16:36
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 10.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants