From 683e163909dba3247775f581d9897c540d8245b1 Mon Sep 17 00:00:00 2001 From: Tristan Knight Date: Thu, 21 Dec 2023 23:49:20 +0000 Subject: [PATCH] fix(duplicates): fix data shape (#37) Co-authored-by: tris203 --- lua/hawtkeys/duplicates.lua | 6 ++---- lua/hawtkeys/utils.lua | 2 +- tests/hawtkeys/utils_spec.lua | 12 ++++++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lua/hawtkeys/duplicates.lua b/lua/hawtkeys/duplicates.lua index c36a261..ab70ae5 100644 --- a/lua/hawtkeys/duplicates.lua +++ b/lua/hawtkeys/duplicates.lua @@ -7,13 +7,11 @@ function M.show_duplicates() local allKeys = tsSearch.get_all_keymaps() local duplicates = utils.find_duplicates(allKeys) local resultTable = {} - for index, data in ipairs(duplicates) do + for index, data in pairs(duplicates) do table.insert(resultTable, tostring(index) .. " duplicates found in ") table.insert( resultTable, - tostring(data[1][1].from_file) - .. ":" - .. tostring(data[2][1].from_file) + tostring(data[1].from_file) .. ":" .. tostring(data[2].from_file) ) end return resultTable diff --git a/lua/hawtkeys/utils.lua b/lua/hawtkeys/utils.lua index 36548bb..0b29a4e 100644 --- a/lua/hawtkeys/utils.lua +++ b/lua/hawtkeys/utils.lua @@ -70,7 +70,7 @@ function M.find_duplicates(keymaps) for _, v in pairs(keymaps) do for _, v2 in pairs(keymaps) do if v.lhs == v2.lhs and v.mode == v2.mode and v.rhs ~= v2.rhs then - duplicates[v.lhs] = { { v }, { v2 } } + duplicates[v.lhs] = { v, v2 } end end end diff --git a/tests/hawtkeys/utils_spec.lua b/tests/hawtkeys/utils_spec.lua index 8de2ca1..1558cba 100644 --- a/tests/hawtkeys/utils_spec.lua +++ b/tests/hawtkeys/utils_spec.lua @@ -13,8 +13,8 @@ describe("utils functionality", function() } local duplicates = utils.find_duplicates(keymaps) eq(2, #duplicates.a) - eq("a", duplicates.a[1][1].lhs) - eq("a", duplicates.a[2][1].lhs) + eq("a", duplicates.a[1].lhs) + eq("a", duplicates.a[2].lhs) end) it("can find multiple duplicate lhs in table", function() @@ -26,10 +26,10 @@ describe("utils functionality", function() } local duplicates = utils.find_duplicates(keymaps) eq(2, #duplicates.a) - eq("a", duplicates.a[1][1].lhs) - eq("a", duplicates.a[2][1].lhs) + eq("a", duplicates.a[1].lhs) + eq("a", duplicates.a[2].lhs) eq(2, #duplicates.b) - eq("b", duplicates.b[1][1].lhs) - eq("b", duplicates.b[2][1].lhs) + eq("b", duplicates.b[1].lhs) + eq("b", duplicates.b[2].lhs) end) end)