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(useExhaustiveDependencies): add option to disable errors for unecessary dependencies #4135

Conversation

simon-paris
Copy link
Contributor

@simon-paris simon-paris commented Sep 30, 2024

Closes #630

Summary

This adds an option to suppress errors for dependencies that are in the dependencies array but not used in the hook function.

The option schema is below. It could also have the new field inside the hooks array but I think you'd generally want to use this for every hook type.

// this config
"useExhaustiveDependencies": {
  "reportUnnecessaryDependencies": false,
  "hooks": [...] // unchanged
}

// allows this
function ReportUnecessaryDependencies() {
    const [a] = useState("hello")
    const [b] = useState("world");
    useEffect(() => {
        console.log(a); // <- prints when b changes, but does not use b
    }, [a, b]);
    return a;
}

Additionally, the options struct for this rule was originally designed to be reused, but at some point it was removed from useHookAtTopLevel here, now it's not actually reused anywhere. Since this PR adds an option field specific to this rule, I've renamed the options struct to indicate that it's non-reusable.

Test Plan

A unit test is included

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Sep 30, 2024
@simon-paris simon-paris changed the title feat: Add option to useExhaustiveDependencies to disable errors for unecessary dependencies feat(useExhaustiveDependencies): Add option to disable errors for unecessary dependencies Sep 30, 2024
@simon-paris simon-paris changed the title feat(useExhaustiveDependencies): Add option to disable errors for unecessary dependencies feat(useExhaustiveDependencies): add option to disable errors for unecessary dependencies Sep 30, 2024
@github-actions github-actions bot added the A-Project Area: project label Sep 30, 2024
Copy link

codspeed-hq bot commented Sep 30, 2024

CodSpeed Performance Report

Merging #4135 will not alter performance

Comparing simon-paris:feat/use-exhaustive-dependencies-disable-report-unused (d02c9ef) with main (a6ea07e)

Summary

✅ 105 untouched benchmarks

Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

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

Nice work! Just need to fix the defaults a bit.

@simon-paris
Copy link
Contributor Author

@arendjr Thanks, all fixed

@arendjr arendjr merged commit 10a1371 into biomejs:main Oct 1, 2024
12 checks passed
@arendjr
Copy link
Contributor

arendjr commented Oct 1, 2024

Just realized we forgot a CHANGELOG entry. Feel free to add it in the next PR or do a separate one.

@simon-paris simon-paris deleted the feat/use-exhaustive-dependencies-disable-report-unused branch October 1, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

📎 Break useExhaustiveDependencies into two rules
2 participants