neovim/lua/plugins/formatter.lua
2025-03-10 21:17:43 +01:00

93 lines
1.6 KiB
Lua

local function opts()
local util = require("formatter.util")
local prettier = {
exe = "prettier",
args = {
"--stdin-filepath",
util.escape_path(util.get_current_buffer_file_path()),
},
stdin = true,
try_node_modules = true,
}
return {
logging = true,
log_level = vim.log.levels.WARN,
filetype = {
lua = {
require("formatter.filetypes.lua").stylua,
},
rust = {
exe = "rustfmt",
args = { "--edition 2021" },
stdin = true,
},
qml = {
exe = "qmlformat",
args = { "--inplace" },
},
nix = {
require("formatter.filetypes.nix").nixfmt,
},
c = {
require("formatter.filetypes.c").clangformat,
},
cpp = {
require("formatter.filetypes.cpp").clangformat,
},
r = {
require("formatter.filetypes.r").styler,
},
python = {
require("formatter.filetypes.python").black,
},
json = {
prettier,
},
typescript = {
prettier,
},
javascript = {
prettier,
},
yaml = {
prettier,
},
css = {
prettier,
},
html = {
prettier,
},
scss = {
prettier,
},
fish = {
require("formatter.filetypes.fish").fishindent,
},
markdown = {
require("formatter.filetypes.markdown").prettier,
},
toml = {
require("formatter.filetypes.toml").taplo,
},
sh = {
require("formatter.filetypes.sh").shfmt,
},
typst = {
exe = "typstyle",
args = { "--inplace" },
},
["*"] = {
require("formatter.filetypes.any").remove_trailing_whitespace,
},
},
}
end
return {
"mhartington/formatter.nvim",
config = function()
require("formatter").setup(opts())
end,
}