80 lines
1.9 KiB
Lua
80 lines
1.9 KiB
Lua
|
|
return {
|
||
|
|
{
|
||
|
|
"mfussenegger/nvim-lint",
|
||
|
|
event = "VeryLazy",
|
||
|
|
config = function()
|
||
|
|
local lint = require("lint")
|
||
|
|
-- sqlfluff --
|
||
|
|
lint.linters.sqlfluff.args = {
|
||
|
|
"lint",
|
||
|
|
"--format=json",
|
||
|
|
"--dialect=postgres",
|
||
|
|
}
|
||
|
|
|
||
|
|
-- yamllint --
|
||
|
|
lint.linters.yamllint.args = {
|
||
|
|
args = { "--format=parsable", "-d relaxed" },
|
||
|
|
}
|
||
|
|
-- actionlint --
|
||
|
|
---- Set custom filetype to not lint everything
|
||
|
|
--- https://github.com/mfussenegger/nvim-lint/issues/591#issuecomment-2142162704
|
||
|
|
vim.filetype.add({
|
||
|
|
pattern = {
|
||
|
|
['.*/.github/workflows/.*%.yml'] = 'yaml.ghaction',
|
||
|
|
['.*/.github/workflows/.*%.yaml'] = 'yaml.ghaction',
|
||
|
|
},
|
||
|
|
})
|
||
|
|
|
||
|
|
local linters = {
|
||
|
|
bash = { "shellcheck" },
|
||
|
|
dockerfile = { "hadolint" },
|
||
|
|
ghaction = { "actionlint" },
|
||
|
|
go = { "golangcilint" },
|
||
|
|
sql = { "sqlfluff" },
|
||
|
|
yaml = { "yamllint" },
|
||
|
|
}
|
||
|
|
-- set linters --
|
||
|
|
lint.linters_by_ft = linters
|
||
|
|
-- set autocommands --
|
||
|
|
for ft, ft_linters in pairs(linters) do
|
||
|
|
local on_change = false
|
||
|
|
local on_write = false
|
||
|
|
for _, l in ipairs(ft_linters) do
|
||
|
|
if lint.linters[l].stdin then
|
||
|
|
on_change = true
|
||
|
|
else
|
||
|
|
on_write = true
|
||
|
|
end
|
||
|
|
end
|
||
|
|
if on_change then
|
||
|
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
||
|
|
pattern = ft,
|
||
|
|
callback = function()
|
||
|
|
vim.api.nvim_create_autocmd({ "TextChanged" }, {
|
||
|
|
callback = function()
|
||
|
|
lint.try_lint(nil, { ignore_errors = true })
|
||
|
|
end,
|
||
|
|
})
|
||
|
|
end,
|
||
|
|
})
|
||
|
|
end
|
||
|
|
if on_write then
|
||
|
|
vim.api.nvim_create_autocmd({ "FileType" }, {
|
||
|
|
pattern = ft,
|
||
|
|
callback = function()
|
||
|
|
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
|
||
|
|
callback = function()
|
||
|
|
lint.try_lint(nil, { ignore_errors = true })
|
||
|
|
end,
|
||
|
|
})
|
||
|
|
-- we want to also call linters here so we don't wait
|
||
|
|
-- for the first write to happen
|
||
|
|
lint.try_lint(nil, { ignore_errors = true })
|
||
|
|
end,
|
||
|
|
})
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|
||
|
|
},
|
||
|
|
}
|