gabrielgio.lua @ 1434c1daf599f2703fd5951556283d4856127005

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