♻️ 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:
parent
c1f1003dc4
commit
f9d52ab208
11 changed files with 166 additions and 56 deletions
|
@ -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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
17
.config/nvim/lua/plugins/extras/formatting/isort.lua
Normal file
17
.config/nvim/lua/plugins/extras/formatting/isort.lua
Normal 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,
|
||||
},
|
||||
}
|
10
.config/nvim/lua/plugins/extras/formatting/rustfmt.lua
Normal file
10
.config/nvim/lua/plugins/extras/formatting/rustfmt.lua
Normal 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,
|
||||
},
|
||||
}
|
34
.config/nvim/lua/plugins/extras/formatting/rustywind.lua
Normal file
34
.config/nvim/lua/plugins/extras/formatting/rustywind.lua
Normal 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,
|
||||
},
|
||||
}
|
17
.config/nvim/lua/plugins/extras/formatting/shellharden.lua
Normal file
17
.config/nvim/lua/plugins/extras/formatting/shellharden.lua
Normal 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,
|
||||
},
|
||||
}
|
31
.config/nvim/lua/plugins/extras/formatting/sqlfmt.lua
Normal file
31
.config/nvim/lua/plugins/extras/formatting/sqlfmt.lua
Normal 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,
|
||||
},
|
||||
}
|
|
@ -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,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
{
|
||||
|
|
17
.config/nvim/lua/plugins/extras/linting/pylint.lua
Normal file
17
.config/nvim/lua/plugins/extras/linting/pylint.lua
Normal 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,
|
||||
},
|
||||
}
|
31
.config/nvim/lua/plugins/extras/linting/stylelint.lua
Normal file
31
.config/nvim/lua/plugins/extras/linting/stylelint.lua
Normal 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,
|
||||
},
|
||||
}
|
|
@ -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" },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
Loading…
Add table
Reference in a new issue