dotfiles/nvim/lua/plugins/41-autoformat.lua
2025-11-10 15:18:32 -06:00

47 lines
1017 B
Lua

return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
"<leader>lf",
function()
require("conform").format({ async = true, lsp_format = "fallback" })
end,
mode = "",
desc = "[l]sp: [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" },
html = { "prettierd" },
javascript = { "prettierd" },
json = { "fixjson" },
lua = { "stylua" },
markdown = { "prettierd" },
ruby = { "rubocop" },
rust = { "rustfmt" },
sh = { "shellharden" },
swift = { "swiftformat" },
terraform = { "terraform_fmt" },
xml = { "xmllint" },
yaml = { "prettierd" },
},
formatters = {},
},
}