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

54 lines
1.2 KiB
Lua

-- 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
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
if type(opts.ensure_installed) == "table" then
table.insert(opts.ensure_installed, "prettierd")
end
end,
},
{
"mhartington/formatter.nvim",
optional = true,
keys = {
{ "<Leader>ff", "<cmd>Format<CR>", desc = "Use Formatter" },
},
opts = function(_, opts)
opts = opts or {}
local filetypes = {
-- FIXME:add more filetypes
json = { require("formatter.defaults.prettierd") },
rust = {
rustfmt = function()
return {
exe = "rustfmt",
args = { "--emit=std ut" },
stdin = true,
}
end,
},
["*"] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require("formatter.filetypes.any").remove_trailing_whitespace,
},
}
opts.filetype = vim.tbl_extend("keep", opts.filetype or {}, filetypes)
end,
},
{
"jose-elias-alvarez/null-ls.nvim",
optional = true,
opts = function(_, opts)
local nls = require("null-ls")
table.insert(opts.sources, nls.builtins.formatting.prettierd)
end,
},
}