neovim-confs/lua/plex/plugins/extras/formatting/prettier.lua

85 lines
2.6 KiB
Lua
Raw Permalink Normal View History

2023-09-06 00:26:45 +02:00
-- This is part of LazyVim's code, with my modifications.
-- See: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/formatting/prettier.lua
2023-10-01 16:46:42 +02:00
local util = require("formatter.util")
local defaults = require("formatter.defaults")
2023-09-06 00:26:45 +02:00
return {
{
2023-09-15 11:49:26 +02:00
"williamboman/mason.nvim",
2023-09-06 00:26:45 +02:00
opts = function(_, opts)
2023-09-15 11:49:26 +02:00
if type(opts.ensure_installed) == "table" then
table.insert(opts.ensure_installed, "prettierd")
2023-09-06 00:26:45 +02:00
end
end,
},
{
2023-09-15 11:49:26 +02:00
"mhartington/formatter.nvim",
2023-09-06 00:26:45 +02:00
optional = true,
2023-09-15 11:49:26 +02:00
keys = {
{ "<Leader>ff", "<cmd>Format<CR>", desc = "Use Formatter" },
},
2023-09-06 00:26:45 +02:00
opts = function(_, opts)
opts = opts or {}
local filetypes = {
2023-10-01 22:41:11 +02:00
-- NOTE: If using this config, you need to install prettierd.
-- At the time of writing that is done with:
-- `sudo npm install -g @fsouza/prettierd`
["*"] = {
-- NOTE: This is not a fallback! It seems to overwrite any other
-- configs.
require("formatter.filetypes.any").remove_trailing_whitespace,
},
text = { require("formatter.defaults.prettierd") },
2024-01-11 09:45:37 +01:00
rust = { require("formatter.filetypes.rust").rustfmt },
2023-10-01 16:46:42 +02:00
cpp = { require("formatter.filetypes.cpp").clangformat },
css = { require("formatter.filetypes.css").prettierd },
2023-10-01 22:41:11 +02:00
html = { require("formatter.filetypes.html").prettierd },
htmldjango = {
2023-10-01 19:23:30 +02:00
function()
return {
exe = "djlint",
2023-10-01 22:41:11 +02:00
args = { "-", "--reformat" },
2023-10-01 19:23:30 +02:00
stdin = 1,
}
end,
},
2023-10-01 16:46:42 +02:00
java = { require("formatter.filetypes.java").clangformat() },
javascript = { require("formatter.filetypes.javascript").prettierd },
json = { require("formatter.filetypes.json").prettierd },
cmake = { require("formatter.filetypes.cmake") },
latex = { require("formatter.filetypes.latex").latexindent },
markdown = { require("formatter.filetypes.markdown").prettierd },
php = { require("formatter.filetypes.php").phpcbf },
2023-10-01 19:23:30 +02:00
python = {
function()
return {
exe = "autopep8",
args = { "--aggressive -" },
stdin = 1,
}
end,
},
2023-10-01 16:46:42 +02:00
sh = { require("formatter.filetypes.sh").shfmt() },
sql = { require("formatter.filetypes.sql").pgformat() },
toml = { require("formatter.filetypes.toml").taplo() },
go = { require("formatter.filetypes.go").gofmt() },
yaml = { require("formatter.filetypes.yaml").prettierd },
c = { require("formatter.filetypes.c").clangformat },
2023-09-06 00:26:45 +02:00
}
2023-09-15 11:49:26 +02:00
opts.filetype = vim.tbl_extend("keep", opts.filetype or {}, filetypes)
2023-09-06 00:26:45 +02:00
end,
},
{
2023-09-15 11:49:26 +02:00
"jose-elias-alvarez/null-ls.nvim",
2023-09-06 00:26:45 +02:00
optional = true,
opts = function(_, opts)
2023-09-15 11:49:26 +02:00
local nls = require("null-ls")
2023-09-06 00:26:45 +02:00
table.insert(opts.sources, nls.builtins.formatting.prettierd)
end,
},
}