dotfiles/.config/nvim/lua/brian/plugins/formatting.lua
2026-01-30 17:23:07 +02:00

53 lines
1.6 KiB
Lua

return {
'stevearc/conform.nvim',
event = { 'BufReadPre', 'BufNewFile' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>cf',
function()
require('conform').format { async = true, lsp_format = 'fallback' }
end,
mode = '',
desc = '[C]ode [F]ormat',
},
},
config = function()
local conform = require 'conform'
conform.setup {
formatters_by_ft = {
javascript = { 'prettierd', 'prettier', stop_after_first = true },
typescript = { 'prettierd', 'prettier', stop_after_first = true },
css = { 'prettierd', 'prettier', stop_after_first = true },
scss = { 'prettierd', 'prettier', stop_after_first = true },
json = { 'prettierd', 'prettier', stop_after_first = true },
yaml = { 'yamlfmt', 'prettierd', 'prettier', stop_after_first = true },
markdown = { 'cbfmt', 'prettierd', 'prettier', stop_after_first = true },
graphql = { 'prettierd', 'prettier', stop_after_first = true },
lua = { 'stylua' },
go = { 'goimports', 'ast_grep' },
rust = { 'ast_grep' },
python = { 'ruff', 'black' },
csharp = { 'csharpier' },
dockerfile = { 'hadolint' },
},
format_on_save = {
lsp_fallback = true,
async = false,
timeout_ms = 1000,
},
default_format_opts = {
lsp_format = 'fallback',
},
}
vim.keymap.set({ 'n', 'v' }, '<leader>mp', function()
conform.format {
lsp_fallback = true,
async = false,
timeout_ms = 1000,
}
end, { desc = '[M]ake [P]retty' })
end,
}