♻️ refactor(nvim): big change in adding formatters and linters

all the formatters and linters are dynamically added, and they are going to the extras modules
This commit is contained in:
Sergio Laín 2023-11-16 15:00:10 +01:00
parent c1f1003dc4
commit f9d52ab208
No known key found for this signature in database
GPG key ID: 14C9B8080681777B
11 changed files with 166 additions and 56 deletions

View file

@ -1,39 +1,11 @@
return {
{
"stevearc/conform.nvim",
keys = {
{
"<leader>cic",
"<cmd>ConformInfo<CR>",
mode = { "n", "v" },
desc = "Conform Info",
},
},
opts = {
formatters_by_ft = {
lua = { "stylua" },
fish = { "fish_indent" },
sh = { "shfmt", "shellharden" },
python = { "isort", "black" },
bash = { "shfmt", "shellharden" },
javascript = { { "prettierd", "prettier", "rustywind" } },
javascriptreact = { { "prettierd", "prettier", "rustywind" } },
typescript = { { "prettierd", "prettier", "rustywind" } },
typescriptreact = { { "prettierd", "prettier", "rustywind" } },
vue = { { "prettierd", "prettier", "rustywind" } },
html = { { "prettierd", "prettier", "rustywind", "stylelint" } },
rust = { "rusfmt" },
go = { "gofumpt", "goimports" },
sass = { "stylelint" },
css = { { "prettierd", "prettier", "stylelint" } },
scss = { { "prettierd", "prettier", "stylelint" } },
less = { { "prettierd", "prettier", "stylelint" } },
markdown = { { "prettierd", "prettier" } },
toml = { "taplo" },
sql = { "sqlfmt" },
mysql = { "sqlfmt" },
plsql = { "sqlfmt" },
},
"stevearc/conform.nvim",
keys = {
{
"<leader>cic",
"<cmd>ConformInfo<CR>",
mode = { "n", "v" },
desc = "Conform Info",
},
},
}

View file

@ -0,0 +1,17 @@
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "isort" })
end,
},
{
"stevearc/conform.nvim",
opts = function(_, opts)
opts.formatters_by_ft.python = opts.formatters_by_ft.python or {}
table.insert(opts.formatters_by_ft.python, "isort")
return opts
end,
},
}

View file

@ -0,0 +1,10 @@
return {
{
"stevearc/conform.nvim",
opts = function(_, opts)
opts.formatters_by_ft.rust = opts.formatters_by_ft.rust or {}
table.insert(opts.formatters_by_ft.rust, "rustfmt")
return opts
end,
},
}

View file

@ -0,0 +1,34 @@
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "rustywind" })
end,
},
{
"stevearc/conform.nvim",
opts = function(_, opts)
--- 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"] = { "rustywind" },
["javascriptreact"] = { "rustywind" },
["typescript"] = { "rustywind" },
["typescriptreact"] = { "rustywind" },
["vue"] = { "rustywind" },
["html"] = { "rustywind" },
})
end,
},
}

View file

@ -0,0 +1,17 @@
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "shellharden" })
end,
},
{
"stevearc/conform.nvim",
opts = function(_, opts)
opts.formatters_by_ft.bash = opts.formatters_by_ft.bash or {}
table.insert(opts.formatters_by_ft.bash, "shellharden")
return opts
end,
},
}

View file

@ -0,0 +1,31 @@
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "sqlfmt" })
end,
},
{
"stevearc/conform.nvim",
opts = function(_, opts)
--- 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({
["sql"] = { "sqlfmt" },
["plsql"] = { "sqlfmt" },
["mysql"] = { "sqlfmt" },
})
end,
},
}

View file

@ -19,7 +19,7 @@ return {
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "bash-language-server", "shfmt", "shellharden" })
vim.list_extend(opts.ensure_installed, { "bash-language-server" })
end,
},
}

View file

@ -73,7 +73,7 @@ return {
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "sqlfmt", "sqlls" })
vim.list_extend(opts.ensure_installed, { "sqlls" })
end,
},
{

View file

@ -0,0 +1,17 @@
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { "pylint" })
end,
},
{
"mfussenegger/nvim-lint",
opts = function(_, opts)
opts.linters_by_ft.python = opts.linters_by_ft.python or {}
table.insert(opts.linters_by_ft.python, "pylint")
return opts
end,
},
}

View file

@ -0,0 +1,31 @@
local stylelint = "stylelint"
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { stylelint })
end,
},
{
"mfussenegger/nvim-lint",
opts = function(_, opts)
opts.linters_by_ft.html = opts.linters_by_ft.html or {}
table.insert(opts.linters_by_ft.html, stylelint)
opts.linters_by_ft.css = opts.linters_by_ft.css or {}
table.insert(opts.linters_by_ft.css, stylelint)
opts.linters_by_ft.scss = opts.linters_by_ft.scss or {}
table.insert(opts.linters_by_ft.scss, stylelint)
opts.linters_by_ft.sass = opts.linters_by_ft.sass or {}
table.insert(opts.linters_by_ft.sass, stylelint)
opts.linters_by_ft.less = opts.linters_by_ft.less or {}
table.insert(opts.linters_by_ft.less, stylelint)
return opts
end,
},
}

View file

@ -1,19 +0,0 @@
return {
{
"mfussenegger/nvim-lint",
event = "LazyFile",
opts = {
-- Event to trigger linters
events = { "BufWritePost", "BufReadPost", "InsertLeave" },
linters_by_ft = {
fish = { "fish" },
markdown = { "markdownlint" },
-- python = { "pylint" },
dockerfile = { "hadolint" },
css = { "stylelint" },
sass = { "stylelint" },
scss = { "stylelint" },
},
},
},
}