Skip to content

"Format on Paste" & "Format on Save Mode: Modification" Deletes Lines Incorrectly #2260

Open
@andrewaustin

Description

@andrewaustin

VS Code version

1.87.2

Extension version

2.2.2

Biome version

1.6.1

Operating system

  • Windows
  • macOS
  • Linux

Description

Spent a lot of time trying to track this down on discord, and was finally able to figure it out with the help of @Sec-ant

If your vscode settings are format on paste or are format mode: modification it seems that weird things happen. I assume this is because only small code fragments are being sent to biome instead of the full file, which biome does not support. See the repo case below.

To fix my issues I had to turn off both Format on Paste and the Format Save Mode to file

Steps to reproduce

This small snippet was enough to cause problems for me:

// let us set an empty customer
if (userJson.customer != undefined && userJson.customer !== null) {
  fakeItem.stripe_customer = { S: userJson.customer };
}

To recreate it you can just enable format on paste and then copy paste the comment let us set an empty customer and you'll see the if block deleted. If you want to test the format on modification mode, you can correct the biome issue (!= should be !==) and you'll also see the if block get deleted.

Expected behavior

Would expect the correct formatting.

Does this issue occur when using the CLI directly?

Not sure / Not applicable

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FormatterArea: formatterA-LSPArea: language server protocolS-Bug-confirmedStatus: report has been confirmed as a valid bugS-Help-wantedStatus: you're familiar with the code base and want to help the project

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions