summaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/shfmt.lua
blob: c736be8330124bddfec21f836190dcaac10fbb72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
---@type conform.FileFormatterConfig
return {
  meta = {
    url = "https://github.com/mvdan/sh",
    description = "A shell parser, formatter, and interpreter with `bash` support.",
  },
  command = "shfmt",
  args = function(_, ctx)
    local args = { "-filename", "$FILENAME" }
    local has_editorconfig = vim.fs.find(".editorconfig", { path = ctx.dirname, upward = true })[1]
      ~= nil
    -- If there is an editorconfig, don't pass any args because shfmt will apply settings from there
    -- when no command line args are passed.
    if not has_editorconfig and vim.bo[ctx.buf].expandtab then
      vim.list_extend(args, { "-i", ctx.shiftwidth })
    end
    return args
  end,
}