Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ local function from_json(opts)
end

vim.tbl_map(function(mes)
local lnum = type(opts.attributes.lnum) == 'function' and opts.attributes.lnum(mes)
or mes[opts.attributes.lnum]
local col = type(opts.attributes.col) == 'function' and opts.attributes.col(mes)
or mes[opts.attributes.col]

diags[#diags + 1] = diag_fmt(
buf,
tonumber(mes[opts.attributes.lnum] - opts.offset),
tonumber(mes[opts.attributes.col] - opts.offset),
tonumber(lnum) - opts.offset,
tonumber(col) - opts.offset,
('%s [%s]'):format(mes[opts.attributes.message], mes[opts.attributes.code]),
opts.severities[mes[opts.attributes.severity]],
opts.source
Expand Down
24 changes: 24 additions & 0 deletions lua/guard/tools/linter/selene.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local lint = require('guard.lint')

return {
cmd = 'selene',
args = { '--no-summary', '--display-style', 'json2' },
stdin = true,
parse = lint.from_json({
attributes = {
lnum = function(offence)
return offence.primary_label.span.start_line
end,
col = function(offence)
return offence.primary_label.span.start_column
end,
},
severities = {
Error = lint.severities.error,
Warning = lint.severities.warning,
},
lines = true,
offset = 0,
source = 'selene',
}),
}