nvim-config/lua/configs/formatter.lua
2024-03-20 21:52:01 -07:00

39 lines
996 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.ruff,
-- 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