Skip to content

Commit

Permalink
fix: map and for each
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoshihou514 committed Dec 13, 2024
1 parent 56f1328 commit e2604e7
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions lua/guard/lint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function M.from_json(opts)
opts = vim.tbl_deep_extend('force', json_opts, opts)

return function(result, buf)
local diags, offences = {}, {}
local offences = {}

if opts.lines then
-- \r\n for windows compatibility
Expand All @@ -171,21 +171,22 @@ function M.from_json(opts)
offences = opts.get_diagnostics(result)
end

return vim.tbl_map(function(mes)
local attr = opts.attributes
local message = attr_value(mes, attr.message)
local code = attr_value(mes, attr.code)
diags[#diags + 1] = M.diag_fmt(
buf,
tonumber(attr_value(mes, attr.lnum)) - opts.offset,
tonumber(attr_value(mes, attr.col)) - opts.offset,
formulate_msg(message, code),
opts.severities[attr_value(mes, attr.severity)],
opts.source,
tonumber(attr_value(mes, attr.lnum_end or attr.lnum)) - opts.offset,
tonumber(attr_value(mes, attr.col_end or attr.lnum)) - opts.offset
)
end, offences or {})
return vim
.iter(offences or {})
:map(function(mes)
local attr = opts.attributes
return M.diag_fmt(
buf,
tonumber(attr_value(mes, attr.lnum)) - opts.offset,
tonumber(attr_value(mes, attr.col)) - opts.offset,
formulate_msg(attr_value(mes, attr.message), attr_value(mes, attr.code)),
opts.severities[attr_value(mes, attr.severity)],
opts.source,
tonumber(attr_value(mes, attr.lnum_end or attr.lnum)) - opts.offset,
tonumber(attr_value(mes, attr.col_end or attr.lnum)) - opts.offset
)
end)
:totable()
end
end

Expand Down

0 comments on commit e2604e7

Please sign in to comment.