Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/deep-women-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#7813](https://github.com/biomejs/biome/issues/7813): improved the diagnostic of the rule [`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/). The diagnostic now shows the name of the variable to add to the dependency array.
Original file line number Diff line number Diff line change
Expand Up @@ -1627,11 +1627,12 @@ impl Rule for UseExhaustiveDependencies {

let message = match state {
Fix::AddDependency {
captures: (_, captures),
captures,
dependencies_array,
..
} => {
let new_elements = captures.first().into_iter().filter_map(|node| {
let (capture_text, captures_range) = captures;
let new_elements = captures_range.first().into_iter().filter_map(|node| {
if let Some(jsx_ref) = JsxReferenceIdentifier::cast_ref(node) {
return Some(AnyJsArrayElement::AnyJsExpression(
make::js_identifier_expression(make::js_reference_identifier(
Expand Down Expand Up @@ -1662,7 +1663,7 @@ impl Rule for UseExhaustiveDependencies {
recreate_array(dependencies_array, elements),
);

markup! { "Add the missing dependency to the list." }
markup! { "Add the missing dependency "<Emphasis>{capture_text.as_ref()}</Emphasis>" to the list." }
}
Fix::RemoveDependency {
dependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ customHook.ts:14:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency a to the list.

16 │ ····},·[a]);
│ +
Expand Down Expand Up @@ -200,7 +200,7 @@ customHook.ts:46:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency a to the list.

46 │ ····useEvenMoreEffect([],·["foo",·a],·()·=>·{
│ +++
Expand Down Expand Up @@ -232,7 +232,7 @@ customHook.ts:46:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency b to the list.

46 │ ····useEvenMoreEffect([],·["foo",·b],·()·=>·{
│ +++
Expand Down Expand Up @@ -348,7 +348,7 @@ customHook.ts:61:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency a to the list.

61 │ ····doSomething([a],·"apple",·()·=>·{
│ +
Expand Down Expand Up @@ -382,7 +382,7 @@ customHook.ts:61:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency b to the list.

61 │ ····doSomething([b],·"apple",·()·=>·{
│ +
Expand Down Expand Up @@ -414,7 +414,7 @@ customHook.ts:64:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency a to the list.

64 │ ····doSomething(["a·b",·a],·[a],·()·=>·{
│ +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ extraDependenciesInvalid.js:28:3 lint/correctness/useExhaustiveDependencies FIX
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency someObj to the list.

30 │ ··},·[someObj.id,·someObj]);
│ +++++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ignoredDependencies.js:8:5 lint/correctness/useExhaustiveDependencies FIXABLE

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency a to the list.

10 │ ····},·[a]);
│ +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ issue1931.js:9:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency calc to the list.

13 │ ····},·[calc]);
│ ++++
Expand Down Expand Up @@ -95,7 +95,7 @@ issue1931.js:21:19 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency calc to the list.

25 │ ····},·[calc]);
│ ++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ issue3080.ts:5:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency bar to the list.

8 │ ····},·[bar]);
│ +++
Expand Down Expand Up @@ -86,7 +86,7 @@ issue3080.ts:5:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency foo to the list.

8 │ ····},·[foo]);
│ +++
Expand Down Expand Up @@ -119,7 +119,7 @@ issue3080.ts:16:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency bar to the list.

16 │ ····useEffect(myEffect,·[bar]);
│ +++
Expand Down Expand Up @@ -151,7 +151,7 @@ issue3080.ts:16:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency foo to the list.

16 │ ····useEffect(myEffect,·[foo]);
│ +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ issue3512.js:18:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency y to the list.

20 │ ····},·[x,·y]);
│ +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ issue5914.js:14:16 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency varA to the list.

14 │ ········varB·=·useMemo(()·=>·varA,·[varA])
│ ++++
Expand Down Expand Up @@ -97,7 +97,7 @@ issue5914.js:26:18 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency varA to the list.

26 │ ····const·varB·=·useMemo(()·=>·varA,·[varA]);
│ ++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ issue6278.js:4:8 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency myFn to the list.

7 │ → },·[myFn]);
│ ++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ issue6893.js:5:8 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency firstId to the list.

7 │ → },·[firstId])
│ +++++++
Expand Down Expand Up @@ -75,7 +75,7 @@ issue6893.js:5:8 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency secondId to the list.

7 │ → },·[secondId])
│ ++++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ issue7982.ts:8:26 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency count to the list.

10 │ ····},·[count]);
│ +++++
Expand Down Expand Up @@ -90,7 +90,7 @@ issue7982.ts:13:27 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency count to the list.

17 │ ········[count],
│ +++++
Expand Down Expand Up @@ -123,7 +123,7 @@ issue7982.ts:20:35 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency count to the list.

22 │ ····},·[count])·as·Function;
│ +++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ issue8427.js:6:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency fe to the list.

8 │ ····},·[id,·fe]);
│ ++++
Expand Down Expand Up @@ -99,7 +99,7 @@ issue8427.js:13:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━
Failing to specify dependencies can result in Effects not updating correctly when state changes.
These "stale closures" are a common source of surprising bugs.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency fetchEntity to the list.

15 │ ····},·[id,·fetchEntity])
│ +++++++++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ issue8802.ts:17:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency props.value to the list.

19 │ ····},·[props.value]);
│ +++++++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ issue8883.tsx:18:5 lint/correctness/useExhaustiveDependencies FIXABLE ━━

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency msg to the list.

18 │ ····useEffect(()·=>·console.log(msg),·[msg]);·//·should·trigger·useExhaustiveDependencies
│ +++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ issue8907Reassigned.js:8:3 lint/correctness/useExhaustiveDependencies FIXABLE

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency setA to the list.

10 │ ··},·[setA]);
│ ++++
Expand Down Expand Up @@ -88,7 +88,7 @@ issue8907Reassigned.js:18:3 lint/correctness/useExhaustiveDependencies FIXABLE

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency b.current to the list.

20 │ ··},·[b.current]);
│ +++++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jsxDependencies.jsx:8:22 lint/correctness/useExhaustiveDependencies FIXABLE

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency Sub to the list.

8 │ ··const·renderItem·=·useCallback(()·=>·<Sub·/>,·[Sub·])
│ ++++
Expand Down Expand Up @@ -94,7 +94,7 @@ jsxDependencies.jsx:28:22 lint/correctness/useExhaustiveDependencies FIXABLE

i Either include it or remove the dependency array.

i Unsafe fix: Add the missing dependency to the list.
i Unsafe fix: Add the missing dependency LocalSub to the list.

28 │ ····const·memoized·=·useCallback(()·=>·<LocalSub·/>,·[LocalSub·]);
│ +++++++++
Expand Down
Loading
Loading