Skip to content

Commit 0d15370

Browse files
authored
fix(linter): useExhaustiveDependencies multiple fixes (fixes #3080, fixes #4248, fixes #5914, fixes #8427, fixes #8484, fixes #3685, fixes #3512, fixes #7982) (#8767)
1 parent 39eb545 commit 0d15370

28 files changed

+1658
-247
lines changed

.changeset/famous-ads-dance.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#3512](https://github.com/biomejs/biome/issues/3512):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly handles nested destructuring patterns
7+
from hook results.
8+
9+
```tsx
10+
const [[x, y], setXY] = useState([1, 2]);
11+
useEffect(() => {
12+
console.log(x, y);
13+
}, [x, y]); // x and y are now correctly recognized as unstable
14+
```

.changeset/forty-sloths-begin.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#3685](https://github.com/biomejs/biome/issues/3685):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly handles transparent expression
7+
wrappers like non-null assertions and type assertions in dependency comparisons.
8+
9+
```tsx
10+
useMemo(() => Boolean(myObj!.x), [myObj!.x]); // No longer reports incorrect diagnostics
11+
useMemo(() => myObj!.x?.y === true, [myObj!.x?.y]); // Now correctly matches dependencies
12+
```

.changeset/public-doodles-cut.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#5914](https://github.com/biomejs/biome/issues/5914):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly handles variables declared in the same
7+
statement.
8+
9+
```tsx
10+
const varA = Math.random(),
11+
varB = useMemo(() => varA, [varA]); // varA is now correctly recognized as needed
12+
```

.changeset/puny-eagles-hang.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8427](https://github.com/biomejs/biome/issues/8427):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly resolves variable references to detect
7+
captured dependencies.
8+
9+
```tsx
10+
const fe = fetchEntity;
11+
useEffect(() => {
12+
fe(id);
13+
}, [id, fe]); // fe is now correctly detected as needed
14+
```

.changeset/rare-things-spend.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8484](https://github.com/biomejs/biome/issues/8484):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly handles member access on stable hook
7+
results.
8+
9+
```tsx
10+
const stableObj = useStable();
11+
useMemo(() => {
12+
return stableObj.stableValue; // stableObj.stableValue is now correctly recognized as stable
13+
}, []);
14+
```

.changeset/rude-spies-feel.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7982](https://github.com/biomejs/biome/issues/7982):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly handles callback expressions with type
7+
assertions.
8+
9+
```tsx
10+
const callback = useCallback(
11+
(() => {
12+
return count * 2;
13+
}) as Function,
14+
[count], // count is now correctly detected
15+
);
16+
```

.changeset/short-chefs-switch.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#3080](https://github.com/biomejs/biome/issues/3080):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now properly analyzes captures within referenced
7+
functions passed to hooks.
8+
9+
```tsx
10+
function myEffect() {
11+
console.log(foo, bar);
12+
}
13+
useEffect(myEffect, [foo, bar]); // foo and bar are now correctly detected
14+
```

.changeset/tiny-owls-show.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#4248](https://github.com/biomejs/biome/issues/4248):
6+
[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) now correctly handles function props passed as
7+
callbacks.
8+
9+
```tsx
10+
const data = React.useMemo(getData, [getData]); // getData is now correctly recognized as needed
11+
```

0 commit comments

Comments
 (0)