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

feat: biome organize imports #599

Merged
merged 3 commits into from
Dec 24, 2024

Conversation

igorlfs
Copy link
Contributor

@igorlfs igorlfs commented Dec 17, 2024

Hello!

This PR adds another biome formatter, to only organize imports (in a similar manner to ruff, with ruff's organize-imports).

The major reason for another formatter is that there are some known limitations when using biome's regular formatter with HTML super languages, such as Svelte and Vue.

@igorlfs
Copy link
Contributor Author

igorlfs commented Dec 19, 2024

Uh, I just realized I can achieve the same result by disabling formatting, inside Biome's configuration. Specifically, here's the snippet for my use case (Svelte):

"formatter": {
        "enabled": true,
        "ignore": [
            "**/*.svelte",
        ]
    }

Coupled with the biome-check formatter, this only organizes imports.

I was considering closing this PR, but I noticed it was mentioned elsewhere, and it would close #585 (I guess)

cc @andrew-t-james-core @rahulpeacock

igorlfs added a commit to igorlfs/dotfiles that referenced this pull request Dec 19, 2024
Biome currently doesn't support proper formatting for HTML-like
languages, such as Svelte. However, it can already be used to sort
imports. So, an additional formatter is still necessary to actually
format the rest of the file.

To handle this situation gracefully, we need to disable formatting for
svelte files within the Biome configuration. This restricts the
biome-check formatter to only sort imports.

See stevearc/conform.nvim#599

To run the actual formatter, the LSP needs to format either before or
after biome-check. Arbitrarily, I chose the LSP to run before, by using
`lsp_format = "first"`.

The last step is to enable handle LSP formatting within the
`format_on_save` function, which needs to match the behavior of
formatting before biome-check.
@stevearc
Copy link
Owner

How would you expect this formatter to be used, and is the use case different from the biome-check formatter?

@igorlfs
Copy link
Contributor Author

igorlfs commented Dec 23, 2024

How would you expect this formatter to be used, and is the use case different from the biome-check formatter?

biome-check is used for formatting and sorting imports. However, in some situations (e.g., using a language such as Svelte), formatting has some limitations that make it not so useful (see OP). To handle this situation, one can either configure biome to NOT format such files (but sort their imports), or we could provide this additional formatter, so users don't need to manually configure biome.

@stevearc
Copy link
Owner

Sounds reasonable to me. Thanks for the PR!

@stevearc stevearc merged commit 06804af into stevearc:master Dec 24, 2024
7 checks passed
@igorlfs igorlfs deleted the feat/biome-sort-imports branch December 24, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants