Thanks to visit codestin.com
Credit goes to github.com

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
36 changes: 36 additions & 0 deletions .changeset/old-seas-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
"@biomejs/biome": patch
---

[`useExhaustiveDependencies`](https://biomejs.dev/linter/rules/use-exhaustive-dependencies) now correctly validate custom hooks whose dependency arrays come before their callbacks.

Previously, a logical error caused the rule to be unable to detect dependency arrays placed before hook callbacks, producing spurious errors and blocking further diagnostics.
```json
{
"linter": {
"rules": {
"correctness": {
"useExhaustiveDependencies": {
"level": "error",
"options": {
"hooks": [
{ "name": "doSomething", "closureIndex": 2, "dependenciesIndex": 0 }
]
}
}
}
}
}
}
```

```js
function component() {
let thing = 5;
// The rule will now correctly recognize `thing` as being specified
// instead of erroring due to "missing" dependency arrays
doSomething([thing], "blah", () => {console.log(thing)})
}
```

The rule documentation & diagnostic messages have also been reworked for improved clarity.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test.jsx:6:11 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━
```block
test.jsx:6:20 lint/correctness/useExhaustiveDependencies FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× This hook specifies more dependencies than necessary: local
× This hook specifies more dependencies than necessary: local.

4 │ function Component2() {
5 │ const [local,SetLocal] = useState(0);
Expand All @@ -139,6 +139,10 @@ test.jsx:6:20 lint/correctness/useExhaustiveDependencies FIXABLE ━━━━
9 │ }
10 │

i React relies on hook dependencies to determine when to re-compute Effects.
Specifying more dependencies than required can lead to unnecessary re-rendering
and degraded performance.

i Unsafe fix: Remove the extra dependencies from the list.

8 │ ····},·[local,·local]);
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_configuration/src/analyzer/linter/rules.rs

Large diffs are not rendered by default.

Loading