feat: use conform for easier formatting

This commit is contained in:
2025-11-12 09:03:02 +01:00
parent 6865b4f655
commit 755ec71e01

View File

@@ -18,6 +18,7 @@ vim.pack.add({
{ src = "https://github.com/neovim/nvim-lspconfig" }, { src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/sainnhe/everforest" }, { src = "https://github.com/sainnhe/everforest" },
{ src = "https://github.com/nvim-lualine/lualine.nvim" }, { src = "https://github.com/nvim-lualine/lualine.nvim" },
{ src = "https://github.com/stevearc/conform.nvim" },
-- autoclosing tags -- autoclosing tags
{ src = "https://github.com/windwp/nvim-ts-autotag" }, { src = "https://github.com/windwp/nvim-ts-autotag" },
@@ -267,29 +268,22 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end, end,
}) })
vim.api.nvim_create_autocmd('BufWritePost', { require("conform").setup({
desc = 'Autoformat code on safe with prettier', formatters_by_ft = {
pattern = '*.html', html = { "prettier" },
callback = function() },
local filepath = vim.fn.expand('%:p') default_format_opts = {
vim.fn.system({ 'npx', 'prettier', '--write', filepath }) lsp_format = "fallback",
vim.cmd('edit!') },
end,
}) })
vim.api.nvim_create_autocmd('BufWritePre', { vim.api.nvim_create_autocmd('BufWritePre', {
desc = 'Autoformat code on save with lsp', desc = 'Autoformat code on save',
pattern = '*', pattern = '*',
callback = function() callback = function(args)
local filetype = vim.bo.filetype require("conform").format({ bufnr = args.buf })
if filetype == "html" then
return
end
vim.lsp.buf.format({ async = false })
end, end,
}) })
vim.filetype.add({ extension = { templ = "templ" } }) vim.filetype.add({ extension = { templ = "templ" } })