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

[ESLint] Add more cases to exhaustive-deps rule #14930

Merged
merged 4 commits into from
Feb 25, 2019

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Feb 22, 2019

@sizebot
Copy link

sizebot commented Feb 22, 2019

Details of bundled changes.

Comparing: f99fca3...e9ea642

eslint-plugin-react-hooks

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
eslint-plugin-react-hooks.development.js +9.1% +8.4% 44.77 KB 48.84 KB 10.62 KB 11.51 KB NODE_DEV
eslint-plugin-react-hooks.production.min.js 🔺+13.3% 🔺+11.5% 10.71 KB 12.13 KB 3.94 KB 4.4 KB NODE_PROD
ESLintPluginReactHooks-dev.js +9.6% +8.1% 47.76 KB 52.34 KB 10.95 KB 11.84 KB FB_WWW_DEV

Generated by 🚫 dangerJS

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

{
// Valid because we assign ref.current
// ourselves. Therefore it's likely not
// a ref managed by React.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment and the code below seem out of sync. Maybe bad copy-pasta? Maybe should mirror the comment above?

Valid because the ref is captured.

node: dependencyNode.parent.property,
message:
`Accessing '${dependency}.current' during ` +
`the effect cleanup is likely a mistake because by this time React ` +
Copy link
Collaborator

Choose a reason for hiding this comment

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

A cultural suggestion: Explain what is happening and why rather than telling someone directly they made a mistake. I suspect people might get overly defensive if the computer tells them they made a mistake.

Suggested change
`the effect cleanup is likely a mistake because by this time React ` +
`the effect cleanup will likely cause a TypeError because by this time React ` +

No opinion what should we call it e.g. "null pointer exception", "reading a property from null" etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TypeError isn't the main problem (easy to work around). A bigger problem is that you'll always keep getting the previous ref value since it's being read too early. The challenge is to explain this without freaking people out about how "complex" it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, I misread. This is a different warning from the one I was thinking about. In this case the problem is that you're reading the next ref value when you meant to access the previous one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, maybe

Suggested change
`the effect cleanup is likely a mistake because by this time React ` +
`the effect cleanup will likely use a different ref value because by this time React ` +

My point was more about not actually saying that this "is a mistake". That's already implied by reporting that a lint rule has been violated. As far as I know the other messages don't add this is likely a mistake either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds reasonable.

@gaearon gaearon merged commit 1bbfbc9 into facebook:master Feb 25, 2019
@gaearon gaearon deleted the lint-rule-tweaks branch February 25, 2019 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants