-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Components: Add exhaustive-deps
eslint rule
#41166
Conversation
Size Change: 0 B Total Size: 1.29 MB ℹ️ View Unchanged
|
If possible it would be great to maintain all ESLint rules from a central location using overrides: Line 179 in 59f42b3
Otherwise it’s harder to reason how rules resolve because the information is chunked in a few places. It’d be important to reference the previous attempt to introduce this rule in #24914. There was a long discussion so I guess it isn’t that simple to work with this rule 😅 |
@gziolo 's advice makes sense to me — we could do something like diff --git a/.eslintrc.js b/.eslintrc.js
index 22c354394d..e70d083496 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -224,6 +224,13 @@ module.exports = {
],
},
},
+ {
+ files: [ 'packages/components/src/**/*.js' ],
+ excludedFiles: [ ...developmentFiles ],
+ rules: {
+ 'react-hooks/exhaustive-deps': 'warn',
+ },
+ },
{
files: [ 'packages/jest*/**/*.js', '**/test/**/*.js' ],
excludedFiles: [ 'test/e2e/**/*.js' ], This way, we could also widen this rule to cover more packages in the future. |
Awesome, I was going to ask if using overrides this way made sense, thank you! |
The rule has been moved to the plugin's central |
All currently known One thing: currently in this PR the rule will generate warnings, should we consider erroring instead? Update: I rebased and changed the lint rule from It looks like |
051e569
to
3527ad8
Compare
Thank you @flootr and @ciampo for knocking out those last few PRs. The list (including the recent additions) is now complete! Running |
Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
3527ad8
to
dfca6be
Compare
I guess the last thing to decided is whether we should |
There was a problem hiding this 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, we can always change to warn
in a follow-up 🚀
Thanks @ciampo |
|
Note: This PR shouldn't be merged until after the list of updates below is completed to ensure everything is ready to pass!
What?
Activate the
exhaustive-deps
rule to trigger warnings for missing deps in dependency arrays foruseEffect
,useLayoutEffect
,useMemo
,useCallback
, oruseImperativeHandle
Why?
Missing dependencies can lead to unexpected results like stale state values. This rule helps us guard against that.
How?
Below is a list of the components/files that currently throw
exhuastive-deps
warnings. I'll be going through as many as possible (help from other contributors is of course welcome!) to analyze and udpate as needed. Once all components are passing linting,this PR can be merged, activating the rule for the entire Components package.Testing Instructions
npx eslint --rule 'react-hooks/exhaustive-deps: warn' packages/components/src
Components and files to be updated:
AlignmentMatrixControl
to passexhaustive-deps
#41167Autocomplete
to passexhaustive-deps
#41382BorderControl
to passexhaustive-deps
#41259ColorPalette
to disableexhaustive-deps
check for now #41253ColorPicker
to passexhaustive-deps
#41294ComboboxControl
to passexhaustive-deps
#41417CustomGradientBar
to passexhaustive-deps
#41463DateDayPicker
to passexhaustive-deps
#41470Draggable
to passexhaustive-deps
#41499Dropdown
to passexhaustive-deps
#41505Flex
to passexhaustive-deps
#41507FocalPointPicker
to pass exhaustive-deps #41520FontSizePicker
to passexhaustive-deps
#41600InputControl
to passexhaustive-deps
#41601Mobile
to ignoreexhuastive-deps
#44207Modal
to passexhaustive-deps
#41610Navigation
to passexhaustive-deps
#41612NavigationItem
to passexhaustive-deps
#41639NavigationMenu
to ignoreexhaustive-deps
#44090NavigatorButton
to passexhaustive-deps
#42051NavigatorScreen
to passexhaustive-deps
#43876Notice
to passexhaustive-deps
#44157PaletteEditListView
to ignoreexhaustive-deps
#45467 as a follow up to @flootr's work inPaletteEditListView
: add missing deps touseEffect
dep array #43911RangeControl
to passexhaustive-deps
#44271ResizableBox
to passexhaustive-deps
#44370Sandbox
to passexhaustive-deps
#44378SearchControl
native files to ignoreexhaustive-deps
#44381SlotFill
to passexhaustive-deps
#44403Snackbar
to passexhaustive-deps
#44934TabPanel
to passexhaustive-deps
#44935ToolsPanel
to passexhaustive-deps
#45028Tooltip
to ignoreexhaustive-deps
#45043ContextSystemProvider
and theuseUpdateEffect
util to ignoreexhaustive-deps
#45044After completing the tasks above, I checked for any new warnings and found the following, which I'll tackle before proceeding:
useFlex
to passexhaustive-deps
#45528withNotices
to passexhaustive-deps
#45530ItemGroup
to passexhaustive-deps
#45531NavigatorScreen
: satisfyexhaustive-deps
eslint rule #45648exhaustive-deps
warning #45660useCx
story to satisfyexhaustive-deps
eslint rule #45614cc @mirka @ciampo