[Tarantool-patches] [PATCH v6 09/25] Fix luacheck warnings in test/box

sergeyb at tarantool.org sergeyb at tarantool.org
Fri May 29 18:09:10 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

Part of #4681

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Reviewed-by: Igor Munkin <imun at tarantool.org>

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Co-authored-by: Igor Munkin <imun at tarantool.org>
---
 .luacheckrc                        | 13 +++++++++++++
 test/box/box.lua                   |  2 +-
 test/box/hash_multipart.result     |  2 +-
 test/box/hash_multipart.test.lua   |  2 +-
 test/box/lua/bitset.lua            |  7 ++-----
 test/box/lua/cfg_bad_vinyl_dir.lua |  2 +-
 test/box/lua/cfg_rtree.lua         |  2 +-
 test/box/lua/cfg_test1.lua         |  2 +-
 test/box/lua/cfg_test2.lua         |  2 +-
 test/box/lua/cfg_test3.lua         |  2 +-
 test/box/lua/cfg_test4.lua         |  2 +-
 test/box/lua/cfg_test5.lua         |  4 ++--
 test/box/lua/cfg_test6.lua         |  2 +-
 test/box/lua/fifo.lua              |  2 +-
 test/box/lua/identifier.lua        |  9 ++++-----
 test/box/lua/index_random_test.lua |  2 +-
 test/box/lua/require_init.lua      |  3 ---
 test/box/lua/test_init.lua         | 10 +++++-----
 test/box/lua/utils.lua             | 13 ++++++-------
 test/box/on_schema_init.lua        |  2 +-
 test/box/proxy.lua                 |  2 +-
 test/box/tiny.lua                  |  2 +-
 test/box/tree_pk.result            |  4 ++--
 test/box/tree_pk.test.lua          |  4 ++--
 24 files changed, 51 insertions(+), 46 deletions(-)

