conform.nvim icon indicating copy to clipboard operation
conform.nvim copied to clipboard

feature request: Organize import using Biome.js for typescript, javascript, typescriptreact, javascriptreact

Open rahulpeacock opened this issue 1 year ago • 6 comments

Did you check existing requests?

  • [X] I have searched the existing issues

Describe the feature

I want to organize the imports using biome.js when I format my buffer/file using biome.js for typescript, javascript, typescriptreact, javascriptreact

Provide background

No response

What is the significance of this feature?

strongly desired

Additional details

For now I am using the args to organize the imports. But it is highly recommend to have a config to organize the imports using biome

This is a workaround for now

-- confirm.lua
return {
  {
    "stevearc/conform.nvim",
    opts = {
      formatters_by_ft = {
        lua = { "stylua" },
        ["javascript"] = { "biome" },
        ["javascriptreact"] = { "biome" },
        ["typescript"] = { "biome" },
        ["typescriptreact"] = { "biome" },
        ["json"] = { "biome" },
        ["css"] = { "biome" },
      },
      formatters = {
        biome = {
          command = "biome",
          args = { "check", "--formatter-enabled=true", "--linter-enabled=false", "--organize-imports-enabled=true", "--write", "--stdin-file-path", "$FILENAME" },
        },
      },
    },
  },
}

rahulpeacock avatar Nov 25 '24 13:11 rahulpeacock

According to the docs it looks like the formatter, linter, and import sorter are all enabled by default. The default conform biome formatter calls biome format. If you want to use biome check, use the biome-check formatter.

Also, to make changes to a formatter args, you can provide append_args or prepend_args instead of overriding the args entirely.

stevearc avatar Nov 25 '24 17:11 stevearc

@stevearc Yes I can pass args but I can't pass the arg --import-sort-enable to the biome format command because it doesn't support that arg

rahulpeacock avatar Nov 25 '24 17:11 rahulpeacock

@stevearc can you share any config with biome-check.

rahulpeacock avatar Nov 25 '24 17:11 rahulpeacock

@rahulpeacock I had some luck with this setup.

andrew-t-james-core avatar Nov 25 '24 18:11 andrew-t-james-core

@andrew-t-james-core this is also a workaround but is there a default config from conform ??

rahulpeacock avatar Nov 26 '24 01:11 rahulpeacock

Can you not just use the built-in biome-check formatter? It runs biome check which, from my understanding, will organize the imports

      formatters_by_ft = {
        lua = { "stylua" },
        ["javascript"] = { "biome-check" },
        ["javascriptreact"] = { "biome-check" },
        ["typescript"] = { "biome-check" },
        ["typescriptreact"] = { "biome-check" },
        ["json"] = { "biome-check" },
        ["css"] = { "biome-check" },
      },

stevearc avatar Nov 27 '24 20:11 stevearc

Can you not just use the built-in biome-check formatter? It runs biome check which, from my understanding, will organize the imports

  formatters_by_ft = {
    lua = { "stylua" },
    ["javascript"] = { "biome-check" },
    ["javascriptreact"] = { "biome-check" },
    ["typescript"] = { "biome-check" },
    ["typescriptreact"] = { "biome-check" },
    ["json"] = { "biome-check" },
    ["css"] = { "biome-check" },
  },

This works for me 🚀

work-in-progress-danny avatar May 10 '25 23:05 work-in-progress-danny

@stevearc would you be willing to accept updates to the biome formatters descriptions to explicitly call out the differences between biome, biome-check and biome-organize-imports?

It took me quite some time to understand that there were 3 separate builtin formatters that are all associated to biome and this seems to be a common issue.

gugahoi avatar Jul 02 '25 01:07 gugahoi

@gugahoi yeah if you want to clarify these formatters I would be happy to review it

stevearc avatar Jul 02 '25 15:07 stevearc

Can you not just use the built-in biome-check formatter? It runs biome check which, from my understanding, will organize the imports

  formatters_by_ft = {
    lua = { "stylua" },
    ["javascript"] = { "biome-check" },
    ["javascriptreact"] = { "biome-check" },
    ["typescript"] = { "biome-check" },
    ["typescriptreact"] = { "biome-check" },
    ["json"] = { "biome-check" },
    ["css"] = { "biome-check" },
  },

idk why biome-organize-imports not working but biome-check does work

KMohZaid avatar Jul 27 '25 08:07 KMohZaid