nvim-config/lua/configs/formatter.lua
2024-03-19 17:47:26 -07:00

38 lines
972 B
Lua

local function config()
local formatter = require('formatter')
local prettierd = require('formatter.defaults.prettierd')
local fmt_lua = require('formatter.filetypes.lua')
local fmt_json = require('formatter.filetypes.json')
local fmt_python = require('formatter.filetypes.python')
formatter.setup({
filetype = {
-- sudo pacman -S stylua
-- https://github.com/JohnnyMorganz/StyLua/releases
lua = { fmt_lua.stylua },
-- pip install isort black
-- TODO: ruff format, depending on the project
python = {
fmt_python.isort,
fmt_python.black,
},
-- sudo npm i -g fixjson
json = { fmt_json.fixjson },
-- npm i prettierd
typescript = { prettierd },
typescriptreact = { prettierd },
scss = { prettierd },
},
})
-- format on write
vim.api.nvim_create_augroup('__formatter__', { clear = true })
vim.api.nvim_create_autocmd('BufWritePost', {
group = '__formatter__',
command = ':FormatWrite',
})
end
return config