feat(extras): added extra for nvim-lint
This commit is contained in:
@ -18,6 +18,15 @@ return {
|
|||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
optional = true,
|
||||||
|
opts = {
|
||||||
|
linters_by_ft = {
|
||||||
|
cmake = { "cmakelint" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"mason.nvim",
|
"mason.nvim",
|
||||||
opts = function(_, opts)
|
opts = function(_, opts)
|
||||||
|
@ -25,6 +25,15 @@ return {
|
|||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
optional = true,
|
||||||
|
opts = {
|
||||||
|
linters_by_ft = {
|
||||||
|
dockerfile = { "hadolint" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"neovim/nvim-lspconfig",
|
"neovim/nvim-lspconfig",
|
||||||
opts = {
|
opts = {
|
||||||
|
@ -37,6 +37,16 @@ return {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
optional = true,
|
||||||
|
opts = {
|
||||||
|
linters_by_ft = {
|
||||||
|
terraform = { "terraform_validate" },
|
||||||
|
tf = { "terraform_validate" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
optional = true,
|
optional = true,
|
||||||
|
65
lua/lazyvim/plugins/extras/linting/nvim-lint.lua
Normal file
65
lua/lazyvim/plugins/extras/linting/nvim-lint.lua
Normal 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,
|
||||||
|
},
|
||||||
|
}
|
Reference in New Issue
Block a user