biomejs/biome-vscode

๐Ÿ› Format on save lint fixes garble the file

Closed this issue ยท 1 comments

VS Code version

1.90.1

Extension version

2.3.0

Biome version

1.8.1

Operating system

  • Windows
  • macOS
  • Linux

Description

Format on save produces wrong output when multiple fixes for the same lint rule are applied to the same expression.

Steps to reproduce

  1. A biome.json config with linter enabled:
    // biome.json
    {
      "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
      "files": {
        "include": ["*.ts", "*.json"]
      },
      "formatter": {
        "enabled": false
      },
      "linter": {
        "enabled": true
      },
      "organizeImports": {
        "enabled": false
      }
    }
  2. Create a TS file where lint/complexity/useFlatMap fails multiple times on the same expression:
    // index.ts
    Object.values(rules.lints.languages)
      .map((l) => Object.values(l))
      .flat()
      .map((l) => Object.values(l))
      .flat();
  3. Configure VSCode to format on save:
    // .vscode/settings.json
    {
      "editor.formatOnSave": true,
      "editor.codeActionsOnSave": {
        "quickfix.biome": "explicit"
      },
      "[typescript]": {
        "editor.defaultFormatter": "biomejs.biome"
      }
    }
  4. Save the file and observe the wrong output:
    // index.ts
    Object.values(rules.lints.languages)
      .flatMap((l) => Object.values(l))
      .map((l) => Object.values(l))
      .flatMapt();

Expected behavior

Lint rule fixes to be correctly applied on save:

// index.ts
Object.values(rules.lints.languages)
  .flatMap((l) => Object.values(l))
  .flatMap((l) => Object.values(l));

Does this issue occur when using the CLI directly?

No

Logs

No response

I believe this is a duplicate of biomejs/biome#2268 and biomejs/biome#1570. Thanks for providing the example code.