From a5ebc1e50139154fd03cecbe20e4a9d74811f764 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Wed, 2 Mar 2022 10:03:57 -0800 Subject: [PATCH] lint: Fix shadow issues Fix shadowing by using variables with a different name or _. I don't think any of these warnings were actual bugs and fixed them to maintain the same behaviour. --- .luacheckrc | 7 ------- assert.lua | 2 +- functional.lua | 2 +- sort.lua | 14 ++++++++------ tablex.lua | 4 ++-- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index ae8ee46..295dcf2 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -8,13 +8,6 @@ return { "213", -- Unused loop variable. "231", -- Local variable is set but never accessed. "311", -- Value assigned to a local variable is unused. - "412", -- Redefining an argument. - "413", -- Redefining a loop variable. - "421", -- Shadowing a local variable. - "422", -- Shadowing an argument. - "423", -- Shadowing a loop variable. - "423", -- Shadowing a loop variable. - "432", -- Shadowing an upvalue argument. "631", -- Line is too long. }, files = { diff --git a/assert.lua b/assert.lua index 978ce10..3a858e4 100644 --- a/assert.lua +++ b/assert.lua @@ -75,7 +75,7 @@ end --replace everything in assert with nop functions that just return their second argument, for near-zero overhead on release function assert:nop() - local nop = function(self, a) + local nop = function(_, a) return a end setmetatable(self, { diff --git a/functional.lua b/functional.lua index d6748d2..4c0e34a 100644 --- a/functional.lua +++ b/functional.lua @@ -209,7 +209,7 @@ end function functional.stitch(t, f) local result = {} for i, v in ipairs(t) do - local v = f(v, i) + v = f(v, i) if v ~= nil then if type(v) == "table" then for _, e in ipairs(v) do diff --git a/sort.lua b/sort.lua index bffa9e2..6c421e5 100644 --- a/sort.lua +++ b/sort.lua @@ -56,8 +56,8 @@ function sort._merge(array, workspace, low, middle, high, less) local i, j, k i = 1 -- copy first half of array to auxiliary array - for j = low, middle do - workspace[i] = array[j] + for w = low, middle do + workspace[i] = array[w] i = i + 1 end -- sieve through @@ -78,8 +78,8 @@ function sort._merge(array, workspace, low, middle, high, less) k = k + 1 end -- copy back any remaining elements of first half - for k = k, j - 1 do - array[k] = workspace[i] + for w = k, j - 1 do + array[w] = workspace[i] i = i + 1 end end @@ -121,7 +121,8 @@ end function sort.stable_sort(array, less) --setup - local trivial, n, less = sort._sort_setup(array, less) + local trivial, n + trivial, n, less = sort._sort_setup(array, less) if not trivial then --temp storage; allocate ahead of time local workspace = {} @@ -135,7 +136,8 @@ end function sort.insertion_sort(array, less) --setup - local trivial, n, less = sort._sort_setup(array, less) + local trivial, n + trivial, n, less = sort._sort_setup(array, less) if not trivial then sort._insertion_sort_impl(array, 1, n, less) end diff --git a/tablex.lua b/tablex.lua index ac4ef5b..8d6d118 100644 --- a/tablex.lua +++ b/tablex.lua @@ -398,8 +398,8 @@ function tablex.collapse(t) local r = {} for _, v in ipairs(t) do if type(v) == "table" then - for _, v in ipairs(v) do - table.insert(r, v) + for _, w in ipairs(v) do + table.insert(r, w) end else table.insert(r, v)