dotfiles/nvim/lua/config/lazy/41-autoformat.lua

50 lines
1.0 KiB
Lua

return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
"<leader>f",
function()
require("conform").format({ async = true, lsp_format = "fallback" })
end,
mode = "",
desc = "[F]ormat buffer",
},
},
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
local disable_filetypes = { c = true, cpp = true }
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
return {
timeout_ms = 2500,
lsp_format = "fallback",
}
end
end,
formatters_by_ft = {
go = { "goimports", "gofmt" },
hcl = { "terragrunt_hclfmt" },
javascript = { "prettierd" },
json = { "fixjson" },
lua = { "stylua" },
markdown = { "prettierd" },
ruby = { "rubocop" },
rust = { "rustfmt" },
sh = { "shellharden" },
swift = { "swiftlint" },
terraform = { "terraform_fmt" },
xml = { "xmllint" },
yaml = { "yamlfix" },
},
formatters = {
yamlfix = {
prepend_args = { "-c", ".yamlfix.toml" },
},
},
},
}