mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-25 14:01:06 +00:00
fix(extras): Extend formatters/linters dynamically
This commit is contained in:
parent
68ff818a5b
commit
6de5b19a1b
9 changed files with 72 additions and 52 deletions
|
|
@ -17,10 +17,10 @@ return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
formatters_by_ft = {
|
opts.formatters_by_ft.python = opts.formatters_by_ft.python or {}
|
||||||
["python"] = { "black" },
|
table.insert(opts.formatters_by_ft.python, "black")
|
||||||
},
|
return opts
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,20 @@ return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
formatters_by_ft = {
|
--- Extend the conform plugin config and add given formatters
|
||||||
|
---@param tbl table<string, conform.FormatterUnit[]> Table of filetype to formatters mappings
|
||||||
|
local function add_formatters(tbl)
|
||||||
|
for ft, formatters in pairs(tbl) do
|
||||||
|
if opts.formatters_by_ft[ft] == nil then
|
||||||
|
opts.formatters_by_ft[ft] = formatters
|
||||||
|
else
|
||||||
|
vim.list_extend(opts.formatters_by_ft[ft], formatters)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
add_formatters({
|
||||||
["javascript"] = { "prettier" },
|
["javascript"] = { "prettier" },
|
||||||
["javascriptreact"] = { "prettier" },
|
["javascriptreact"] = { "prettier" },
|
||||||
["typescript"] = { "prettier" },
|
["typescript"] = { "prettier" },
|
||||||
|
|
@ -35,7 +47,7 @@ return {
|
||||||
["markdown.mdx"] = { "prettier" },
|
["markdown.mdx"] = { "prettier" },
|
||||||
["graphql"] = { "prettier" },
|
["graphql"] = { "prettier" },
|
||||||
["handlebars"] = { "prettier" },
|
["handlebars"] = { "prettier" },
|
||||||
},
|
})
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ return {
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-lint",
|
"mfussenegger/nvim-lint",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
linters_by_ft = {
|
opts.linters_by_ft.cmake = opts.linters_by_ft.cmake or {}
|
||||||
cmake = { "cmakelint" },
|
table.insert(opts.linters_by_ft.cmake, "cmakelint")
|
||||||
},
|
return opts
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mason.nvim",
|
"mason.nvim",
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ return {
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-lint",
|
"mfussenegger/nvim-lint",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
linters_by_ft = {
|
opts.linters_by_ft.dockerfile = opts.linters_by_ft.dockerfile or {}
|
||||||
dockerfile = { "hadolint" },
|
table.insert(opts.linters_by_ft.dockerfile, "hadolint")
|
||||||
},
|
return opts
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,10 @@ return {
|
||||||
if vim.fn.executable("credo") == 0 then
|
if vim.fn.executable("credo") == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
opts.linters_by_ft = {
|
|
||||||
elixir = { "credo" },
|
opts.linters_by_ft.elixir = opts.linters_by_ft.elixir or {}
|
||||||
}
|
table.insert(opts.linters_by_ft.elixir, "credo")
|
||||||
|
return opts
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -114,11 +114,11 @@ return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
formatters_by_ft = {
|
opts.formatters_by_ft.go = opts.formatters_by_ft.go or {}
|
||||||
go = { "goimports", "gofumpt" },
|
vim.table_extend(opts.formatters_by_ft.go, { "goimports", "gofumpt" })
|
||||||
},
|
return opts
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-dap",
|
"mfussenegger/nvim-dap",
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ return {
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-lint",
|
"mfussenegger/nvim-lint",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
linters_by_ft = {
|
opts.linters_by_ft.markdown = opts.linters_by_ft.markdown or {}
|
||||||
markdown = { "markdownlint" },
|
table.insert(opts.linters_by_ft.markdown, "markdownlint")
|
||||||
},
|
return opts
|
||||||
},
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,18 @@ return {
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
formatters_by_ft = {
|
opts.formatters_by_ft.cs = opts.formatters_by_ft.cs or {}
|
||||||
cs = { "csharpier" },
|
table.insert(opts.formatters_by_ft.cs, "csharpier")
|
||||||
},
|
|
||||||
formatters = {
|
opts.formatters = {
|
||||||
csharpier = {
|
csharpier = {
|
||||||
command = "dotnet-csharpier",
|
command = "dotnet-csharpier",
|
||||||
args = { "--write-stdout" },
|
args = { "--write-stdout" },
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
},
|
return opts
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"williamboman/mason.nvim",
|
"williamboman/mason.nvim",
|
||||||
|
|
|
||||||
|
|
@ -38,22 +38,28 @@ return {
|
||||||
{
|
{
|
||||||
"mfussenegger/nvim-lint",
|
"mfussenegger/nvim-lint",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
linters_by_ft = {
|
opts.linters_by_ft.terraform = opts.linters_by_ft.terraform or {}
|
||||||
terraform = { "terraform_validate" },
|
table.insert(opts.linters_by_ft.terraform, "terraform_validate")
|
||||||
tf = { "terraform_validate" },
|
|
||||||
},
|
opts.linters_by_ft.tf = opts.linters_by_ft.tf or {}
|
||||||
},
|
table.insert(opts.linters_by_ft.tf, "terraform_validate")
|
||||||
|
return opts
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
opts = {
|
opts = function(_, opts)
|
||||||
formatters_by_ft = {
|
opts.formatters_by_ft.terraform = opts.formatters_by_ft.terraform or {}
|
||||||
terraform = { "terraform_fmt" },
|
table.insert(opts.formatters_by_ft.terraform, "terraform_fmt")
|
||||||
tf = { "terraform_fmt" },
|
|
||||||
["terraform-vars"] = { "terraform_fmt" },
|
opts.formatters_by_ft.tf = opts.formatters_by_ft.tf or {}
|
||||||
},
|
table.insert(opts.formatters_by_ft.tf, "terraform_fmt")
|
||||||
},
|
|
||||||
|
opts.formatters_by_ft["terraform-vars"] = opts.formatters_by_ft["terraform-vars"] or {}
|
||||||
|
table.insert(opts.formatters_by_ft["terraform-vars"], "terraform_fmt")
|
||||||
|
return opts
|
||||||
|
end,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue