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 zig = { require("formatter.filetypes.zig").zigfmt },
38 typespec = { tspfmt },
39 },
40 ["*"] = {
41 require("formatter.filetypes.any").remove_trailing_whitespace,
42 },
43})
44
45local augroup = vim.api.nvim_create_augroup
46local autocmd = vim.api.nvim_create_autocmd
47
48augroup("__formatter__", { clear = true })
49autocmd("BufWritePost", {
50 group = "__formatter__",
51 command = ":FormatWrite",
52})