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

Add eslint-plugin-react-hooks/exhaustive-deps rule to check stale closure dependencies #14636

Merged
merged 33 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c0eafd8
Add ESLint rule for useEffect/useCallback/useMemo Hook dependencies
calebmer Oct 31, 2018
6e2ba67
Fix ReactiveDependencies rule
jamiebuilds Oct 31, 2018
4704a98
fix lint errors
jamiebuilds Oct 31, 2018
6f67ef1
Support useLayoutEffect
gaearon Jan 10, 2019
da75f31
Add some failing tests and comments
gaearon Jan 10, 2019
58183fe
Gather dependencies in child scopes too
gaearon Jan 11, 2019
d1515f4
If we don't find foo.bar.baz in deps, try foo.bar, then foo
gaearon Jan 11, 2019
57ebe56
foo is enough for both foo.bar and foo.baz
gaearon Jan 11, 2019
369aa61
Shorter rule name
gaearon Jan 17, 2019
2df41d8
Add fixable meta
gaearon Jan 18, 2019
3b3d7da
Remove a bunch of code and start from scratch
gaearon Jan 19, 2019
d4d501b
[WIP] Only report errors from dependency array
gaearon Jan 19, 2019
695693c
Fix typo
gaearon Jan 19, 2019
340bffb
[Temp] Skip all tests
gaearon Feb 13, 2019
3832eb3
Fix the first test
gaearon Feb 13, 2019
244a1ff
Revamp the test suite
gaearon Feb 14, 2019
58e38ca
Fix [foo] to include foo.bar
gaearon Feb 15, 2019
0aea58e
Don't suggest call expressions
gaearon Feb 15, 2019
14b2229
Special case 'current' for refs
gaearon Feb 15, 2019
366d5df
Don't complain about known static deps
gaearon Feb 18, 2019
3d46a1e
Support useImperativeHandle
gaearon Feb 18, 2019
3679627
Better punctuation and formatting
gaearon Feb 18, 2019
5d2c991
More uniform message format
gaearon Feb 19, 2019
e0203cb
Treat React.useRef/useState/useReducer as static too
gaearon Feb 19, 2019
54c2e16
Add special message for ref.current
gaearon Feb 19, 2019
6fd2d12
Add a TODO case
gaearon Feb 19, 2019
0c722bb
Alphabetize the autofix
gaearon Feb 20, 2019
12aeaca
Only alphabetize if it already was
gaearon Feb 20, 2019
c40bcaa
Don't add static deps by default
gaearon Feb 20, 2019
56785b5
Add an undefined variable case
gaearon Feb 20, 2019
294b474
Tweak wording
gaearon Feb 20, 2019
2f86a69
Rename to exhaustive-deps
gaearon Feb 20, 2019
8b554ca
Clean up / refactor a little bit
gaearon Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fixtures/eslint/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"plugins": ["react-hooks"],
"rules": {
"react-hooks/rules-of-hooks": 2
"react-hooks/rules-of-hooks": 2,
"react-hooks/exhaustive-deps": 2
}
}
26 changes: 22 additions & 4 deletions fixtures/eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@
// 2. "File > Add Folder to Workspace" this specific folder in VSCode with ESLint extension
// 3. Changes to the rule source should get picked up without restarting ESLint server

function Foo() {
if (condition) {
useEffect(() => {});
}
function Comment({comment, commentSource}) {
const currentUserID = comment.viewer.id;
const environment = RelayEnvironment.forUser(currentUserID);
const commentID = nullthrows(comment.id);
useEffect(
() => {
const subscription = SubscriptionCounter.subscribeOnce(
`StoreSubscription_${commentID}`,
() =>
StoreSubscription.subscribe(
environment,
{
comment_id: commentID,
},
currentUserID,
commentSource
)
);
return () => subscription.dispose();
},
[commentID, commentSource, currentUserID, environment]
);
}
Loading