Files
dotfiles_arch/nvim/.config/nvim/lua/plugins/conform.lua

83 lines
2.6 KiB
Lua

-- conform.lua: Automates code formatting on save or manual trigger.
return {
{
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("conform").setup({
formatters_by_ft = {
-- Lua
lua = { "stylua" },
-- JavaScript/TypeScript/Web
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
vue = { "prettier" },
css = { "prettier" },
scss = { "prettier" },
less = { "prettier" },
html = { "prettier" },
json = { "prettier" },
jsonc = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
graphql = { "prettier" },
handlebars = { "prettier" },
-- Toml
toml = { "taplo" }, -- Changed from tombi to taplo
-- KDL
kdl = { "kdlfmt" },
-- Ruby
ruby = { "rubocop" },
-- LaTeX
tex = { "tex-fmt" },
-- Python (ruff replaces black + isort)
python = { "ruff_format" }, -- Changed: consolidated to ruff
-- Bash/Shell
sh = { "shfmt" }, -- Changed: using shfmt instead of beautysh
bash = { "shfmt" }, -- Changed: using shfmt instead of beautysh
zsh = { "beautysh" }, -- Keep beautysh for zsh
},
-- Format on save
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
-- Formatter settings
formatters = {
stylua = {
prepend_args = { "--indent-type", "Spaces", "--indent-width", "2" },
},
prettier = {
prepend_args = { "--tab-width", "2" },
},
shfmt = {
prepend_args = { "-i", "2" }, -- 2 spaces for bash/sh
},
beautysh = {
prepend_args = { "--indent-size", "2" }, -- 2 spaces for zsh
},
},
})
-- Manual format keymap (same as your old <leader>gf)
vim.keymap.set("n", "<leader>gf", function()
require("conform").format({
lsp_fallback = true,
async = false,
timeout_ms = 1000,
})
end, { desc = "Format buffer" })
-- Optional: format on visual selection
vim.keymap.set("v", "<leader>gf", function()
require("conform").format({
lsp_fallback = true,
async = false,
timeout_ms = 1000,
})
end, { desc = "Format selection" })
end,
},
}