Skip to content

🐛 useSortedKeys issues with in-line comments #6491

@baenio

Description

@baenio

Environment information

CLI:
  Version:                      2.0.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

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:           v20.18.1
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         npm/11.4.2

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

Workspace:
  Open Documents:               0

Expected result

When turning useSortedKeys on and setting it for vscode to apply on save I got multiple issues with in-line comments, while the keys are being sorted:

  1. Inside of biome.jsonc the in-line comments gets removed completely, if the keys inside of an object can be sorted and I save the file - even tho the key/value doesn't move
// before
"correctness": {
  "noNodejsModules": "off", // TODO: Apply later
  "noUndeclaredVariables": { "level": "on", "options": { "checkTypes": true } },
  "noUndeclaredDependencies": "on",
  "noUnusedImports": { "fix": "safe", "level": "on" },
  "useExhaustiveDependencies": "off"
},

// after
"correctness": {
  "noNodejsModules": "off",
  "noUndeclaredDependencies": "on",
  "noUndeclaredVariables": { "level": "on", "options": { "checkTypes": true } },
  "noUnusedImports": { "fix": "safe", "level": "on" },
  "useExhaustiveDependencies": "off"
},
  1. In a javascript file the in-line comment stays at the old position and doesn't move with the key/value on the same line
// before
const foo = {
  a: 1,
  c: 3,
  b: 2, // This is b
};

// after
const foo = {
  a: 1,
  b: 2,
  c: 3, // This is b
};

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

Labels

A-AnalyzerArea: analyzerL-JSONLanguage: JSON and super languagesL-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