aboutsummaryrefslogtreecommitdiff
path: root/lua/gabrielgio/formatter.lua
blob: ca0ebc774d368ff618d64aae4d6c00f906fcb633 (plain)
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
34
35
36
37
38
39
local formatter = require("formatter")
local go = require("formatter.filetypes.go")
local util = require("formatter.util")

formatter.setup({
	filetype = {
		nix = { require("formatter.filetypes.nix").alejandra },
		lua = { require("formatter.filetypes.lua").stylua },
		fish = { require("formatter.filetypes.fish").fishindent },
		javascript = { require("formatter.filetypes.javascript").prettier },
		go = { go.gofumpt, go.goimports },
		terraform = {
			function()
				return {
					exe = "terraform",
					args = {
						"fmt",
						"-",
					},
					stdin = true,
				}
			end,
		},
		yaml = {
			function()
				return { exe = "yamlfmt" }
			end,
		},
	},
	["*"] = {
		require("formatter.filetypes.any").remove_trailing_whitespace,
	},
})

vim.api.nvim_create_augroup("__formatter__", { clear = true })
vim.api.nvim_create_autocmd("BufWritePost", {
	group = "__formatter__",
	command = ":FormatWrite",
})