stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.72k stars 142 forks source link

bug: Can't pass options into formatters inside of lazygit #366

Closed akmalsoliev closed 3 months ago

akmalsoliev commented 4 months ago

Neovim version (nvim -v)

5.6.0

Operating system/version

MacOS 14.4.1

Add the debug logs

Log file

Formatters for this buffer:
LSP: lua_ls
stylua ready (lua) /Users/usr1/.local/share/nvim/mason/bin/stylua

Describe the bug

Inability to enforce indentantation width and using spaces or tabs with stylua

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

Use the lazyvim init

Expected Behavior

2 spaces for an indent

Minimal example file

No response

Minimal init.lua

return { -- Autoformat
    "stevearc/conform.nvim",
    keys = {
        {
            "<leader>f",
            '<CMD>lua require("conform").format({ timeout_ms = 3000 })<CR>',
            mode = { "n", "v" },
            desc = "[F]ormat file",
        },
    },
    opts = {
        notify_on_error = true,
        format_on_save = {
            timeout_ms = 500,
            lsp_fallback = true,
        },
        formatters_by_ft = {
            lua = { "stylua" },
            python = { "ruff_fix", "ruff_format" },
            rust = { "rustfmt" },
            bash = { "beautysh" },
            sql = { "sqlfluff" },
            json = { "prettier" },
            ["*"] = { "trim_whitespace" },
        },
        formatters = {
            stylua = {
                options = {
                    indent_width = 2,
                    indent_type = "Tabs",
                },
            },
            rustfmt = {
                options = {
                    autosave = 1,
                },
            },
        },
    },
}


### Additional context

_No response_
akmalsoliev commented 3 months ago

msyavuz commented 3 months ago

I don't think it works that way. You can customize default values of formatters but the option field is only present in these three. You can create a default stylua.toml and put options there then point stylua to it with --config-path argument.

akmalsoliev commented 3 months ago

Merhaba @msyavuz, thanks so much for your reply, I will def give it a try and get back to you.

akmalsoliev commented 3 months ago

@msyavuz I finally got around this issue, thanks so much it works like a charm! Teşekkürler!!!

Fix:

return { -- Autoformat
  "stevearc/conform.nvim",
  keys = {
    {
      "<leader>f",
      '<CMD>lua require("conform").format({ timeout_ms = 3000 })<CR>',
      mode = { "n", "v" },
      desc = "[F]ormat file",
    },
  },
  opts = {
    notify_on_error = true,
    format_on_save = {
      timeout_ms = 500,
      lsp_fallback = true,
    },
    formatters_by_ft = {
      lua = { "stylua" },
      python = { "ruff_fix", "ruff_format" },
      rust = { "rustfmt" },
      bash = { "beautysh" },
      sql = { "sqlfluff" },
      json = { "prettier" },
      ["*"] = { "trim_whitespace" },
    },
  },
  formatters = {
    stylua = {
      args = { "--config-path", "~/.config/stylua/stylua.toml" },
    },
    rustfmt = {
      autosave = 1,
    },
  },
}

My stylua.toml:

➤ cat ~/.config/stylua/stylua.toml
indent_width = 2
indent_type = "Spaces"