gabrielgio.lua @ 4b243dca91ff815d09081b2302c20dfce7a05599

 1local formatter = require("formatter")
 2local go = require("formatter.filetypes.go")
 3local util = require("formatter.util")
 4
 5local function yamlfmt()
 6	return { exe = "yamlfmt" }
 7end
 8
 9local function terraformfmt()
10	return {
11		exe = "terraform",
12		args = {
13			"fmt",
14			"-",
15		},
16		stdin = true,
17	}
18end
19
20formatter.setup({
21	filetype = {
22		nix = { require("formatter.filetypes.nix").alejandra },
23		lua = { require("formatter.filetypes.lua").stylua },
24		fish = { require("formatter.filetypes.fish").fishindent },
25		javascript = { require("formatter.filetypes.javascript").prettier },
26		css = { require("formatter.filetypes.css").cssbeautify },
27		scss = { require("formatter.filetypes.css").cssbeautify },
28		go = { go.gofumpt, go.goimports },
29		terraform = { terraformfmt },
30		yaml = { yamlfmt },
31	},
32	["*"] = {
33		require("formatter.filetypes.any").remove_trailing_whitespace,
34	},
35})
36
37local augroup = vim.api.nvim_create_augroup
38local autocmd = vim.api.nvim_create_autocmd
39
40augroup("__formatter__", { clear = true })
41autocmd("BufWritePost", {
42	group = "__formatter__",
43	command = ":FormatWrite",
44})