nvim: Refactor linter and formatter loading

Put them into tables next to each other in preparation for more
dynamic module loading.
This commit is contained in:
Marty Oehme 2024-03-01 10:37:25 +01:00
parent bbe972cfc2
commit 1e7e6f082d
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -1,3 +1,38 @@
local linters = {
astro = { "eslint_d" },
bash = { "shellcheck" },
javascript = { "eslint_d" },
javascriptreact = { "eslint_d" },
markdown = { "markdownlint", "vale" },
quarto = { "markdownlint", "vale" },
sh = { "shellcheck" },
svelte = { "eslint_d" },
text = { "vale" },
typescript = { "eslint_d" },
typescriptreact = { "eslint_d" },
}
local formatters = {
angular = { { "prettierd", "prettier" } },
astro = { { "prettierd", "prettier" } },
bash = { "shfmt" },
bib = { "bibtex-tidy" },
css = { { "prettierd", "prettier" } },
graphql = { { "prettierd", "prettier" } },
html = { { "prettierd", "prettier" } },
javascript = { { "prettierd", "prettier" } },
javascriptreact = { { "prettierd", "prettier" } },
json = { "jq" },
lua = { "stylua" },
python = { "ruff_fix", "ruff_format" },
sh = { "shfmt" },
svelte = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } },
typescriptreact = { { "prettierd", "prettier" } },
vue = { { "prettierd", "prettier" } },
yaml = { { "prettierd", "prettier" } },
zsh = { "shfmt" },
}
return { return {
-- vista-like outline view for code -- vista-like outline view for code
{ {
@ -79,29 +114,16 @@ return {
{ {
"mfussenegger/nvim-lint", "mfussenegger/nvim-lint",
config = function() config = function()
local linters = {
astro = { "eslint_d" },
bash = { "shellcheck" },
javascript = { "eslint_d" },
javascriptreact = { "eslint_d" },
markdown = { "markdownlint", "vale" },
quarto = { "markdownlint", "vale" },
sh = { "shellcheck" },
svelte = { "eslint_d" },
text = { "vale" },
typescript = { "eslint_d" },
typescriptreact = { "eslint_d" },
}
require("lint").linters_by_ft = linters require("lint").linters_by_ft = linters
vim.api.nvim_create_autocmd({ "BufWritePost", "InsertLeave" }, { vim.api.nvim_create_autocmd({ "BufWritePost", "InsertLeave" }, {
callback = function() callback = function()
if not vim.g.disable_autoformat then if not vim.g.disable_autolint then
require("lint").try_lint() require("lint").try_lint()
end end
end, end,
}) })
end, end,
event = { "BufReadPost", "BufNewFile" }, event = { "BufWritePost", "InsertLeave" },
}, },
-- formatting setup -- formatting setup
@ -116,27 +138,7 @@ return {
end end
return { lsp_fallback = true } return { lsp_fallback = true }
end, end,
formatters_by_ft = { formatters_by_ft = formatters,
angular = { { "prettierd", "prettier" } },
astro = { { "prettierd", "prettier" } },
bash = { "shfmt" },
bib = { "bibtex-tidy" },
css = { { "prettierd", "prettier" } },
graphql = { { "prettierd", "prettier" } },
html = { { "prettierd", "prettier" } },
javascript = { { "prettierd", "prettier" } },
javascriptreact = { { "prettierd", "prettier" } },
json = { "jq" },
lua = { "stylua" },
python = { "ruff_fix", "ruff_format" },
sh = { "shfmt" },
svelte = { { "prettierd", "prettier" } },
typescript = { { "prettierd", "prettier" } },
typescriptreact = { { "prettierd", "prettier" } },
vue = { { "prettierd", "prettier" } },
yaml = { { "prettierd", "prettier" } },
zsh = { "shfmt" },
},
formatters = { formatters = {
-- enable python isort functionality -- enable python isort functionality
ruff_fix = { ruff_fix = {