Skip to content

feature: easier configuration #138

@folke

Description

@folke

LazyVim uses conform.nvim for formatting.

To make configuration easier, we added some extra options to conform.nvim:

  • opts.format: default options used by require("conform").format()
  • opts.formatters: instead of just adding new formatters, you can also override the default options for any formatter
  • opts.formatters[NAME].extra_args: extra arguments passed to the formatter command.
    If you want to fully override the args, just use args instead of extra_args.

This all works as expected in LazyVim, but I believe these changes would benefit others as well.
Ideally, I also prefer not to deviate from a plugin's options.

Would you be open to accept a PR for this? If so I can create one.

Example

{
  -- LazyVim will use these options when formatting with the conform.nvim formatter
  format = {
    timeout_ms = 1000,
  },
  formatters_by_ft = {
    lua = { "stylua" },
    fish = { "fish_indent" },
    sh = { "shfmt" },
  },
  -- LazyVim will merge the options you set here with builtin formatters.
  -- You can also define any custom formatters here.
  ---@type table<string,table>
  formatters = {
    injected = { options = { ignore_errors = true } },
    -- # Example of using dprint only when a dprint.json file is present
    dprint = {
      condition = function(ctx)
        return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
      end,
    },
    --
    -- Example of using shfmt with extra args
    shfmt = {
      extra_args = { "-i", "2", "-ci" },
    },
  },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions