nvim-config/lua/configs/formatter.lua

39 lines
996 B
Lua
Raw Normal View History

2024-03-20 00:47:26 +00:00
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,
2024-03-21 04:52:01 +00:00
fmt_python.ruff,
-- fmt_python.black,
2024-03-20 00:47:26 +00:00
},
-- 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