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(linter): react/exhaustive-deps #7151

Merged
merged 1 commit into from
Nov 12, 2024
Merged

feat(linter): react/exhaustive-deps #7151

merged 1 commit into from
Nov 12, 2024

Conversation

camc314
Copy link
Collaborator

@camc314 camc314 commented Nov 6, 2024

Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in #2637 !

closes #2637
relates to #2174

Copy link

graphite-app bot commented Nov 6, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added A-linter Area - Linter A-semantic Area - Semantic labels Nov 6, 2024
@camc314 camc314 force-pushed the c/exhaustive-deps2 branch 3 times, most recently from 95fa95d to e4715ae Compare November 6, 2024 21:41
@camc314 camc314 force-pushed the c/exhaustive-deps2 branch 2 times, most recently from a9758db to 1cd2f0b Compare November 6, 2024 22:45
@camc314 camc314 changed the title DRAFT: feat(linter): react/exhaustive-deps feat(linter): react/exhaustive-deps Nov 6, 2024
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Nov 6, 2024
@camc314 camc314 force-pushed the c/exhaustive-deps2 branch 2 times, most recently from 99854fb to 97c5918 Compare November 6, 2024 23:46
@camc314
Copy link
Collaborator Author

camc314 commented Nov 7, 2024

Rough first draft but most of the way their. would appreciate some early reviews as this was a massive amount of work and i don't want to go too far 🙂

@camc314 camc314 marked this pull request as ready for review November 7, 2024 17:57
@Boshen
Copy link
Member

Boshen commented Nov 8, 2024

Rough first draft but most of the way their. would appreciate some early reviews as this was a massive amount of work and i don't want to go too far 🙂

This is amazing! I would run it through oxlint ecosystem ci and see what happens.

Copy link
Collaborator

@camchenry camchenry left a comment

Choose a reason for hiding this comment

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

This looks pretty good overall, I didn't thoroughly review all of the code (there is a lot!) but I took a look at the diagnostics and have a few help text suggestions. I think keeping this in nursery and continuing to iterate on it would be good

@Boshen
Copy link
Member

Boshen commented Nov 9, 2024

Note: once merged, manually add this rule to oxlint-ecosystem-ci's CI script. We then change this to correctness after running it for 2 - 4 weeks.

Copy link
Collaborator

@camchenry camchenry left a comment

Choose a reason for hiding this comment

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

it's hard to review all of this code, but I have skimmed over most of it and not too much stuck out to me. I think this is ready to start being tested in nursery

crates/oxc_linter/src/service/runtime.rs Outdated Show resolved Hide resolved
@camc314
Copy link
Collaborator Author

camc314 commented Nov 9, 2024

@Boshen did it look ok in the ecosystem ci? https://github.com/oxc-project/oxlint-ecosystem-ci/actions/runs/11755920122/job/32751524336

thanks for testing for me 🙂

Copy link

codspeed-hq bot commented Nov 9, 2024

CodSpeed Performance Report

Merging #7151 will not alter performance

Comparing c/exhaustive-deps2 (3dcac1a) with main (c5f4ee7)

Summary

✅ 30 untouched benchmarks

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Nov 11, 2024
Copy link
Member

Boshen commented Nov 11, 2024

Merge activity

  • Nov 11, 3:36 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 11, 3:36 AM EST: A user added this pull request to the Graphite merge queue.
  • Nov 11, 3:43 AM EST: The Graphite merge queue couldn't merge this PR because it was in draft mode.
  • Nov 12, 6:37 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Nov 12, 6:42 AM EST: A user added this pull request to the Graphite merge queue.
  • Nov 12, 6:47 AM EST: A user merged this pull request with the Graphite merge queue.

@Boshen Boshen marked this pull request as draft November 11, 2024 08:39
@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

Hit the merge button too quickly 😅

In oxlint-ecosystem-ci/repos:

~/oxc/target/release/oxlint -A all -W exhaustive-deps
Finished in 5.5s on 117561 files with 1 rules using 8 threads.
Found 536 warnings and 23 errors.

Some false positives:

affine  canary ❯ ~/oxc/oxc/target/release/oxlint -A all -W exhaustive-deps

  ⚠ react_hooks(exhaustive-deps): React Hook useMemo has a missing dependency: 'T'
     ╭─[packages/frontend/core/src/components/page-list/virtualized-list.tsx:142:6]
 141 │     return items;
 142 │   }, [groupCollapsedState, groups]);
     ·      ─────────────────────────────
 143 │ };
     ╰────
  help: Either include it or remove the dependency array.

It's picking up type annotation

    const items: VirtuosoItem<T>[] = [];

@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

Do you also need to include function calls?

  ⚠ react_hooks(exhaustive-deps): React Hook useEffect has a missing dependency: 'makeMappingRequest'
    ╭─[kibana/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/index_error.tsx:83:6]
 82 │     makeMappingRequest({ indexName });
 83 │   }, [indexName]);
    ·      ───────────
 84 │
    ╰────
  help: Either include it or remove the dependency array.

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 11, 2024
@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

  ⚠ react_hooks(exhaustive-deps): React Hook useCallback has unnecessary dependency: dataVisualizerListState.sortField
     ╭─[kibana/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_field_stats.ts:307:5]
 306 │     dataVisualizerListState.sortDirection,
 307 │     dataVisualizerListState.sortField,
     ·     ───────────────────────
 308 │     samplingProbability,
     ╰────
  help: Either include it or remove the dependency array.

