mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-21 16:39:06 +02:00
feat!: make conform.nvim
and nvim-lint
the default formatters/linters
This commit is contained in:
parent
70f91956e7
commit
14c091b1fc
13 changed files with 148 additions and 64 deletions
69
lua/lazyvim/plugins/formatting.lua
Normal file
69
lua/lazyvim/plugins/formatting.lua
Normal file
|
@ -0,0 +1,69 @@
|
|||
return {
|
||||
{
|
||||
"stevearc/conform.nvim",
|
||||
dependencies = { "mason.nvim" },
|
||||
lazy = true,
|
||||
cmd = "ConformInfo",
|
||||
keys = {
|
||||
{
|
||||
"<leader>cF",
|
||||
function()
|
||||
require("conform").format({ formatters = { "injected" } })
|
||||
end,
|
||||
mode = { "n", "v" },
|
||||
desc = "Format Injected Langs",
|
||||
},
|
||||
},
|
||||
init = function()
|
||||
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
||||
-- Install the conform formatter on VeryLazy
|
||||
require("lazyvim.util").on_very_lazy(function()
|
||||
require("lazyvim.util").format.register({
|
||||
name = "conform.nvim",
|
||||
priority = 100,
|
||||
primary = true,
|
||||
format = function(buf)
|
||||
require("conform").format({ bufnr = buf })
|
||||
end,
|
||||
sources = function(buf)
|
||||
local ret = require("conform").list_formatters(buf)
|
||||
return vim.tbl_map(function(v)
|
||||
return v.name
|
||||
end, ret)
|
||||
end,
|
||||
})
|
||||
end)
|
||||
end,
|
||||
opts = {
|
||||
formatters_by_ft = {
|
||||
lua = { "stylua" },
|
||||
fish = { "fish_indent" },
|
||||
sh = { "shfmt" },
|
||||
},
|
||||
-- LazyVim will merge the options you set here with builtin formatters.
|
||||
-- You can also define any custom formatters here.
|
||||
---@type table<string,table>
|
||||
formatters = {
|
||||
injected = { options = { ignore_errors = true } },
|
||||
-- -- Example of using dprint only when a dprint.json file is present
|
||||
-- dprint = {
|
||||
-- condition = function(ctx)
|
||||
-- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
|
||||
-- end,
|
||||
-- },
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
opts.formatters = opts.formatters or {}
|
||||
for name, formatter in pairs(opts.formatters) do
|
||||
if type(formatter) == "table" then
|
||||
local ok, defaults = pcall(require, "conform.formatters." .. name)
|
||||
if ok and type(defaults) == "table" then
|
||||
opts.formatters[name] = vim.tbl_deep_extend("force", {}, defaults, formatter)
|
||||
end
|
||||
end
|
||||
end
|
||||
require("conform").setup(opts)
|
||||
end,
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue