From a2216e14521763e702f69a9bfd046aa15a5b3f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Mon, 6 Mar 2017 10:54:38 +0000 Subject: luacheck: clean up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- .luacheckrc | 1 + Makefile | 1 + lua/inet/init.lua | 5 ++--- test/inet.lua | 15 ++++++++------- test/inet_set.lua | 4 +--- 5 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..0c5ab03 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1 @@ +globals = { '_ENV' } diff --git a/Makefile b/Makefile index eae0586..4b8d9fb 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,4 @@ build: test: lua5.2 ./test.lua lua5.3 ./test.lua + find lua/ test/ -iname '*.lua' | xargs luacheck diff --git a/lua/inet/init.lua b/lua/inet/init.lua index fcdabe9..99d1195 100644 --- a/lua/inet/init.lua +++ b/lua/inet/init.lua @@ -273,8 +273,7 @@ end function inet6:is_balanced() local pcs = self.pcs - local i = 8 - for i=i,8 do + for i=1,8 do local piece = pcs[i] if piece < 0 or piece > 0xffff then return false @@ -453,7 +452,7 @@ function inet6:flip() local flipbit = lshift(1, bitno) local r = self:clone() local val = r.pcs[block] - r.pcs[block] = bxor(r.pcs[block], flipbit) + r.pcs[block] = bxor(val, flipbit) --print(mask, block, maskbits, bitno, flipbit, self, r:balance()) return r end diff --git a/test/inet.lua b/test/inet.lua index 43432cc..e86c074 100644 --- a/test/inet.lua +++ b/test/inet.lua @@ -12,6 +12,7 @@ local function dontparse(...) end return test.new(function() + local ip -- parsing parse('1:2:3:4:5:6:7:8') parse('::1/33') @@ -35,10 +36,10 @@ return test.new(function() assert(tostring(parse('1:ffff:ffff:fe00::/56') * 2) == '2::/56') assert(tostring(parse('1:ffff:ffff:fe00::/56') * 2 * -2) == '1:ffff:ffff:fe00::/56') - local ip = inet('10.0.0.0/33') + ip = inet('10.0.0.0/33') assert(ip == nil) - local ip = inet('10.0.0.0/24') + ip = inet('10.0.0.0/24') assert(type(ip) == 'table') assert(#ip == 24, 'incorrect netmask') assert(tostring(ip) == '10.0.0.0/24', 'not human readable') @@ -84,14 +85,14 @@ return test.new(function() -- test inet*.network assert(inet('10.0.0.1/30'):network() == inet('10.0.0.0/30'), 'inet4.network() is broken') assert(inet('1::2/64'):network() == inet('1::/64'), 'inet6.network() is broken') - local ip = inet('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/62') + ip = inet('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/62') assert((ip/22):network() == inet('ffff:fc00::/22'), 'inet6.network() is broken') assert((ip/27):network() == inet('ffff:ffe0::/27'), 'inet6.network() is broken') --- test inet4:flip - assert(inet('10.0.0.1/24'):flip() == inet('10.0.1.1/24'), 'inet.flip() is broken') - assert(inet('10.0.0.0/24'):flip() == inet('10.0.1.0/24'), 'inet.flip() is broken') - assert(inet('10.0.0.0/24'):flip():flip() == inet('10.0.0.0/24'), 'inet.flip() is broken') + assert(inet('10.0.0.1/24'):flip() == inet('10.0.1.1/24'), 'inet4.flip() is broken') + assert(inet('10.0.0.0/24'):flip() == inet('10.0.1.0/24'), 'inet4.flip() is broken') + assert(inet('10.0.0.0/24'):flip():flip() == inet('10.0.0.0/24'), 'inet4.flip() is broken') assert(inet('10.20.30.0/24'):flip() == inet('10.20.31.0/24')) assert(inet('10.20.30.5/24'):flip() == inet('10.20.31.5/24')) assert(inet('10.20.30.5/32'):flip() == inet('10.20.30.4/32')) @@ -104,7 +105,7 @@ return test.new(function() assert(inet('::1/32'):flip() == inet('0:1::1/32')) assert(inet('::1/48'):flip() == inet('0:0:1::1/48')) for i=1,#ips do - local ip = ips[i] + ip = ips[i] for j=1,128 do local foo = ip / j local bar = foo:flip() diff --git a/test/inet_set.lua b/test/inet_set.lua index ec16d8c..4c673d5 100644 --- a/test/inet_set.lua +++ b/test/inet_set.lua @@ -2,7 +2,7 @@ local inet = require 'inet' local inet_set = require 'inet.set' local test = require 'test' -function agg_set(a, b) +local function agg_set(a, b) inet_set.aggregate(a) assert(#a == #b, 'wrong set size') for i=1,#a do @@ -13,8 +13,6 @@ end return test.new(function() - local ip = inet('10.0.0.0/24') - agg_set({ inet('10.0.0.0/24'), inet('10.0.1.0/24'), -- cgit v1.2.1