Files
nvim-config/lua/plugins/formatting.lua

72 lines
2.0 KiB
Lua

-- Formatting configuration with conform.nvim
-- Autoformat on save with per-filetype formatters
--
-- LazyVim owns format-on-save: it registers conform via LazyVim.format.register()
-- and triggers a BufWritePre autocmd gated on vim.g.autoformat / vim.b.autoformat.
-- Do NOT set format_on_save here - it bypasses that pipeline.
--
-- Controls:
-- :LazyFormat format current buffer now
-- <leader>cf format buffer (LazyVim default)
-- <leader>uf toggle autoformat for this buffer
-- <leader>uF toggle autoformat globally
--
-- Per-filetype skip is done from autocmd.lua via `vim.b.autofmrat = false`.
return {
{
"stevearc/conform.nvim",
opts = {
formatters_by_ft = {
-- Go
go = { "gofumpt", "goimports" },
-- Lua
lua = { "stylua" },
-- Javascript / Typescript
javascript = { "prettier" },
javascriptreact = { "prettier" },
typescript = { "prettier" },
typescriptreact = { "prettier" },
-- Web
html = { "prettier" },
css = { "prettier" },
scss = { "prettier" },
-- Data
json = { "prettier" },
jsonc = { "prettier" },
yaml = { "prettier" },
toml = { "prettier" },
-- Markdown
markdown = { "prettier" },
["markdown.mdx"] = { "prettier" },
-- SQL - manual format only, autoformat skipped in autocmds.lua
sql = { "sql_formatter" },
mysql = { "sql_formatter" },
plsql = { "sql_formatter" },
},
-- Per-formatter argument tweaks (merged with LazyVim defaults)
formatters = {
stylua = {
prepend_args = { "--indent-type", "Spaces", "--indent-width", "2" },
},
prettier = {
prepend_args = { "--tab-width", "2", "--single-quote" },
},
sql_formatter = {
prepend_args = { "--language", "postgresql" },
},
goimports = {
prepend_args = { "-local", "github.com" },
},
},
},
},
}