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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃搸 useExhaustiveDependencies - Implement Configurable Stable Hooks in biome.json #1128

Closed
TakaoNarikawa opened this issue Dec 9, 2023 · 4 comments
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@TakaoNarikawa
Copy link

Description

I'm proposing an enhancement for the Biome linter, inspired by ESLint's handling of similar issues (Issue #16873). The key idea is to enable the specification of stable custom hooks in biome.json, akin to how React's useState is treated in dependency arrays. This feature aims to improve consistency and developer experience when working with various state management libraries like Recoil. For further background and discussion, you can refer to this discussion.

Background

The current use_exhaustive_dependencies rule in Biome does not differentiate between hooks that require their setter functions to be included in dependency arrays and those that do not. For example, with React's useState, we don't need to include the setter function in dependency arrays:

const [foo, setFoo] = useState(123);
const fn1 = useCallback(() => setFoo(234), []);

However, with similar hooks from other libraries, like useRecoilState from Recoil, the setter must be included:

const [bar, setBar] = useRecoilState(barAtom);
const fn2 = useCallback(() => setBar(234), [setBar]); // setBar needs to be included

This inconsistency can lead to confusion and potential issues in dependency management.

Proposed Feature

The idea is to introduce a new configuration option in biome.json to designate specific hooks as stable. For example:

"useExhaustiveDependencies": {
  "level": "error",
  "options": {
    "hooks": [],
    "stableHooks": {
      "useRecoilState": true,
      "useResetRecoilState": [true, false]
    }
  }
}

In this configuration, useRecoilState would be treated as entirely stable, while useResetRecoilState would have its first index marked as stable and the second as not.

Technical Challenges and Request for Contribution

While I have made a preliminary attempt at this (Commit f0433f18), I must confess that my experience with Rust is quite limited. As a result, I am not in a position to commit these changes to the project myself. Therefore, I am seeking assistance from more experienced Rust developers in our community to help implement this feature.

@ematipico ematipico added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature labels Dec 12, 2023
@ematipico ematipico added the S-Help-wanted Status: you're familiar with the code base and want to help the project label Jan 14, 2024
@ematipico
Copy link
Member

Let's see if we can find someone that can help you.

However, I think you; should still send a PR with the deserialization of the new option, and we will take over from there. Doing so, you'll get an attribution for your work!

@arendjr
Copy link
Contributor

arendjr commented Jan 14, 2024

I鈥檓 interested in seeing this to completion, but it鈥檒l be at least a few weeks until I can pick this up, I expect, so don鈥檛 assign me just yet 馃槄

@arendjr
Copy link
Contributor

arendjr commented Mar 5, 2024

I'm going to work on this.

@ematipico
Copy link
Member

Closed by #1979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

No branches or pull requests

3 participants