1
0
Fork 0
neovim-config/lua/plugins/lint.lua

81 lines
2 KiB
Lua
Raw Normal View History

2024-09-19 12:58:41 -03:00
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" },
2025-07-27 21:10:46 -04:00
zsh = { "zsh" },
2024-09-19 12:58:41 -03:00
}
-- 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
},
}