nvim-config/lua/configs/formatter.lua
2024-07-02 12:08:51 -07:00

39 lines
1003 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 ruff
python = {
fmt_python.isort,
-- TODO: black vs ruff based on cwd
fmt_python.black,
-- fmt_python.ruff,
},
-- 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