aboutsummaryrefslogtreecommitdiff
path: root/lua/gabrielgio/formatter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/gabrielgio/formatter.lua')
-rw-r--r--lua/gabrielgio/formatter.lua41
1 files changed, 22 insertions, 19 deletions
diff --git a/lua/gabrielgio/formatter.lua b/lua/gabrielgio/formatter.lua
index ca0ebc7..bf882bc 100644
--- a/lua/gabrielgio/formatter.lua
+++ b/lua/gabrielgio/formatter.lua
@@ -2,6 +2,21 @@ local formatter = require("formatter")
local go = require("formatter.filetypes.go")
local util = require("formatter.util")
+local function yamlfmt()
+ return { exe = "yamlfmt" }
+end
+
+local function terraformfmt()
+ return {
+ exe = "terraform",
+ args = {
+ "fmt",
+ "-",
+ },
+ stdin = true,
+ }
+end
+
formatter.setup({
filetype = {
nix = { require("formatter.filetypes.nix").alejandra },
@@ -9,31 +24,19 @@ formatter.setup({
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,
- },
+ terraform = { terraformfmt },
+ yaml = { yamlfmt },
},
["*"] = {
require("formatter.filetypes.any").remove_trailing_whitespace,
},
})
-vim.api.nvim_create_augroup("__formatter__", { clear = true })
-vim.api.nvim_create_autocmd("BufWritePost", {
+local augroup = vim.api.nvim_create_augroup
+local autocmd = vim.api.nvim_create_autocmd
+
+augroup("__formatter__", { clear = true })
+autocmd("BufWritePost", {
group = "__formatter__",
command = ":FormatWrite",
})