Skip to content

refactor(lint): modularize json linters #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Consult the [builtin tools](https://github.com/nvimdev/guard.nvim/tree/main/lua%
#### Linters

- [clang-tidy](https://clang.llvm.org/extra/clang-tidy/)
- [luacheck](https://github.com/lunarmodules/luacheck)
- [pylint](https://github.com/PyCQA/pylint)
- [rubocop](https://github.com/rubocop/rubocop)
- [shellcheck](https://github.com/koalaman/shellcheck)
Expand Down
39 changes: 39 additions & 0 deletions lua/guard/tools/linter/luacheck.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local diag_fmt = require('guard.lint').diag_fmt
return {
cmd = 'luacheck',
args = { '--formatter', 'plain', '--codes', '-', '--filename' },
fname = true,
stdin = true,
output_fmt = function(result, buf)
local lines = vim.split(result, '\n', { trimempty = true })

if #lines < 1 then
return {}
end

-- For each line, substring between parentheses contains
-- three digit issue code, prefixed with E for errors and W for warnings.
-- https://luacheck.readthedocs.io/en/stable/cli.html
local severities = {
E = 1,
W = 2,
}

local diags = {}

vim.tbl_map(function(line)
local lnum, col, severity, code, message = line:match('(%d+):(%d+):%s%((%a)(%w+)%) (.+)')

diags[#diags + 1] = diag_fmt(
buf,
tonumber(lnum) - 1,
tonumber(col) - 1,
message .. ' [' .. code .. ']',
severities[severity] or 4,
'luacheck'
)
end, lines)

return diags
end,
}