Skip to content

🐛 False-positive noUnusedImports error when a variable has the same name as an imported type namespace #7516

@r4ai

Description

@r4ai

Environment information

CLI:
  Version:                      2.2.4
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  BIOME_THREADS:                unset
  NO_COLOR:                     unset
  TERM:                         xterm-256color
  JS_RUNTIME_VERSION:           v22.19.0
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         bun/1.2.22

Biome Configuration:
  Status:                       Loaded successfully
  Path:                         biome.jsonc
  Formatter enabled:            true
  Linter enabled:               true
  Assist enabled:               true
  VCS enabled:                  true

Workspace:
  Open Documents:               0

What happened?

A lint/correctness/noUnusedImports error is always triggered when I define a variable with the same name as an imported type namespace object.

Program that triggers the error

// lint/correctness/noUnusedImports: This import is unused.
import type * as hast from "hast"

const _ = () => {
  let hast: hast.Root
}

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB0AHkAcABlACAAKgAgAGEAcwAgAGgAYQBzAHQAIABmAHIAbwBtACAAIgBoAGEAcwB0ACIACgAKAGMAbwBuAHMAdAAgAF8AIAA9ACAAKAApACAAPQA%2BACAAewAKACAAIABsAGUAdAAgAGgAYQBzAHQAOgAgAGgAYQBzAHQALgBSAG8AbwB0AAoAfQA%3D

Program that does not trigger the error

This just changes the variable name to hoge from hast.

import type * as hast from "hast"

const _ = () => {
  let hoge: hast.Root 
}

https://biomejs.dev/playground/?code=aQBtAHAAbwByAHQAIAB0AHkAcABlACAAKgAgAGEAcwAgAGgAYQBzAHQAIABmAHIAbwBtACAAIgBoAGEAcwB0ACIACgAKAGMAbwBuAHMAdAAgAF8AIAA9ACAAKAApACAAPQA%2BACAAewAKACAAIABsAGUAdAAgAGgAbwBnAGUAOgAgAGgAYQBzAHQALgBSAG8AbwB0AAoAfQA%3D

Expected result

lint/correctness/noUnusedImports error should not be triggered.

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

Labels

A-LinterArea: linterL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions