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

Fixed [#8967](https://github.com/biomejs/biome/issues/8967). [useExhaustiveDependencies](https://biomejs.dev/linter/rules/use-exhaustive-dependencies/) no longer reports false positives for variables destructured from a rest pattern.
Original file line number Diff line number Diff line change
Expand Up @@ -1003,13 +1003,14 @@ fn get_single_pattern_member(
.map(|member| {
(
array_pattern.syntax().clone(),
ReactHookResultMember::Index(member),
Some(ReactHookResultMember::Index(member)),
)
})
})
}),
JsSyntaxKind::JS_OBJECT_BINDING_PATTERN_PROPERTY
| JsSyntaxKind::JS_OBJECT_BINDING_PATTERN_SHORTHAND_PROPERTY => {
| JsSyntaxKind::JS_OBJECT_BINDING_PATTERN_SHORTHAND_PROPERTY
| JsSyntaxKind::JS_OBJECT_BINDING_PATTERN_REST => {
let Some(object_pattern) = parent_syntax
.parent()
.and_then(JsObjectBindingPatternPropertyList::cast)
Expand All @@ -1019,27 +1020,41 @@ fn get_single_pattern_member(
else {
return GetSinglePatternMemberResult::Unknown;
};
let Some(member) = (match AnyJsObjectBindingPatternMember::try_cast(parent_syntax) {
Ok(AnyJsObjectBindingPatternMember::JsObjectBindingPatternProperty(property)) => {
property
if matches!(
parent_syntax.kind(),
JsSyntaxKind::JS_OBJECT_BINDING_PATTERN_REST
) {
Some((object_pattern.syntax().clone(), None))
} else if let Some(member) =
match AnyJsObjectBindingPatternMember::try_cast(parent_syntax) {
Ok(AnyJsObjectBindingPatternMember::JsObjectBindingPatternProperty(
property,
)) => property
.member()
.ok()
.and_then(|member| member.name())
.map(ReactHookResultMember::Key)
.map(ReactHookResultMember::Key),
Ok(
AnyJsObjectBindingPatternMember::JsObjectBindingPatternShorthandProperty(
shorthand_property,
),
) => shorthand_property
.identifier()
.ok()
.and_then(|identifier| {
identifier.as_js_identifier_binding()?.name_token().ok()
})
.map(|name_token| {
ReactHookResultMember::Key(name_token.token_text_trimmed())
}),
// Shouldn't happen because of the previous check
_ => None,
}
Ok(AnyJsObjectBindingPatternMember::JsObjectBindingPatternShorthandProperty(
shorthand_property,
)) => shorthand_property
.identifier()
.ok()
.and_then(|identifier| identifier.as_js_identifier_binding()?.name_token().ok())
.map(|name_token| ReactHookResultMember::Key(name_token.token_text_trimmed())),
// Shouldn't happen because of the previous check
_ => None,
}) else {
{
Some((object_pattern.syntax().clone(), Some(member)))
} else {
return GetSinglePatternMemberResult::Unknown;
};
Some((object_pattern.syntax().clone(), member))
}
}
JsSyntaxKind::JS_VARIABLE_DECLARATOR => {
return GetSinglePatternMemberResult::NoPattern;
Expand All @@ -1054,7 +1069,10 @@ fn get_single_pattern_member(
{
return GetSinglePatternMemberResult::TooDeep;
}
GetSinglePatternMemberResult::Member(member)
match member {
Some(member) => GetSinglePatternMemberResult::Member(member),
None => GetSinglePatternMemberResult::NoPattern,
}
}

enum GetSinglePatternMemberResult {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* should not generate diagnostics */

import { useEffect } from "react";

// Issue #8967: Rest pattern destructuring should not cause false positives
function Component(props) {
const { data, ...restProps } = props;
const { prop1 } = restProps;

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

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

return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
assertion_line: 152
expression: issue8967.js
---
# Input
```js
/* should not generate diagnostics */

import { useEffect } from "react";

// Issue #8967: Rest pattern destructuring should not cause false positives
function Component(props) {
const { data, ...restProps } = props;
const { prop1 } = restProps;

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

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

return null;
}

```