Re-enable "react-hooks/exhaustive-deps" by default in wp-scripts linting #23189
Labels
Needs Technical Feedback
Needs testing from a developer perspective.
[Tool] ESLint plugin
/packages/eslint-plugin
Is your feature request related to a problem? Please describe
I've relatively recently started using
wp-scripts
as part of developing blocks, and I noticed thereact-hooks/exhaustive-deps
rule is disabled.Looking back through the history of PRs, it looks like it was added and then later removed while merging #14985 (comment). In the discussion, it's mentioned the rule was being too noisy. While that hasn't been my experience, to each their own; however, I do believe this rule helps catch easy mistakes in areas that can lead to large problems—side effects.
What does this rule do?
It will statically analyze the side effect callback to detect variables that should be included (if any) in
useEffect
's second argument, which enumerates dependencies to the effect in question. Additionally, it will be smart/aware of variables coming from other hooks. For example, it will recognize that the resulting value ofuseRef
is mutable and therefore cannot be relied upon as a dependency.useEffect
's second argument is key to its behavior, not a stylistic choice. To the extent that this rule can help catch bugs, I believe it will help more that in will hurt in the long run.Describe the solution you'd like
Similar to how the config currently extends
plugin:react/recommended
, I'd propose to addplugin:react-hooks/recommended
to the extends array. This will addreact-hooks/exhaustive-deps
as a warning, not an error. Other common react configs follow this same kind of setup.If agreeable, I'm happy to create a PR and aid with addressing any warnings that ensue from enabling this rule.
Describe alternatives you've considered
The workaround for this is for folks to create their own eslint config and modify as desired with
wordpress/eslint-plugin/recommended
as a starting point. This is definitely doable, although it seems like a roundabout step for something that's so widely used.The text was updated successfully, but these errors were encountered: