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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 noUnusedImports still removes comments above the imports #5407

Closed
1 task done
fregante opened this issue Mar 21, 2025 · 4 comments · Fixed by #5468
Closed
1 task done

💅 noUnusedImports still removes comments above the imports #5407

fregante opened this issue Mar 21, 2025 · 4 comments · Fixed by #5468
Assignees
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

@fregante
Copy link

Environment information

CLI:
  Version:                      1.9.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.14.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.1.32"

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

Linter:
  JavaScript enabled:           true
  JSON enabled:                 true
  CSS enabled:                  true
  GraphQL enabled:              false
  Recommended:                  false
  All:                          false
  Enabled rules:
  style/useNodejsImportProtocol
  correctness/noUnusedImports
  style/useExportType
  style/useImportType

Workspace:
  Open Documents:               0

Rule name

noUnusedImports

Playground link

https://biomejs.dev/playground/?lintRules=all&analyzerFixMode=safeAndUnsafeFixes&code=LwAqAAoAIAAqACAAVABoAGkAcwAgAHAAcgBvAGcAcgBhAG0AIABpAHMAIABmAHIAZQBlACAAcwBvAGYAdAB3AGEAcgBlADoAIAB5AG8AdQAgAGMAYQBuACAAcgBlAGQAaQBzAHQAcgBpAGIAdQB0AGUAIABpAHQAIABhAG4AZAAvAG8AcgAgAG0AbwBkAGkAZgB5AAoAIAA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uAHMAZQAgAGYAbwByACAAbQBvAHIAZQAgAGQAZQB0AGEAaQBsAHMALgAKACAAKgAKACAAKgAgAFkAbwB1ACAAcwBoAG8AdQBsAGQAIABoAGEAdgBlACAAcgBlAGMAZQBpAHYAZQBkACAAYQAgAGMAbwBwAHkAIABvAGYAIAB0AGgAZQAgAEcATgBVACAAQQBmAGYAZQByAG8AIABHAGUAbgBlAHIAYQBsACAAUAB1AGIAbABpAGMAIABMAGkAYwBlAG4AcwBlAAoAIAAqACAAYQBsAG8AbgBnACAAdwBpAHQAaAAgAHQAaABpAHMAIABwAHIAbwBnAHIAYQBtAC4AIAAgAEkAZgAgAG4AbwB0ACwAIABzAGUAZQAgADwAaAB0AHQAcAA6AC8ALwB3AHcAdwAuAGcAbgB1AC4AbwByAGcALwBsAGkAYwBlAG4AcwBlAHMALwA%2BAC4ACgAgACoALwAKAAoAaQBtAHAAbwByAHQAIAB4ACAAZgByAG8AbQAgACIAagBxAHUAZQByAHkAIgA7AA%3D%3D

Expected result

The following file is emptied:

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import x from "jquery";

Same as bug #3401.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@fregante fregante added the S-Needs triage Status: this issue needs to be triaged label Mar 21, 2025
@dyc3
Copy link
Contributor

dyc3 commented Mar 21, 2025

This has already been fixed (as shown by the playground). The fix has not been released yet. You can try one of the nightly releases if you need the fix right away.

@dyc3 dyc3 closed this as completed Mar 21, 2025
@fregante
Copy link
Author

as shown by the playground

Shown where? The autofix suggests removing the entire block. This screenshot is from the playground:

Image

@fregante
Copy link
Author

fregante commented Mar 21, 2025

You can try one of the nightly releases if you need the fix right away.

Unfortunately I'm unable to use prereleases due to this bug:

@ematipico ematipico reopened this Mar 25, 2025
@ematipico ematipico 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 Mar 25, 2025
@github-actions github-actions bot removed the S-Needs triage Status: this issue needs to be triaged label Mar 25, 2025
@ematipico
Copy link
Member

As for the fix, I think we should follow the new import sorting revamp assumptions, and define the comment as a detached comment.

This comment should be placed as part of the new root in case the file becomes empty, or part of the next statement.

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

Successfully merging a pull request may close this issue.

3 participants