nvim: Replace null-ls with nvim-lint

Fully replaced null-ls. Will need more tweaking on the nvim-lint setup but
works generally for now. Works well in tandem with conform formatter.
This commit is contained in:
Marty Oehme 2023-12-08 17:45:34 +01:00
parent 5ccf8bc1fc
commit ab06ef922b
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 55 additions and 62 deletions

View file

@ -40,19 +40,18 @@
"markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" }, "markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" },
"markmap.nvim": { "branch": "main", "commit": "3befc2a54c2448a16c30c1c7762aab263f22946a" }, "markmap.nvim": { "branch": "main", "commit": "3befc2a54c2448a16c30c1c7762aab263f22946a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "4eb8e15e3c0757303d4c6dea64d2981fc679e990" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "4eb8e15e3c0757303d4c6dea64d2981fc679e990" },
"mason-null-ls.nvim": { "branch": "main", "commit": "d1f7258f80867f718d643d88eee66959671a4bef" },
"mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" }, "mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" },
"mdeval.nvim": { "branch": "master", "commit": "2654caf8ecaad702b50199d18e39cff23d81e0ba" }, "mdeval.nvim": { "branch": "master", "commit": "2654caf8ecaad702b50199d18e39cff23d81e0ba" },
"mini.nvim": { "branch": "main", "commit": "b5645ac6eefce8e7af9d7dd4e5e296a81cba8a10" }, "mini.nvim": { "branch": "main", "commit": "b5645ac6eefce8e7af9d7dd4e5e296a81cba8a10" },
"molten-nvim": { "branch": "main", "commit": "93f2f168e77cbd82a881e07030cdbd45a48ed070" }, "molten-nvim": { "branch": "main", "commit": "93f2f168e77cbd82a881e07030cdbd45a48ed070" },
"neotest": { "branch": "master", "commit": "009328955066ae6c170d24bb0de5f168d8760ff8" }, "neotest": { "branch": "master", "commit": "009328955066ae6c170d24bb0de5f168d8760ff8" },
"neotest-python": { "branch": "master", "commit": "81d2265efac717bb567bc15cc652ae10801286b3" }, "neotest-python": { "branch": "master", "commit": "81d2265efac717bb567bc15cc652ae10801286b3" },
"null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" },
"nvim-FeMaco.lua": { "branch": "main", "commit": "6af458f0196215f397db31a6e1fb2df795811693" }, "nvim-FeMaco.lua": { "branch": "main", "commit": "6af458f0196215f397db31a6e1fb2df795811693" },
"nvim-base16": { "branch": "master", "commit": "96e308958625a84940d5e443475465abf99c7bd9" }, "nvim-base16": { "branch": "master", "commit": "96e308958625a84940d5e443475465abf99c7bd9" },
"nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" },
"nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" }, "nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" },
"nvim-coverage": { "branch": "main", "commit": "cf4b5c61dfac977026a51a2bcad9173c272986ce" }, "nvim-coverage": { "branch": "main", "commit": "cf4b5c61dfac977026a51a2bcad9173c272986ce" },
"nvim-lint": { "branch": "master", "commit": "849ccb610de3f6ce1a239ea1e68568ef1a53d5df" },
"nvim-lspconfig": { "branch": "master", "commit": "cf3dd4a290084a868fac0e2e876039321d57111c" }, "nvim-lspconfig": { "branch": "master", "commit": "cf3dd4a290084a868fac0e2e876039321d57111c" },
"nvim-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" }, "nvim-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" },
"nvim-surround": { "branch": "main", "commit": "703ec63aa798e5e07d309b35e42def34bebe0174" }, "nvim-surround": { "branch": "main", "commit": "703ec63aa798e5e07d309b35e42def34bebe0174" },

View file

