summaryrefslogtreecommitdiff
path: root/lua/config/plugins/formatting.lua
blob: 6efe5d2545236d6990040a1ae0e1fe997eaf01ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
return {
	{
		"conform.nvim",
		event = "DeferredUIEnter",
		after = function(_)
			vim.opt.formatexpr = "v:lua.require'conform'.formatexpr()"

			require("conform").setup({
				formatters_by_ft = {
					lua = { "stylua" },
					nix = { "nixfmt" },
					rust = { "rustfmt", lsp_format = "fallback" },

					json = { "biome" },
					jsonc = { "biome" },
					javascript = { "biome" },
					javascriptreact = { "biome" },
					["javascript.jsx"] = { "biome" },
					typescript = { "biome" },
					typescriptreact = { "biome" },
					["typescript.jsx"] = { "biome" },
				},
			})

			vim.api.nvim_create_autocmd("BufWritePre", {
				pattern = "*",
				callback = function(args)
					require("conform").format({ bufnr = args.buf })
				end,
			})
		end,
	},
}