diff --git a/lua/guard/lint.lua b/lua/guard/lint.lua index 085a456a..f4ea5ff0 100644 --- a/lua/guard/lint.lua +++ b/lua/guard/lint.lua @@ -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 diff --git a/lua/guard/tools/linter/selene.lua b/lua/guard/tools/linter/selene.lua new file mode 100644 index 00000000..78ff0bf1 --- /dev/null +++ b/lua/guard/tools/linter/selene.lua @@ -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', + }), +}