From 0c193d79019eb2d3fc25e7f0b5aa24197cb8b3ca Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 3 Mar 2022 00:01:20 -0800 Subject: [PATCH] lint: Don't assign values that will never be used No bugs here, but giving an initial value can hide cases where we fail to set a value. Use an assert instead so we can see errors if we change and break this code. Except break_next which goes out of scope after it's assigned (I guess it used to be outside the loop). --- .luacheckrc | 1 - colour.lua | 3 ++- intersect.lua | 3 ++- pretty.lua | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 95c5344..1e5df27 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -4,7 +4,6 @@ return { "211", -- Unused local variable. "212/self", -- Unused argument self. "213", -- Unused loop variable. - "311", -- Value assigned to a local variable is unused. "631", -- Line is too long. }, files = { diff --git a/colour.lua b/colour.lua index 0feebb1..3d7a351 100644 --- a/colour.lua +++ b/colour.lua @@ -136,7 +136,7 @@ function colour.rgb_to_hsl(r, g, b) local l, d = max + min, max - min local s = d / (l > 1 and (2 - l) or l) l = l / 2 - local h = nil --depends on below + local h --depends on below if max == r then h = (g - b) / d if g < b then h = h + 6 end @@ -145,6 +145,7 @@ function colour.rgb_to_hsl(r, g, b) else h = (r - g) / d + 4 end + assert(h) return h / 6, s, l end diff --git a/intersect.lua b/intersect.lua index 4e62e7d..8b4ca7c 100644 --- a/intersect.lua +++ b/intersect.lua @@ -186,7 +186,7 @@ function intersect.line_line_collide(a_start, a_end, a_rad, b_start, b_end, b_ra local numerb = dx1 * dyab - dy1 * dxab --check coincident lines - local intersected = "none" + local intersected if math.abs(numera) < COLLIDE_EPS and math.abs(numerb) < COLLIDE_EPS and @@ -215,6 +215,7 @@ function intersect.line_line_collide(a_start, a_end, a_rad, b_start, b_end, b_ra end end end + assert(intersected) if intersected == "both" then --simply displace along A normal diff --git a/pretty.lua b/pretty.lua index 42fd2e4..8aa1725 100644 --- a/pretty.lua +++ b/pretty.lua @@ -153,7 +153,6 @@ function pretty._process(input, config, processing_state) end if break_next then table.insert(line_chunks, table.remove(chunks, 1)) - break_next = false end end chunks = line_chunks