feat(extras): added extra for nvim-lint

This commit is contained in:
Folke Lemaitre
2023-09-29 15:05:01 +02:00
parent 9762e7e431
commit 05f45bb720
4 changed files with 93 additions and 0 deletions

View File

@ -18,6 +18,15 @@ return {
})
end,
},
{
"mfussenegger/nvim-lint",
optional = true,
opts = {
linters_by_ft = {
cmake = { "cmakelint" },
},
},
},
{
"mason.nvim",
opts = function(_, opts)

View File

@ -25,6 +25,15 @@ return {
end,
},
},
{
"mfussenegger/nvim-lint",
optional = true,
opts = {
linters_by_ft = {
dockerfile = { "hadolint" },
},
},
},
{
"neovim/nvim-lspconfig",
opts = {

View File

@ -37,6 +37,16 @@ return {
end
end,
},
{
"mfussenegger/nvim-lint",
optional = true,
opts = {
linters_by_ft = {
terraform = { "terraform_validate" },
tf = { "terraform_validate" },
},
},
},
{
"stevearc/conform.nvim",
optional = true,

View File

@ -0,0 +1,65 @@
return {
{
"mfussenegger/nvim-lint",
event = "BufReadPost",
opts = {
events = { "BufWritePost", "BufReadPost", "InsertLeave" },
linters_by_ft = {
fish = { "fish" },
},
linters = {},
linter_opts = {},
},
config = function(_, opts)
local M = {}
M._did_setup = false
function M.setup()
if M._did_setup then
return
end
local lint = require("lint")
for name, linter in pairs(opts.linters) do
lint.linters[name] = linter
end
lint.linters_by_ft = vim.tbl_extend("force", lint.linters_by_ft, opts.linters_by_ft)
for l, o in pairs(opts.linter_opts or {}) do
lint.linters[l] = vim.tbl_deep_extend("force", lint.linters[l], o)
end
M._did_setup = true
end
function M.debounce(ms, fn)
local timer = vim.loop.new_timer()
return function(...)
local argv = { ... }
timer:start(ms, 0, function()
timer:stop()
vim.schedule_wrap(fn)(unpack(argv))
end)
end
end
function M.lint()
M.setup()
local lint = require("lint")
local names = lint.linters_by_ft[vim.bo.filetype] or {}
local ctx = { filename = vim.api.nvim_buf_get_name(0) }
ctx.dirname = vim.fn.fnamemodify(ctx.filename, ":h")
names = vim.tbl_filter(function(name)
local linter = lint.linters[name]
return linter and not (linter.condition and not linter.condition(ctx))
end, names)
if #names > 0 then
lint.try_lint(names)
end
end
vim.api.nvim_create_autocmd(opts.events, {
group = vim.api.nvim_create_augroup("nvim-lint", { clear = true }),
callback = M.debounce(100, M.lint),
})
end,
},
}