The span is not pointing at the member expression.

@Boshen Boshen marked this pull request as ready for review November 11, 2024 08:47
@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

This looks pretty weird

  ⚠ react_hooks(exhaustive-deps): React Hook useEffect has missing dependencies: 'searchParams.get', 't', and 'form.setValue'
    ╭─[cal/packages/features/eventtypes/components/DuplicateDialog.tsx:67:6]
 66 │     }
 67 │   }, [searchParams?.get("dialog")]);
    ·      ─────────────────────────────
 68 │
    ╰────
  help: Either include it or remove the dependency array.

@Boshen
Copy link
Member

Boshen commented Nov 11, 2024

kibana has the most violations, you may want to test it during developement.

@camc314
Copy link
Collaborator Author

camc314 commented Nov 11, 2024

This looks pretty weird

  ⚠ react_hooks(exhaustive-deps): React Hook useEffect has missing dependencies: 'searchParams.get', 't', and 'form.setValue'
    ╭─[cal/packages/features/eventtypes/components/DuplicateDialog.tsx:67:6]
 66 │     }
 67 │   }, [searchParams?.get("dialog")]);
    ·      ─────────────────────────────
 68 │
    ╰────
  help: Either include it or remove the dependency array.
``

🙂 looks like we're following the same behaviour as eslint

Screenshot 2024-11-11 at 09 40 29

@camc314
Copy link
Collaborator Author

camc314 commented Nov 11, 2024

Do you also need to include function calls?

  ⚠ react_hooks(exhaustive-deps): React Hook useEffect has a missing dependency: 'makeMappingRequest'
    ╭─[kibana/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/index_error.tsx:83:6]
 82 │     makeMappingRequest({ indexName });
 83 │   }, [indexName]);
    ·      ───────────
 84 │
    ╰────
  help: Either include it or remove the dependency array.

looks like they've got it disabled? for this file https://github.com/elastic/kibana//blob/2466a172af66452bdd939dddc56506faba7ffb7a/.eslintrc.js#L1623

when i run eslint on this file, it reports (same as us)

@camc314
Copy link
Collaborator Author

camc314 commented Nov 11, 2024

@Boshen after a4f7675 i don't there are more false positives in affine at least

@Boshen
Copy link
Member

Boshen commented Nov 12, 2024

  ⚠ react_hooks(exhaustive-deps): React Hook useCallback received a function whose dependencies are unknown.
    ╭─[kibana/src/plugins/console/public/application/hooks/use_save_current_text_object.ts:27:5]
 26 │       return useCallback(
 27 │ ╭─▶     throttle(
 28 │ │         (text: string) => {
 29 │ │           const { current: promise } = promiseChainRef;
 30 │ │           if (!currentTextObject) return;
 31 │ │           promise.finally(() =>
 32 │ │             objectStorageClient.text.update({ ...currentTextObject, text, updatedAt: Date.now() })
 33 │ │           );
 34 │ │         },
 35 │ │         WAIT_MS,
 36 │ │         { trailing: true }
 37 │ ╰─▶     ),
 38 │         [objectStorageClient, currentTextObject]
    ╰────
  help: Pass an inline function instead.

Interesting case, how should this be handled?

Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

Feel free to merge after a final self review.

@camc314
Copy link
Collaborator Author

camc314 commented Nov 12, 2024

  ⚠ react_hooks(exhaustive-deps): React Hook useCallback received a function whose dependencies are unknown.
    ╭─[kibana/src/plugins/console/public/application/hooks/use_save_current_text_object.ts:27:5]
 26 │       return useCallback(
 27 │ ╭─▶     throttle(
 28 │ │         (text: string) => {
 29 │ │           const { current: promise } = promiseChainRef;
 30 │ │           if (!currentTextObject) return;
 31 │ │           promise.finally(() =>
 32 │ │             objectStorageClient.text.update({ ...currentTextObject, text, updatedAt: Date.now() })
 33 │ │           );
 34 │ │         },
 35 │ │         WAIT_MS,
 36 │ │         { trailing: true }
 37 │ ╰─▶     ),
 38 │         [objectStorageClient, currentTextObject]
    ╰────
  help: Pass an inline function instead.

Interesting case, how should this be handled?

lol we do the same thing as react, only we're currently reporting on a different line so it wasn't being ignored

Screenshot 2024-11-12 at 08 54 34

@camc314
Copy link
Collaborator Author

camc314 commented Nov 12, 2024

@Boshen i guess we should be reporting the same (or at least very similar spans to react? if ok with you, i'll make an issue to track bits that aren't exactly complete for this rule

@Boshen
Copy link
Member

Boshen commented Nov 12, 2024

@Boshen i guess we should be reporting the same (or at least very similar spans to react? if ok with you, i'll make an issue to track bits that aren't exactly complete for this rule

Indeed, current span breaks already written eslint ignores.

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Nov 12, 2024
Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in #2637 !

still a draft. current state:

3x false positives (all todo with refs)

3x false negatives (TS will catch these
13x false negatvies todo with refs
1x false negative TODO

closes  #2637
relates to #2174
@graphite-app graphite-app bot merged commit 3dcac1a into main Nov 12, 2024
27 checks passed
@graphite-app graphite-app bot deleted the c/exhaustive-deps2 branch November 12, 2024 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-linter Area - Linter A-semantic Area - Semantic C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants