Skip to content

Commit

Permalink
fix(analyze/js): fix some imports not being detected
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Nov 19, 2024
1 parent 6b18387 commit 389c0bc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- [noMisleadingCharacterClass](https://biomejs.dev/linter/rules/no-misleading-character-class/) no longer panics on malformed escape sequences that end with a multi-byte character ([#4587](https://github.com/biomejs/biome/issues/4587)). Contributed by @Conaclos

- Fixed a panic related to bogus import statements in `useExhaustiveDependencies` ([#4568](https://github.com/biomejs/biome/issues/4568)) Contributed by @dyc3

### Parser

#### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,18 +597,14 @@ fn capture_needs_to_be_in_the_dependency_list(
| AnyJsBindingDeclaration::JsArrayBindingPatternRestElement(_)
| AnyJsBindingDeclaration::JsObjectBindingPatternProperty(_)
| AnyJsBindingDeclaration::JsObjectBindingPatternRest(_)
| AnyJsBindingDeclaration::JsObjectBindingPatternShorthandProperty(_) => {
unreachable!("The declaration should be resolved to its prent declaration")
}
| AnyJsBindingDeclaration::JsObjectBindingPatternShorthandProperty(_) => true,

// This should be unreachable because of the test if the capture is imported
AnyJsBindingDeclaration::JsShorthandNamedImportSpecifier(_)
| AnyJsBindingDeclaration::JsNamedImportSpecifier(_)
| AnyJsBindingDeclaration::JsBogusNamedImportSpecifier(_)
| AnyJsBindingDeclaration::JsDefaultImportSpecifier(_)
| AnyJsBindingDeclaration::JsNamespaceImportSpecifier(_) => {
unreachable!()
}
| AnyJsBindingDeclaration::JsNamespaceImportSpecifier(_) => false,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type {Point} fom '.geomet';
import {useEffect, seRef} 'react';

xpor function ueCanvasn(
) {
useEffect( => {on late Point},[c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: issue4568.js
---
# Input
```jsx
import type {Point} fom '.geomet';
import {useEffect, seRef} 'react';

xpor function ueCanvasn(
) {
useEffect( => {on late Point},[c

```
# Diagnostics
```
issue4568.js:6:3 lint/correctness/useExhaustiveDependencies ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! This hook specifies more dependencies than necessary: c

4 │ xpor function ueCanvasn(
5 │ ) {
> 6useEffect( => {on late Point},[c
^^^^^^^^^
7

i This dependency can be removed from the list.

4 │ xpor function ueCanvasn(
5 │ ) {
> 6useEffect( => {on late Point},[c
^
7


```
10 changes: 8 additions & 2 deletions crates/biome_js_semantic/src/semantic_model/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ use biome_js_syntax::{
use biome_rowan::AstNode;

pub(crate) fn is_imported(node: &JsSyntaxNode) -> bool {
node.ancestors()
.any(|x| matches!(x.kind(), JsSyntaxKind::JS_IMPORT))
node.ancestors().any(|x| {
matches!(
x.kind(),
JsSyntaxKind::JS_IMPORT
| JsSyntaxKind::JS_NAMED_IMPORT_SPECIFIERS
| JsSyntaxKind::JS_DEFAULT_IMPORT_SPECIFIER
)
})
}

/// Marker trait that groups all "AstNode" that can be imported or
Expand Down

0 comments on commit 389c0bc

Please sign in to comment.