Tarantool development patches archive
 help / color / mirror / Atom feed
From: sergeyb@tarantool.org
To: tarantool-patches@dev.tarantool.org, v.shpilevoy@tarantool.org,
	imun@tarantool.org
Cc: alexander.turenko@tarantool.org
Subject: [Tarantool-patches] [PATCH 03/19] Fix luacheck warnings in test/box
Date: Thu, 16 Jul 2020 17:11:24 +0300	[thread overview]
Message-ID: <f09023d1c2f48db3d048bcd663d2bc50dec542ab.1594907318.git.sergeyb@tarantool.org> (raw)
In-Reply-To: <cover.1594907318.git.sergeyb@tarantool.org>

From: Sergey Bronnikov <sergeyb@tarantool.org>

Part of #4681

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

Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Co-authored-by: Igor Munkin <imun@tarantool.org>
---
 .luacheckrc                        | 58 +++++++++++++++++++++++++++++-
 test/box/box.lua                   |  7 ++--
 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         |  2 +-
 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/utils.lua             | 10 +++---
 test/box/on_schema_init.lua        |  8 ++---
 test/box/proxy.lua                 |  2 +-
 test/box/tiny.lua                  |  2 +-
 18 files changed, 87 insertions(+), 36 deletions(-)

diff --git a/.luacheckrc b/.luacheckrc
index 358789457..4ed6734a7 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -34,7 +34,13 @@ exclude_files = {
     "src/box/lua/serpent.lua",
     "test-run/**/*.lua",
     "test/app/*.test.lua",
-    "test/box/**/*.lua",
+    "test/box/*.test.lua",
+    -- Unused source file, to be dropped (gh-5169).
+    "test/box/lua/require_init.lua",
+    -- Unused source file, to be dropped (gh-5169).
+    "test/box/lua/require_mod.lua",
+    -- Unused source file, to be dropped (gh-5169).
+    "test/box/lua/test_init.lua",
     "test/box-py/**/*.lua",
     "test/box-tap/**/*.lua",
     "test/engine/**/*.lua",
@@ -84,3 +90,53 @@ files["test/app-tap/string.test.lua"] = {
 files["test/app/lua/fiber.lua"] = {
     globals = {"box_fiber_run_test"}
 }
+files["test/box/box.lua"] = {
+    globals = {
+        "cfg_filter",
+        "sorted",
+        "iproto_request",
+    }
+}
+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 = {
+        "arithmetic",
+        "check_space",
+        "create_iterator",
+        "iterate",
+        "setmap",
+        "sort",
+        "space_field_types",
+        "space_bsize",
+        "table_generate",
+        "table_shuffle",
+        "tuple_to_string",
+    }
+}
+files["test/box/lua/bitset.lua"] = {
+    globals = {
+        "clear",
+        "create_space",
+        "delete",
+        "drop_space",
+        "dump",
+        "fill",
+        "test_insert_delete",
+    }
+}
+files["test/box/lua/fifo.lua"] = {
+    globals = {
+        "fifomax",
+        "fifo_push",
+        "fifo_top",
+        "find_or_create_fifo",
+    }
+}
+files["test/box/lua/identifier.lua"] = {
+     globals = {"run_test"}
+}
diff --git a/test/box/box.lua b/test/box/box.lua
index 6fad07015..72b116dfd 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')
 
@@ -19,7 +19,7 @@ local _hide = {
 
 function cfg_filter(data)
     if type(data)~='table' then return data end
-    local keys,k,_ = {}
+    local keys = {}
     for k in pairs(data) do
         table.insert(keys, k)
     end
@@ -50,7 +50,8 @@ function iproto_request(socket, query_header, query_body)
     assert(size ~= nil, 'Failed to read response')
     size = msgpack.decode(size)
     local response = socket:read(size)
-    local header, header_len = msgpack.decode(response)
+    local header_len
+    header, header_len = msgpack.decode(response)
     body = msgpack.decode(response:sub(header_len))
     return {
         ['header'] = header,
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..d462c3bbc 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"),
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..3103239ad 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/utils.lua b/test/box/lua/utils.lua
index 5f859fd19..a6185fbd0 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
@@ -208,14 +207,13 @@ function create_iterator(obj, key, opts)
     local 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..a10687a09 100644
--- a/test/box/on_schema_init.lua
+++ b/test/box/on_schema_init.lua
@@ -1,12 +1,12 @@
 #!/usr/bin/env tarantool
-os = require('os')
+local os = require('os')
 
-function test_before_replace_trig(old, new)
+local function test_before_replace_trig(old, new) -- luacheck: no unused args
     -- return multiple values so that the stack fills earlier.
     return new:update{{'+', 2, 1}}, new:update{{'+', 2, 1}}, new:update{{'+', 2, 1}}, new:update{{'+', 2, 1}}
 end
 
-function space_on_replace_trig(old, new)
+local function space_on_replace_trig(old, new) -- luacheck: no unused args
     if new and new[3] == 'test_on_schema_init' then
         box.on_commit(function()
             box.space.test_on_schema_init:before_replace(test_before_replace_trig)
@@ -14,7 +14,7 @@ function space_on_replace_trig(old, new)
     end
 end
 
-function on_init_trig()
+local function on_init_trig()
     box.space._space:on_replace(space_on_replace_trig)
 end
 
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"),
-- 
2.26.2

  parent reply	other threads:[~2020-07-16 14:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 14:11 [Tarantool-patches] [PATCH 00/19] Add static analysis of Lua code in test/ with luacheck sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 01/19] Fix luacheck warnings in test/app-tap sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 02/19] Fix luacheck warnings in test/app sergeyb
2020-07-16 14:11 ` sergeyb [this message]
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 04/19] Fix luacheck warnings in test/box-py sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 05/19] Fix luacheck warnings in test/box-tap sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 06/19] Fix luacheck warnings in test/engine sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 07/19] Fix luacheck warnings in test/engine_long sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 08/19] Fix luacheck warnings in test/long_run-py sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 09/19] Fix luacheck warnings in test/replication sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 10/19] Fix luacheck warnings in test/replication-py sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 11/19] Fix luacheck warnings in test/sql sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 12/19] Fix luacheck warnings in test/sql-tap sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 13/19] Fix luacheck warnings in test/swim sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 14/19] Fix luacheck warnings in test/vinyl sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 15/19] Fix luacheck warnings in test/wal_off sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 16/19] Fix luacheck warnings in test/xlog sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 17/19] Fix luacheck warnings in test/xlog-py sergeyb
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 18/19] Add luacheck supression for luajit test sergeyb
2020-07-20 19:46   ` Igor Munkin
2020-07-21 11:52     ` Sergey Bronnikov
2020-07-21 12:38       ` Igor Munkin
2020-07-16 14:11 ` [Tarantool-patches] [PATCH 19/19] luajit: bump new version sergeyb
2020-07-16 14:18 ` [Tarantool-patches] [PATCH] test: fix warnings spotted by luacheck sergeyb
2020-07-20 18:26   ` Igor Munkin
2020-10-30 13:59   ` Kirill Yukhin
2020-07-17  8:09 ` [Tarantool-patches] [PATCH 00/19] Add static analysis of Lua code in test/ with luacheck Sergey Bronnikov
2020-08-07  9:19 ` Igor Munkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f09023d1c2f48db3d048bcd663d2bc50dec542ab.1594907318.git.sergeyb@tarantool.org \
    --to=sergeyb@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=imun@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 03/19] Fix luacheck warnings in test/box' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox