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

馃悰 Format on save lint fixes garble the file #241

Closed
2 of 3 tasks
valeneiko opened this issue Jun 15, 2024 · 1 comment
Closed
2 of 3 tasks

馃悰 Format on save lint fixes garble the file #241

valeneiko opened this issue Jun 15, 2024 · 1 comment
Labels

Comments

@valeneiko
Copy link

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

@Sec-ant
Copy link
Member

Sec-ant commented Jun 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants