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/rich-parrots-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed #8499: `useExhaustiveDependencies` properly handles aliased destructured object keys when using `stableResult` configuration.
19 changes: 14 additions & 5 deletions crates/biome_js_analyze/src/react/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use biome_js_semantic::{Capture, Closure, ClosureExtensions, SemanticModel};
use biome_js_syntax::binding_ext::AnyJsBindingDeclaration;
use biome_js_syntax::{
AnyJsExpression, AnyJsMemberExpression, JsArrowFunctionExpression, JsCallExpression,
JsFunctionExpression, TextRange, binding_ext::AnyJsIdentifierBinding,
static_value::StaticValue,
JsFunctionExpression, JsObjectBindingPatternProperty, TextRange,
binding_ext::AnyJsIdentifierBinding, static_value::StaticValue,
};
use biome_js_syntax::{JsArrayBindingPatternElement, JsSyntaxToken};
use biome_rowan::AstNode;
Expand Down Expand Up @@ -272,9 +272,18 @@ pub fn is_binding_react_stable(
.map(|parent| parent.syntax().index() / 2)
.and_then(|index| index.try_into().ok());
let key = binding
.name_token()
.ok()
.map(|token| token.text_trimmed().to_string());
// Handle cases like const { foo: bar } = useSomething();
.parent::<JsObjectBindingPatternProperty>()
.and_then(|pattern_property| pattern_property.member().ok())
.and_then(|member| member.name())
.map(|name_token| name_token.to_string())
.or_else(|| {
// Handle the rest of the cases, i.e., var foo = useSomething();
binding
.name_token()
.ok()
.map(|token| token.text_trimmed().to_string())
});
let Some(callee) = declarator
.initializer()
.and_then(|initializer| initializer.expression().ok())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json",
"linter": {
"rules": {
"correctness": {
"useExhaustiveDependencies": {
"level": "error",
"options": {
"hooks": [
{
"name": "useStable",
"stableResult": [
"stable"
]
}
]
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect } from "react";

declare function useStable(): { stable: string };

export function SuccessComp() {
const { stable } = useStable();

useEffect(() => {
console.log(stable);
}, []);

return null;
}

export function FailedComp() {
const { stable: alias } = useStable();

// This error is a false positive as the value is still stable
useEffect(() => {
console.log(alias);
}, []);

return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 152
expression: issue8499.ts
---
# Input
```ts
import { useEffect } from "react";

declare function useStable(): { stable: string };

export function SuccessComp() {
const { stable } = useStable();

useEffect(() => {
console.log(stable);
}, []);

return null;
}

export function FailedComp() {
const { stable: alias } = useStable();

// This error is a false positive as the value is still stable
useEffect(() => {
console.log(alias);
}, []);

return null;
}

```