From e2604e7b8bf8d9d8c2e10e98c1322e2ddcdda257 Mon Sep 17 00:00:00 2001 From: xiaoshihou Date: Fri, 13 Dec 2024 10:59:04 +0000 Subject: [PATCH] fix: map and for each --- lua/guard/lint.lua | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lua/guard/lint.lua b/lua/guard/lint.lua index 87877f5..3538b15 100644 --- a/lua/guard/lint.lua +++ b/lua/guard/lint.lua @@ -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 @@ -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