diff --git a/.luacheckrc b/.luacheckrc
index 630834e16..f99cc17eb 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -41,3 +41,16 @@ files["src/box/lua/schema.lua"] = {globals = {"tonumber64"}, ignore = {"431", "4
 files["test/app/lua/fiber.lua"] = {globals = {"box_fiber_run_test"}}
 files["test/app-tap/lua/require_mod.lua"] = {globals = {"exports"}}
 files["test/app-tap/string.test.lua"] = {globals = {"utf8"}}
+files["test/box/lua/push.lua"] = {globals = {"push_collection"}}
+files["test/box/lua/index_random_test.lua"] = {globals = {"index_random_test"}}
+files["test/box/lua/utils.lua"] = {
+	globals = {"space_field_types", "iterate", "arithmetic", "table_shuffle",
+	"table_generate", "tuple_to_string", "check_space", "space_bsize",
+	"create_iterator", "setmap", "sort"}}
+files["test/box/lua/bitset.lua"] = {
+	globals = {"create_space", "fill", "delete", "clear", "drop_space",
+	"dump", "test_insert_delete"}
+}
+files["test/box/lua/fifo.lua"] = {globals = {"fifomax", "find_or_create_fifo", "fifo_push", "fifo_top"}}
+files["test/box/lua/identifier.lua"] = {globals = {"run_test"}}
+files["test/box/lua/require_mod.lua"] = {globals = {"exports"}}
diff --git a/test/box/box.lua b/test/box/box.lua
index 6fad07015..2cf399f96 100644
--- a/test/box/box.lua
+++ b/test/box/box.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 local msgpack = require('msgpack')
 
diff --git a/test/box/hash_multipart.result b/test/box/hash_multipart.result
index e94313b62..e6915652f 100644
--- a/test/box/hash_multipart.result
+++ b/test/box/hash_multipart.result
@@ -62,7 +62,7 @@ test_run:cmd("setopt delimiter ';'")
 function select_all()
     local result = {}
     local tuple, v
-    for tuple, v in hash:pairs() do
+    for _, v in hash:pairs() do
         table.insert(result, v)
     end
     return result
diff --git a/test/box/hash_multipart.test.lua b/test/box/hash_multipart.test.lua
index c0a871bee..c572d13b6 100644
--- a/test/box/hash_multipart.test.lua
+++ b/test/box/hash_multipart.test.lua
@@ -24,7 +24,7 @@ test_run:cmd("setopt delimiter ';'")
 function select_all()
     local result = {}
     local tuple, v
-    for tuple, v in hash:pairs() do
+    for _, v in hash:pairs() do
         table.insert(result, v)
     end
     return result
diff --git a/test/box/lua/bitset.lua b/test/box/lua/bitset.lua
index 41d2c3681..948bf3710 100644
--- a/test/box/lua/bitset.lua
+++ b/test/box/lua/bitset.lua
@@ -1,8 +1,5 @@
 local utils = require('utils')
 
-local SPACE_NO = 0 
-local INDEX_NO = 1
-
 function create_space()
     local space = box.schema.create_space('tweedledum')
     space:create_index('primary', { type = 'hash', parts = {1, 'unsigned'}, unique = true })
@@ -13,7 +10,7 @@ function fill(...)
     local space = box.space['tweedledum']
     local nums = utils.table_generate(utils.arithmetic(...))
     utils.table_shuffle(nums)
-    for _k, v in ipairs(nums) do
+    for _, v in ipairs(nums) do
         space:insert{v, v}
     end
 end
@@ -22,7 +19,7 @@ function delete(...)
     local space = box.space['tweedledum']
     local nums = utils.table_generate(utils.arithmetic(...))
     utils.table_shuffle(nums)
-    for _k, v in ipairs(nums) do
+    for _, v in ipairs(nums) do
         space:delete{v}
     end
 end
diff --git a/test/box/lua/cfg_bad_vinyl_dir.lua b/test/box/lua/cfg_bad_vinyl_dir.lua
index 8e1a98dc8..82746b99a 100644
--- a/test/box/lua/cfg_bad_vinyl_dir.lua
+++ b/test/box/lua/cfg_bad_vinyl_dir.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_rtree.lua b/test/box/lua/cfg_rtree.lua
index f2d32ef7d..860cb14a8 100644
--- a/test/box/lua/cfg_rtree.lua
+++ b/test/box/lua/cfg_rtree.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 box.error.injection.set("ERRINJ_INDEX_RESERVE", true)
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_test1.lua b/test/box/lua/cfg_test1.lua
index 60b7aff9a..aa026ed42 100644
--- a/test/box/lua/cfg_test1.lua
+++ b/test/box/lua/cfg_test1.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_test2.lua b/test/box/lua/cfg_test2.lua
index 2397f9c19..536661698 100644
--- a/test/box/lua/cfg_test2.lua
+++ b/test/box/lua/cfg_test2.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_test3.lua b/test/box/lua/cfg_test3.lua
index 6a6e544b6..4978900fb 100644
--- a/test/box/lua/cfg_test3.lua
+++ b/test/box/lua/cfg_test3.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_test4.lua b/test/box/lua/cfg_test4.lua
index 82dab8757..21a38f95c 100644
--- a/test/box/lua/cfg_test4.lua
+++ b/test/box/lua/cfg_test4.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/lua/cfg_test5.lua b/test/box/lua/cfg_test5.lua
index e3eb87392..8b6f9b31c 100644
--- a/test/box/lua/cfg_test5.lua
+++ b/test/box/lua/cfg_test5.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
@@ -7,4 +7,4 @@ box.cfg{
 }
 
 require('console').listen(os.getenv('ADMIN'))
-box.schema.user.grant('guest', 'read,write,execute', 'universe')
\ No newline at end of file
+box.schema.user.grant('guest', 'read,write,execute', 'universe')
diff --git a/test/box/lua/cfg_test6.lua b/test/box/lua/cfg_test6.lua
index efcfc6f3e..0a5859bc5 100644
--- a/test/box/lua/cfg_test6.lua
+++ b/test/box/lua/cfg_test6.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen = os.getenv("LISTEN"),
diff --git a/test/box/lua/fifo.lua b/test/box/lua/fifo.lua
index bb3446179..c9216cfde 100644
--- a/test/box/lua/fifo.lua
+++ b/test/box/lua/fifo.lua
@@ -4,7 +4,7 @@ function find_or_create_fifo(space, name)
     local fifo = space:get{name}
     if fifo == nil then
         fifo = {}
-        for i = 1, fifomax do table.insert(fifo, 0) end
+        for _ = 1, fifomax do table.insert(fifo, 0) end
         fifo = space:insert{name, 4, 4, unpack(fifo)}
     end
     return fifo
diff --git a/test/box/lua/identifier.lua b/test/box/lua/identifier.lua
index 0cfb9e722..c42840aaf 100644
--- a/test/box/lua/identifier.lua
+++ b/test/box/lua/identifier.lua
@@ -1,6 +1,6 @@
-max_len_string = string.rep('a', box.schema.NAME_MAX)
+local max_len_string = string.rep('a', box.schema.NAME_MAX)
 
-valid_testcases = {
+local valid_testcases = {
     --[[ Symbols from various unicode groups ,, --]]
     "1", "_", "sd", "я", "Ё",
     ".", "@", "#" , "⁋", "☢",
@@ -13,7 +13,7 @@ valid_testcases = {
     "⧭", "⭓", max_len_string
 }
 
-invalid_testcases = {
+local invalid_testcases = {
     --[[ Invalid and non printable unicode sequences --]]
     --[[ 1-3 ASCII control, C0 --]]
     "\x01", "\x09", "\x1f",
@@ -35,7 +35,6 @@ invalid_testcases = {
 }
 
 function run_test(create_func, cleanup_func)
-    local json = require("json")
     local bad_tests = {}
     for i, identifier in ipairs(valid_testcases) do
         local ok, res = pcall(create_func,identifier)
@@ -48,7 +47,7 @@ function run_test(create_func, cleanup_func)
         end
     end
     for i, identifier in ipairs(invalid_testcases) do
-        local ok, res = pcall(create_func,identifier)
+        local ok, _ = pcall(create_func,identifier)
         if ok then
             table.insert(bad_tests, "invalid_testcases: "..i)
         end
diff --git a/test/box/lua/index_random_test.lua b/test/box/lua/index_random_test.lua
index 7b5256a7c..83e230216 100644
--- a/test/box/lua/index_random_test.lua
+++ b/test/box/lua/index_random_test.lua
@@ -7,7 +7,7 @@ function index_random_test(space, index_no)
 	-- insert values into the index
 	for k=1,COUNT,1 do space:insert{k}  end
 	-- delete some values from the index
-	for i=1,COUNT/2,1 do
+	for _=1,COUNT/2,1 do
 		local k = math.random(COUNT)
 		local tuple = space:delete{k}
 		if tuple ~= nil then COUNT = COUNT - 1 end
diff --git a/test/box/lua/require_init.lua b/test/box/lua/require_init.lua
index c9ab07dce..8a2b477cc 100644
--- a/test/box/lua/require_init.lua
+++ b/test/box/lua/require_init.lua
@@ -1,5 +1,2 @@
 #!/usr/bin/env tarantool
 box.load_cfg()
-mod = require("require_mod")
-package_path = package.path
-package_cpath = package.cpath
diff --git a/test/box/lua/test_init.lua b/test/box/lua/test_init.lua
index 88cc3acdc..3823a0d13 100644
--- a/test/box/lua/test_init.lua
+++ b/test/box/lua/test_init.lua
@@ -1,15 +1,15 @@
 #!/usr/bin/env tarantool
 box.load_cfg()
 -- testing start-up script
-floor = require("math").floor
+require("math").floor
 
 --
 -- Access to box.cfg from start-up script
 --
 
-box_cfg = box.cfg()
+local box_cfg = box.cfg()
 
-function print_config()
+local function print_config()
 	return box_cfg
 end
 
@@ -24,10 +24,10 @@ local function do_insert()
     box.space[0]:insert{1, 2, 4, 8}
 end
 
-space = box.schema.create_space('tweedledum', { id = 0 })
+local space = box.schema.create_space('tweedledum', { id = 0 })
 space:create_index('primary', { type = 'hash' })
 
-fiber = box.fiber.create(do_insert)
+local fiber = box.fiber.create(do_insert)
 box.fiber.resume(fiber)
 
 --
diff --git a/test/box/lua/utils.lua b/test/box/lua/utils.lua
index 5f859fd19..fd562b767 100644
--- a/test/box/lua/utils.lua
+++ b/test/box/lua/utils.lua
@@ -22,8 +22,7 @@ function iterate(space_no, index_no, f1, f2, iterator, ...)
 			return f
 		end
 	end
-	local state, v
-	for state, v in box.space[space_no].index[index_no]:pairs({...}, { iterator = iterator }) do
+	for _, v in box.space[space_no].index[index_no]:pairs({...}, { iterator = iterator }) do
 		local pk = get_field(v, 1);
 		local tk = '$';
 		for f = f1 + 1, f2, 1 do tk = (tk..(get_field(v, f))..'$'); end;
@@ -90,7 +89,7 @@ end;
 
 -- return string tuple
 function tuple_to_string(tuple, yaml)
-    ans = '['
+    local ans = '['
     for i = 0, #tuple - 1 do
         if #i == 4 then
             ans = ans..i
@@ -205,17 +204,17 @@ function space_bsize(s)
 end
 
 function create_iterator(obj, key, opts)
-    local iter, key, state = obj:pairs(key, opts)
+    local iter, state
+    iter, key, state = obj:pairs(key, opts)
     local res = {iter = iter, key = key, state = state}
     res.next = function()
-        local st, tp = iter.gen(key, state)
+        local _, tp = iter.gen(key, state)
         return tp
     end
     res.iterate_over = function()
-        local tp = nil
         local ret = {}
         local i = 0
-        tp = res.next()
+        local tp = res.next()
         while tp do
             ret[i] = tp
             i = i + 1
diff --git a/test/box/on_schema_init.lua b/test/box/on_schema_init.lua
index 17cf89166..f74d6d7fe 100644
--- a/test/box/on_schema_init.lua
+++ b/test/box/on_schema_init.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 function test_before_replace_trig(old, new)
     -- return multiple values so that the stack fills earlier.
diff --git a/test/box/proxy.lua b/test/box/proxy.lua
index 8bbd505f8..c763e9634 100644
--- a/test/box/proxy.lua
+++ b/test/box/proxy.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/tiny.lua b/test/box/tiny.lua
index 04b523fb2..608d48366 100644
--- a/test/box/tiny.lua
+++ b/test/box/tiny.lua
@@ -1,5 +1,5 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
 box.cfg{
     listen              = os.getenv("LISTEN"),
diff --git a/test/box/tree_pk.result b/test/box/tree_pk.result
index df3c78bed..f2a4f5352 100644
--- a/test/box/tree_pk.result
+++ b/test/box/tree_pk.result
@@ -153,8 +153,8 @@ test_run:cmd("setopt delimiter ';'")
 ...
 function crossjoin(space0, space1, limit)
     local result = {}
-    for state, v0 in space0:pairs() do
-        for state, v1 in space1:pairs() do
+    for _, v0 in space0:pairs() do
+        for _, v1 in space1:pairs() do
             if limit <= 0 then
                 return result
             end
diff --git a/test/box/tree_pk.test.lua b/test/box/tree_pk.test.lua
index 1190ab424..86041a642 100644
--- a/test/box/tree_pk.test.lua
+++ b/test/box/tree_pk.test.lua
@@ -58,8 +58,8 @@ test_run = env.new()
 test_run:cmd("setopt delimiter ';'")
 function crossjoin(space0, space1, limit)
     local result = {}
-    for state, v0 in space0:pairs() do
-        for state, v1 in space1:pairs() do
+    for _, v0 in space0:pairs() do
+        for _, v1 in space1:pairs() do
             if limit <= 0 then
                 return result
             end
-- 
2.23.0



More information about the Tarantool-patches mailing list