Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Biome CLI and VSCode extension disagree on noUnusedVariables #2767

Open
1 task done
MCFX2 opened this issue May 8, 2024 · 1 comment
Open
1 task done

馃悰 Biome CLI and VSCode extension disagree on noUnusedVariables #2767

MCFX2 opened this issue May 8, 2024 · 1 comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@MCFX2
Copy link

MCFX2 commented May 8, 2024

Environment information

CLI:
  Version:                      1.7.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.12.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "yarn/4.1.1"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Workspace:
  Open Documents:               0

What happened?

  1. Created a project using Vite
  2. Edited vite-env.d.ts to define an ImportMeta (which is used for type-safe env configs)
interface ImportMetaEnv {
	// ... imagine there are fields here, contents not relevant
}

interface ImportMeta {
	readonly env: ImportMetaEnv;
}
  1. Open file in VSCode, and additionally run biome check, and compare the results.
  2. VSCode claims this is an error as the interface is unused, while biome check finds no issues.
    a. Also, this warning cannot be suppressed, because it hides the warning in VSCode but triggers a suppressions/unused warning on biome check.

Expected result

Either both will issue an incorrect noUnusedVariables warning, because the ImportMeta interface is not exported (and thus not used), or both will be fine with it. The actual fix in this case is to simply export the interface, but it's concerning that I would get a warning in one scenario but not the other.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@Sec-ant
Copy link
Contributor

Sec-ant commented May 9, 2024

I can reproduce this issue.

According to the TypeScript document:

Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope (and therefore to modules as well).

I think the correct behavior is to ignore any unused type declarations in such files because the moment they are defined, they can be accessed from the global in other files directly, or via /// <reference types="xxx" />.

To be more sepecific, type declarations should be ignored by this rule when:

  • The file ends with .d.ts
  • The file doesn't contain top-level imports or exports

@Sec-ant Sec-ant added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests

2 participants