@ -59,7 +59,7 @@ local function on_attach(client, bufnr)
{ buffer = bufnr, desc = "Next error" } { buffer = bufnr, desc = "Next error" }
) )
require("which-key").register({ ["<localleader>l"] = { name = "+lsp" } }) require("which-key").register({ ["<localleader>l"] = { name = "+language" } })
map( map(
"n", "n",
"<localleader>ld", "<localleader>ld",
@ -147,12 +147,11 @@ lspconfig.pyright.setup({
}) })
lspconfig.ruff_lsp.setup({ lspconfig.ruff_lsp.setup({
on_attach = function(client, bufnr) on_attach = function(client, bufnr)
on_attach(client, bufnr)
if python_path == nil then if python_path == nil then
python_path, _ = require("util").get_python_venv(client.config.root_dir) python_path, _ = require("util").get_python_venv(client.config.root_dir)
end end
-- print(string.format("[PYTHON VENV]: %s", vim.inspect(python_path)))
client.config.settings.python.pythonPath = python_path client.config.settings.python.pythonPath = python_path
on_attach(client, bufnr)
end, end,
}) })
@ -163,44 +162,3 @@ if require("util").is_available("arduino") then
}) })
end end
local null_ls = require("null-ls")
null_ls.setup({})
require("mason-null-ls").setup({
ensure_installed = { "black", "prettier", "shfmt", "eslint-lsp", "stylua", "jq", "vale", "markdownlint" },
automatic_installation = false,
handlers = {
shfmt = function(_, _)
null_ls.register(null_ls.builtins.formatting.shfmt.with({
extra_filetypes = { "bash", "zsh" },
}))
end,
prettier = function(_, _)
null_ls.register(null_ls.builtins.formatting.prettier.with({
extra_filetypes = { "astro" },
disabled_filetypes = { "markdown" },
timeout = 7000,
}))
end,
eslint = function(_, _)
null_ls.register(null_ls.builtins.diagnostics.eslint.with({
extra_filetypes = { "astro" },
}))
null_ls.register(null_ls.builtins.code_actions.eslint.with({
extra_filetypes = { "astro" },
}))
end,
markdownlint = function(_, _)
null_ls.register(null_ls.builtins.diagnostics.markdownlint.with({
extra_filetypes = { "quarto" },
}))
end,
vale = function(_, _)
null_ls.register(null_ls.builtins.diagnostics.vale.with({
condition = function(utils)
return (utils.root_has_file({ ".vale.ini", "_vale.ini" }) and utils.root_has_file({ "styles/" }))
end,
}))
end,
},
})

View file

@ -55,14 +55,6 @@ return {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
cmd = { "LspInstall", "LspUninstall" }, cmd = { "LspInstall", "LspUninstall" },
}, },
{
"jose-elias-alvarez/null-ls.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"jay-babu/mason-null-ls.nvim",
},
event = "VeryLazy",
},
}, },
event = "BufReadPost", event = "BufReadPost",
config = function() config = function()
@ -75,6 +67,50 @@ return {
} }, } },
}, },
-- linting setup
{
"mfussenegger/nvim-lint",
config = function()
local linters = {
astro = {},
bash = {},
javascript = {},
javascriptreact = {},
markdown = {},
quarto = {},
sh = {},
svelte = {},
text = {},
typescript = {},
typescriptreact = {},
}
local per_cmd = function(cmd, ft_table)
if vim.fn.executable(cmd) == 1 then
for _, v in pairs(ft_table) do
table.insert(v, cmd)
end
end
end
per_cmd("markdownlint", { linters.markdown })
per_cmd("vale", { linters.markdown, linters.text, linters.quarto })
per_cmd("shellcheck", { linters.sh, linters.bash })
per_cmd("eslint_d", {
linters.astro,
linters.javascript,
linters.javascriptreact,
linters.svelte,
linters.typescript,
linters.typescriptreact,
})
require("lint").linters_by_ft = linters
vim.api.nvim_create_autocmd({ "BufWritePost", "InsertLeave" }, {
callback = function()
require("lint").try_lint()
end,
})
end,
event = { "BufReadPost", "BufNewFile" },
},
-- formatting setup -- formatting setup
{ {