[Tarantool-patches] [PATCH] Fix luacheck warnings in src/lua/*.lua

Sergey Bronnikov sergeyb at tarantool.org
Fri Apr 3 12:39:02 MSK 2020


GitHub branch: https://github.com/tarantool/tarantool/tree/ligurio/gh-4681-fix-luacheck-warnings

How-to check:

$ tarantoolctl rocks install luacheck
$ .rocks/bin/luacheck src/lua/*.lua

---
 src/lua/argparse.lua   |  6 ++--
 src/lua/buffer.lua     |  4 +--
 src/lua/clock.lua      |  2 +-
 src/lua/crypto.lua     | 18 +++++-----
 src/lua/csv.lua        |  5 ++-
 src/lua/digest.lua     |  6 ++--
 src/lua/env.lua        |  2 +-
 src/lua/errno.lua      |  2 +-
 src/lua/fio.lua        | 28 ++++++++--------
 src/lua/help.lua       | 24 +++++++-------
 src/lua/httpc.lua      |  3 --
 src/lua/init.lua       | 17 +++++-----
 src/lua/msgpackffi.lua | 15 ++++-----
 src/lua/socket.lua     | 66 ++++++++++++++++++-------------------
 src/lua/string.lua     |  1 -
 src/lua/swim.lua       | 20 +++++------
 src/lua/tap.lua        | 75 ++++++++++++++++++++----------------------
 src/lua/trigger.lua    |  3 --
 18 files changed, 142 insertions(+), 155 deletions(-)

diff --git a/src/lua/argparse.lua b/src/lua/argparse.lua
index faa0ae130..f58985425 100644
--- a/src/lua/argparse.lua
+++ b/src/lua/argparse.lua
@@ -90,8 +90,8 @@ local function convert_parameter(name, convert_from, convert_to)
     return convert_from
 end
 
-local function parameters_parse(t_in, options)
-    local t_out, t_in = {}, t_in or {}
+local function parameters_parse(t__in, options)
+    local t_out, t_in = {}, t__in or {}
 
     -- Prepare a lookup table for options. An option name -> a
     -- type name to convert a parameter into or true (which means
@@ -145,7 +145,7 @@ local function parameters_parse(t_in, options)
                 if parameter_has_value(lookup[command]) then
                     -- in case next argument is value of this key (not --arg)
                     local next_arg = t_in[i + 1]
-                    local is_long, is_short, is_dash = parse_param_prefix(next_arg)
+                    is_long, is_short, is_dash = parse_param_prefix(next_arg)
                     if is_dash then
                         skip_param = true
                     elseif is_long == false and not is_short and not is_dash then
diff --git a/src/lua/buffer.lua b/src/lua/buffer.lua
index 9aac82b39..5979980ed 100644
--- a/src/lua/buffer.lua
+++ b/src/lua/buffer.lua
@@ -182,7 +182,7 @@ local ibuf_methods = {
     unused = ibuf_unused;
 }
 
-local function ibuf_tostring(ibuf)
+local function ibuf_tostring(ibuf) -- luacheck: ignore 212
     return '<ibuf>'
 end
 local ibuf_mt = {
@@ -193,7 +193,7 @@ local ibuf_mt = {
 
 ffi.metatype(ibuf_t, ibuf_mt);
 
-local function ibuf_new(arg, arg2)
+local function ibuf_new(arg)
     local buf = ffi.new(ibuf_t)
     local slabc = builtin.tarantool_lua_slab_cache()
     builtin.ibuf_create(buf, slabc, READAHEAD)
diff --git a/src/lua/clock.lua b/src/lua/clock.lua
index 60c78663c..fee43ccde 100644
--- a/src/lua/clock.lua
+++ b/src/lua/clock.lua
@@ -33,7 +33,7 @@ clock.bench = function(fun, ...)
     overhead = clock.proc() - overhead
     local start_time = clock.proc()
     local res = {0, fun(...)}
-    res[1] = clock.proc() - start_time - overhead, res
+    res[1] = clock.proc() - start_time - overhead
     return res
 end
 
diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua
index bf3064c70..9929b93ba 100644
--- a/src/lua/crypto.lua
+++ b/src/lua/crypto.lua
@@ -75,7 +75,7 @@ local function openssl_err_str()
 end
 
 local digests = {}
-for class, name in pairs({
+for class, _ in pairs({
     md2 = 'MD2', md4 = 'MD4', md5 = 'MD5',
     sha1 = 'SHA1', sha224 = 'SHA224',
     sha256 = 'SHA256', sha384 = 'SHA384', sha512 = 'SHA512',
@@ -318,7 +318,7 @@ for class, digest in pairs(digests) do
     digest_api[class] = setmetatable({
         new = function () return digest_new(digest) end
     }, {
-        __call = function (self, str)
+        __call = function (self, str) -- luacheck: ignore 212
             if type(str) ~= 'string' then
                 error("Usage: digest."..class.."(string)")
             end
@@ -332,7 +332,7 @@ for class, digest in pairs(digests) do
 end
 
 digest_api = setmetatable(digest_api,
-    {__index = function(self, digest)
+    {__index = function(self, digest) -- luacheck: ignore 212
         return error('Digest method "' .. digest .. '" is not supported')
     end })
 
@@ -341,7 +341,7 @@ for class, digest in pairs(hmacs) do
     hmac_api[class] = setmetatable({
         new = function (key) return hmac_new(digest, key) end
     }, {
-        __call = function (self, key, str)
+        __call = function (self, key, str) -- luacheck: ignore 212
             if type(str) ~= 'string' then
                 error("Usage: hmac."..class.."(key, string)")
             end
@@ -361,7 +361,7 @@ for class, digest in pairs(hmacs) do
 end
 
 hmac_api = setmetatable(hmac_api,
-    {__index = function(self, digest)
+    {__index = function(self, digest) -- luacheck: ignore 212
         return error('HMAC method "' .. digest .. '" is not supported')
     end })
 
@@ -384,12 +384,12 @@ local crypto_dirs = {
 }
 
 local algo_api_mt = {
-    __index = function(self, mode)
+    __index = function(self, mode) -- luacheck: ignore 212
         error('Cipher mode ' .. mode .. ' is not supported')
     end
 }
 local crypto_api_mt = {
-    __index = function(self, cipher)
+    __index = function(self, cipher) -- luacheck: ignore 212
         return error('Cipher method "' .. cipher .. '" is not supported')
     end
 }
@@ -408,7 +408,7 @@ for algo_name, algo_value in pairs(crypto_algos) do
                                              dir_value)
                 end
             }, {
-                __call = function(self, str, key, iv)
+                __call = function(self, str, key, iv) -- luacheck: ignore 212
                     local ctx = crypto_stream_new(algo_value, mode_value, key,
                                                   iv, dir_value)
                     local res = ctx:update(str)
@@ -428,7 +428,7 @@ local public_methods = {
 }
 
 local module_mt = {
-    __serialize = function(s)
+    __serialize = function()
         return public_methods
     end,
     __index = public_methods
diff --git a/src/lua/csv.lua b/src/lua/csv.lua
index 7dff2f213..de6726bb7 100644
--- a/src/lua/csv.lua
+++ b/src/lua/csv.lua
@@ -188,10 +188,10 @@ module.dump = function(t, opts, writable)
     if type(writable) == 'nil' then
         result_table = {}
     end
-    for k, line in pairs(t) do
+    for _, line in pairs(t) do
         local first = true
         local output_tuple = {}
-        for k2, field in pairs(line) do
+        for _, field in pairs(line) do
             local strf = tostring(field)
             local buf_new_size = (strf:len() + 1) * 2
             if buf_new_size > bufsz then
@@ -214,7 +214,6 @@ module.dump = function(t, opts, writable)
         else
             writable:write(table.concat(output_tuple))
         end
-        output_tuple = {}
     end
     ffi.C.csv_destroy(csv)
     csv.realloc(buf, 0)
diff --git a/src/lua/digest.lua b/src/lua/digest.lua
index 6ed91cfa2..5c6eb2ae2 100644
--- a/src/lua/digest.lua
+++ b/src/lua/digest.lua
@@ -91,7 +91,7 @@ PMurHash = {
 }
 
 setmetatable(PMurHash, {
-    __call = function(self, str)
+    __call = function(self, str) -- luacheck: ignore 212
         if type(str) ~= 'string' then
             error("Usage: digest.murhash(string)")
         end
@@ -134,7 +134,7 @@ CRC32 = {
 }
 
 setmetatable(CRC32, {
-    __call = function(self, str)
+    __call = function(self, str) -- luacheck: ignore 212
         if type(str) ~= 'string' then
             error("Usage digest.crc32(string)")
         end
@@ -246,7 +246,7 @@ local m = {
     end
 }
 
-for digest, name in pairs(digest_shortcuts) do
+for digest, _ in pairs(digest_shortcuts) do
     m[digest] = function (str)
         return crypto.digest[digest](str)
     end
diff --git a/src/lua/env.lua b/src/lua/env.lua
index dd1616a84..d851586f0 100644
--- a/src/lua/env.lua
+++ b/src/lua/env.lua
@@ -28,7 +28,7 @@ os.environ = function()
 end
 
 os.setenv = function(key, value)
-    local rv = nil
+    local rv = nil -- luacheck: ignore 311
     if value ~= nil then
         rv = ffi.C.setenv(key, value, 1)
     else
diff --git a/src/lua/errno.lua b/src/lua/errno.lua
index db800ce30..c91cad4b7 100644
--- a/src/lua/errno.lua
+++ b/src/lua/errno.lua
@@ -17,5 +17,5 @@ return setmetatable({
 }, {
     __index = errno_list,
     __newindex = function() error("Can't create new errno constants") end,
-    __call = function(self, ...) return ffi.errno(...) end
+    __call = function(self, ...) return ffi.errno(...) end -- luacheck: ignore 212
 })
diff --git a/src/lua/fio.lua b/src/lua/fio.lua
index 4692e1026..dd71c6742 100644
--- a/src/lua/fio.lua
+++ b/src/lua/fio.lua
@@ -306,7 +306,7 @@ fio.abspath = function(path)
         error("Usage: fio.abspath(path)")
     end
     path = path
-    local joined_path = ''
+    local joined_path = '' -- luacheck: ignore 311
     local path_tab = {}
     if string.sub(path, 1, 1) == '/' then
         joined_path = path
@@ -343,7 +343,7 @@ fio.listdir = function(path)
         return t
     end
     local names = string.split(str, "\n")
-    for i, name in ipairs(names) do
+    for _, name in ipairs(names) do
         table.insert(t, name)
     end
     return t
@@ -355,15 +355,15 @@ fio.mktree = function(path, mode)
     end
     path = fio.abspath(path)
 
-    local path = string.gsub(path, '^/', '')
+    path = string.gsub(path, '^/', '')
     local dirs = string.split(path, "/")
 
     local current_dir = "/"
-    for i, dir in ipairs(dirs) do
+    for _, dir in ipairs(dirs) do
         current_dir = fio.pathjoin(current_dir, dir)
         local stat = fio.stat(current_dir)
         if stat == nil then
-            local st, err = fio.mkdir(current_dir, mode)
+            local _, err = fio.mkdir(current_dir, mode)
             -- fio.stat() and fio.mkdir() above are separate calls
             -- and a file system may be changed between them. So
             -- if the error here is due to an existing directory,
@@ -384,20 +384,20 @@ fio.rmtree = function(path)
     if type(path) ~= 'string' then
         error("Usage: fio.rmtree(path)")
     end
-    local status, err
+    local status -- luacheck: ignore 231
     path = fio.abspath(path)
     local ls, err = fio.listdir(path)
     if err ~= nil then
         return nil, err
     end
-    for i, f in ipairs(ls) do
+    for _, f in ipairs(ls) do
         local tmppath = fio.pathjoin(path, f)
         local st = fio.lstat(tmppath)
         if st then
             if st:is_dir() then
-                st, err = fio.rmtree(tmppath)
+                _, err = fio.rmtree(tmppath)
             else
-                st, err = fio.unlink(tmppath)
+                _, err = fio.unlink(tmppath)
             end
             if err ~= nil  then
                 return nil, err
@@ -430,7 +430,6 @@ fio.copytree = function(from, to)
     if type(from) ~= 'string' or type(to) ~= 'string' then
         error('Usage: fio.copytree(from, to)')
     end
-    local status, reason
     local st = fio.stat(from)
     if not st then
         return false, string.format("Directory %s does not exist", from)
@@ -444,14 +443,14 @@ fio.copytree = function(from, to)
     end
 
     -- create tree of destination
-    status, reason = fio.mktree(to)
+    local status, reason = fio.mktree(to) -- luacheck: ignore 231
     if reason ~= nil then
         return false, reason
     end
-    for i, f in ipairs(ls) do
+    for _, f in ipairs(ls) do
         local ffrom = fio.pathjoin(from, f)
         local fto = fio.pathjoin(to, f)
-        local st = fio.lstat(ffrom)
+        st = fio.lstat(ffrom)
         if st and st:is_dir() then
             status, reason = fio.copytree(ffrom, fto)
             if reason ~= nil then
@@ -465,7 +464,8 @@ fio.copytree = function(from, to)
             end
         end
         if st:is_link() then
-            local link_to, reason = fio.readlink(ffrom)
+            local link_to
+            link_to, reason = fio.readlink(ffrom)
             if reason ~= nil then
                 return false, reason
             end
diff --git a/src/lua/help.lua b/src/lua/help.lua
index 54ff1b5d0..768f4dec4 100644
--- a/src/lua/help.lua
+++ b/src/lua/help.lua
@@ -7,22 +7,22 @@ local doc = require('help.en_US')
 -- corresponds to a tarantool version a user runs.
 local DOCUMENTATION_VERSION = '2.1'
 
-help = { doc.help }
-tutorial = {}
-tutorial[1] = help[1]
+help = { doc.help } -- luacheck: ignore 111
+tutorial = {} -- luacheck: ignore 111
+tutorial[1] = help[1] -- luacheck: ignore 112 113
 
-local help_function_data = {};
-local help_object_data = {}
+local help_function_data = {}; -- luacheck: ignore 211
+local help_object_data = {} -- luacheck: ignore 211
 
-local function help_call(table, param)
-    return help
+local function help_call(table, param) -- luacheck: ignore 212
+    return help -- luacheck: ignore 113
 end
 
-setmetatable(help, { __call = help_call })
+setmetatable(help, { __call = help_call }) -- luacheck: ignore 113
 
 local screen_id = 1;
 
-local function tutorial_call(table, action)
+local function tutorial_call(table, action) -- luacheck: ignore 212
     if action == 'start' then
         screen_id = 1;
     elseif action == 'next' or action == 'more' then
@@ -46,9 +46,9 @@ local function tutorial_call(table, action)
     return (res:gsub('<version>', DOCUMENTATION_VERSION))
 end
 
-setmetatable(tutorial, { __call = tutorial_call })
+setmetatable(tutorial, { __call = tutorial_call }) -- luacheck: ignore 113
 
 return {
-    help = help;
-    tutorial = tutorial;
+    help = help; -- luacheck: ignore 113
+    tutorial = tutorial; -- luacheck: ignore 113
 }
diff --git a/src/lua/httpc.lua b/src/lua/httpc.lua
index 6381c6a1a..9336dcee0 100644
--- a/src/lua/httpc.lua
+++ b/src/lua/httpc.lua
@@ -29,8 +29,6 @@
 --  SUCH DAMAGE.
 --
 
-local fiber = require('fiber')
-
 local driver = package.loaded.http.client
 package.loaded.http = nil
 
@@ -112,7 +110,6 @@ local special_characters = {
     [']'] = true,
     ['<'] = true,
     ['>'] = true,
-    ['>'] = true,
     ['@'] = true,
     [','] = true,
     [';'] = true,
diff --git a/src/lua/init.lua b/src/lua/init.lua
index ff3e74c3c..b075915a3 100644
--- a/src/lua/init.lua
+++ b/src/lua/init.lua
@@ -71,7 +71,7 @@ local function setsearchroot(path)
     package_searchroot = path and fio.abspath(path)
 end
 
-dostring = function(s, ...)
+dostring = function(s, ...) -- luacheck: ignore 121
     local chunk, message = loadstring(s)
     if chunk == nil then
         error(message, 2)
@@ -80,7 +80,7 @@ dostring = function(s, ...)
 end
 
 local fiber = require("fiber")
-os.exit = function(code)
+os.exit = function(code) -- luacheck: ignore 122
     code = (type(code) == 'number') and code or 0
     ffi.C.tarantool_exit(code)
     -- Make sure we yield even if the code after
@@ -144,9 +144,9 @@ local function gen_search_func(path_fn, templates, need_traverse)
 
         local searchpaths = {}
 
-        for _, path in ipairs(paths) do
+        for _, p in ipairs(paths) do
             for _, template in pairs(templates) do
-                table.insert(searchpaths, fio.pathjoin(path, template))
+                table.insert(searchpaths, fio.pathjoin(p, template))
             end
         end
 
@@ -176,7 +176,8 @@ local function gen_loader_func(search_fn, load_fn)
         if not file then
             return err
         end
-        local loaded, err = load_fn(file, name)
+        local loaded
+        loaded, err = load_fn(file, name)
         if err == nil then
             return loaded
         else
@@ -221,9 +222,9 @@ table.insert(package.loaders, 5, gen_loader_func(search_rocks_lib, load_lib))
 -- package.cpath  7
 -- croot          8
 
-package.search = search
-package.searchroot = searchroot
-package.setsearchroot = setsearchroot
+package.search = search -- luacheck: ignore 122
+package.searchroot = searchroot -- luacheck: ignore 122
+package.setsearchroot = setsearchroot -- luacheck: ignore 122
 
 return {
     uptime = uptime;
diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua
index f775f2d41..471b72c84 100644
--- a/src/lua/msgpackffi.lua
+++ b/src/lua/msgpackffi.lua
@@ -291,7 +291,7 @@ local function encode(obj)
     return r
 end
 
-local function encode_ibuf(obj, ibuf)
+local function encode_ibuf(obj, ibuf) -- luacheck: ignore 211
     encode_r(ibuf, obj, 0)
 end
 
@@ -320,7 +320,7 @@ local decode_r
 
 -- See similar constants in utils.cc
 local DBL_INT_MAX = 1e14 - 1
-local DBL_INT_MIN = -1e14 + 1
+local DBL_INT_MIN = -1e14 + 1 -- luacheck: ignore 211
 
 local function decode_u8(data)
     local num = ffi.cast(uint8_ptr_t, data[0])[0]
@@ -465,8 +465,7 @@ end
 local function decode_array(data, size)
     assert (type(size) == "number")
     local arr = {}
-    local i
-    for i=1,size,1 do
+    for i=1,size,1 do -- luacheck: ignore 213
         table.insert(arr, decode_r(data))
     end
     if not msgpack.cfg.decode_save_metatables then
@@ -478,8 +477,7 @@ end
 local function decode_map(data, size)
     assert (type(size) == "number")
     local map = {}
-    local i
-    for i=1,size,1 do
+    for i=1,size,1 do -- luacheck: ignore 213
         local key = decode_r(data);
         local val = decode_r(data);
         map[key] = val
@@ -492,7 +490,7 @@ end
 
 local ext_decoder = {
     -- MP_UNKNOWN_EXTENSION
-    [0] = function(data, len) error("unsupported extension type") end,
+    [0] = function() error("unsupported extension type") end,
     -- MP_DECIMAL
     [1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end,
 }
@@ -502,7 +500,6 @@ local function decode_ext(data)
     -- mp_decode_extl and mp_decode_decimal
     -- need type code
     data[0] = data[0] - 1
-    local old_data = data[0]
     local len = builtin.mp_decode_extl(data, t)
     local fun = ext_decoder[t[0]]
     if type(fun) == 'function' then
@@ -589,7 +586,7 @@ local function check_offset(offset, len)
     if offset == nil then
         return 1
     end
-    local offset = ffi.cast('ptrdiff_t', offset)
+    offset = ffi.cast('ptrdiff_t', offset)
     if offset < 1 or offset > len then
         error(string.format("offset = %d is out of bounds [1..%d]",
             tonumber(offset), len))
diff --git a/src/lua/socket.lua b/src/lua/socket.lua
index a334ad45b..c5691a425 100644
--- a/src/lua/socket.lua
+++ b/src/lua/socket.lua
@@ -172,7 +172,7 @@ local function get_iflags(table, flags)
     if type(flags) ~= 'table' then
         flags = { flags }
     end
-    for i, f in pairs(flags) do
+    for _, f in pairs(flags) do
         if table[f] == nil then
             return nil
         end
@@ -660,7 +660,7 @@ local function check_delimiter(self, limit, eols)
     end
 
     local shortest
-    for i, eol in ipairs(eols) do
+    for _, eol in ipairs(eols) do
         local data = ffi.C.memmem(rbuf.rpos, rbuf:size(), eol, #eol)
         if data ~= nil then
             local len = ffi.cast('char *', data) - rbuf.rpos + #eol
@@ -706,16 +706,16 @@ local function read(self, limit, timeout, check, ...)
         local res = sysread(self, data, rbuf:unused())
         if res == 0 then -- eof
             self._errno = nil
-            local len = rbuf:size()
-            local data = ffi.string(rbuf.rpos, len)
+            len = rbuf:size()
+            data = ffi.string(rbuf.rpos, len)
             rbuf.rpos = rbuf.rpos + len
             return data
         elseif res ~= nil then
             rbuf.wpos = rbuf.wpos + res
-            local len = check(self, limit, ...)
+            len = check(self, limit, ...)
             if len ~= nil then
                 self._errno = nil
-                local data = ffi.string(rbuf.rpos, len)
+                data = ffi.string(rbuf.rpos, len)
                 rbuf.rpos = rbuf.rpos + len
                 return data
             end
@@ -1039,7 +1039,7 @@ local function tcp_connect(host, port, timeout)
         boxerrno(0)
         return s
     end
-    local timeout = timeout or TIMEOUT_INFINITY
+    timeout = timeout or TIMEOUT_INFINITY
     local stop = fiber.clock() + timeout
     local dns = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM',
         protocol = 'tcp' })
@@ -1047,7 +1047,7 @@ local function tcp_connect(host, port, timeout)
         boxerrno(boxerrno.EINVAL)
         return nil
     end
-    for i, remote in pairs(dns) do
+    for _, remote in pairs(dns) do
         timeout = stop - fiber.clock()
         if timeout <= 0 then
             boxerrno(boxerrno.ETIMEDOUT)
@@ -1078,8 +1078,8 @@ local function tcp_server_handler(server, sc, from)
     end
 end
 
-local function tcp_server_loop(server, s, addr)
-    fiber.name(format("%s/%s:%s", server.name, addr.host, addr.port), {truncate = true})
+local function tcp_server_loop(server, s, address)
+    fiber.name(format("%s/%s:%s", server.name, address.host, address.port), {truncate = true})
     log.info("started")
     while socket_readable(s) do
         local sc, from = socket_accept(s)
@@ -1104,15 +1104,15 @@ local function tcp_server_usage()
     error('Usage: socket.tcp_server(host, port, handler | opts)')
 end
 
-local function tcp_server_do_bind(s, addr)
-    if socket_bind(s, addr.host, addr.port) then
-        if addr.family == 'AF_UNIX' then
+local function tcp_server_do_bind(s, address)
+    if socket_bind(s, address.host, address.port) then
+        if address.family == 'AF_UNIX' then
             -- Make close() remove the unix socket file created
             -- by bind(). Note, this must be done before closing
             -- the socket fd so that no other tcp server can
             -- reuse the same path before we remove the file.
             s.close = function(self)
-                fio.unlink(addr.port)
+                fio.unlink(address.port)
                 return socket_close(self)
             end
         end
@@ -1121,12 +1121,12 @@ local function tcp_server_do_bind(s, addr)
     return false
 end
 
-local function tcp_server_bind_addr(s, addr)
-    if tcp_server_do_bind(s, addr) then
+local function tcp_server_bind_addr(s, address)
+    if tcp_server_do_bind(s, address) then
         return true
     end
 
-    if addr.family ~= 'AF_UNIX' then
+    if address.family ~= 'AF_UNIX' then
         return false
     end
 
@@ -1136,7 +1136,7 @@ local function tcp_server_bind_addr(s, addr)
 
     local save_errno = boxerrno()
 
-    local sc = tcp_connect(addr.host, addr.port)
+    local sc = tcp_connect(address.host, address.port)
     if sc ~= nil then
         sc:close()
         boxerrno(save_errno)
@@ -1148,13 +1148,13 @@ local function tcp_server_bind_addr(s, addr)
         return false
     end
 
-    log.info("tcp_server: remove dead UNIX socket: %s", addr.port)
-    if not fio.unlink(addr.port) then
+    log.info("tcp_server: remove dead UNIX socket: %s", address.port)
+    if not fio.unlink(address.port) then
         log.warn("tcp_server: %s", boxerrno.strerror())
         boxerrno(save_errno)
         return false
     end
-    return tcp_server_do_bind(s, addr)
+    return tcp_server_do_bind(s, address)
 end
 
 
@@ -1172,8 +1172,8 @@ local function tcp_server_bind(host, port, prepare, timeout)
         end
     end
 
-    for _, addr in ipairs(dns) do
-        local s = socket_new(addr.family, addr.type, addr.protocol)
+    for _, address in ipairs(dns) do
+        local s = socket_new(address.family, address.type, address.protocol)
         if s ~= nil then
             local backlog
             if prepare then
@@ -1181,13 +1181,13 @@ local function tcp_server_bind(host, port, prepare, timeout)
             else
                 socket_setsockopt(s, 'SOL_SOCKET', 'SO_REUSEADDR', 1) -- ignore error
             end
-            if not tcp_server_bind_addr(s, addr) or not s:listen(backlog) then
+            if not tcp_server_bind_addr(s, address) or not s:listen(backlog) then
                 local save_errno = boxerrno()
                 socket_close(s)
                 boxerrno(save_errno)
                 return nil
             end
-            return s, addr
+            return s, address
        end
     end
     -- DNS resolved successfully, but addresss family is not supported
@@ -1211,12 +1211,12 @@ local function tcp_server(host, port, opts, timeout)
         tcp_server_usage()
     end
     server.name = server.name or 'server'
-    local s, addr = tcp_server_bind(host, port, server.prepare, timeout)
+    local s, address = tcp_server_bind(host, port, server.prepare, timeout)
     if not s then
         return nil
     end
-    fiber.create(tcp_server_loop, server, s, addr)
-    return s, addr
+    fiber.create(tcp_server_loop, server, s, address)
+    return s, address
 end
 
 socket_mt   = {
@@ -1311,7 +1311,7 @@ local function lsocket_tcp_getpeername(self)
     return peer.host, tostring(peer.port), peer.family:match("AF_(.*)"):lower()
 end
 
-local function lsocket_tcp_settimeout(self, value, mode)
+local function lsocket_tcp_settimeout(self, value, mode) -- luacheck: ignore 212
     check_socket(self)
     self.timeout = value
     -- mode is effectively ignored
@@ -1467,7 +1467,7 @@ local function lsocket_tcp_receive(self, pattern, prefix)
         local result = { prefix }
         local deadline = fiber.clock() + (self.timeout or TIMEOUT_INFINITY)
         repeat
-            local data = read(self, LIMIT_INFINITY, timeout, check_infinity)
+            data = read(self, LIMIT_INFINITY, timeout, check_infinity)
             if data == nil then
                 if not errno_is_transient[self._errno] then
                     return nil, socket_error(self)
@@ -1535,7 +1535,7 @@ lsocket_tcp_mt.__index.send = lsocket_tcp_send;
 -- TCP Constructor and Shortcuts
 --
 
-local function lsocket_tcp()
+local function lsocket_tcp(self)
     local s = socket_new('AF_INET', 'SOCK_STREAM', 'tcp')
     if not s then
         return nil, socket_error(self)
@@ -1559,7 +1559,7 @@ local function lsocket_bind(host, port, backlog)
     if host == nil or port == nil then
         error("Usage: luasocket.bind(host, port [, backlog])")
     end
-    local function prepare(s) return backlog end
+    local function prepare() return backlog end
     local s = tcp_server_bind(host, port, prepare)
     if not s then
         return nil, boxerrno.strerror()
@@ -1578,7 +1578,7 @@ return setmetatable({
     iowait = internal.iowait,
     internal = internal,
 }, {
-    __call = function(self, ...) return socket_new(...) end;
+    __call = function(self, ...) return socket_new(...) end; -- luacheck: ignore 212
     __index = {
         tcp = lsocket_tcp;
         connect = lsocket_connect;
diff --git a/src/lua/string.lua b/src/lua/string.lua
index 6e12c59ae..d3a846645 100644
--- a/src/lua/string.lua
+++ b/src/lua/string.lua
@@ -233,7 +233,6 @@ local function string_startswith(inp, head, _start, _end)
         return false
     end
     _start = _start - 1
-    _end = _start + head_len - 1
     return memcmp(c_char_ptr(inp) + _start, c_char_ptr(head), head_len) == 0
 end
 
diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index 01eeb7eae..7fd2e8250 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -1,5 +1,5 @@
 local ffi = require('ffi')
-local uuid = require('uuid')
+local uuid_ = require('uuid')
 local buffer = require('buffer')
 local msgpack = require('msgpack')
 local crypto = require('crypto')
@@ -239,7 +239,7 @@ local function swim_check_uuid(value, func_name)
         end
         return error(func_name..': expected string UUID or struct tt_uuid')
     end
-    value = uuid.fromstr(value)
+    value = uuid_.fromstr(value)
     if not value then
         return error(func_name..': invalid UUID')
     end
@@ -370,7 +370,7 @@ end
 --
 local function swim_member_payload_str(m)
     local ptr = swim_check_member(m, 'member:payload_str()')
-    local cdata, size = swim_member_payload_raw(ptr)
+    local _, size = swim_member_payload_raw(ptr)
     if size > 0 then
         return ffi.string(swim_member_payload_raw(ptr))
     end
@@ -461,7 +461,7 @@ local swim_member_mt = {
         is_dropped = swim_member_is_dropped,
     },
     __serialize = swim_member_serialize,
-    __newindex = function(m)
+    __newindex = function()
         return error('swim_member is a read-only object')
     end
 }
@@ -781,20 +781,20 @@ local swim_member_event_mt = {
 --
 -- Create a closure function for preprocessing raw SWIM member
 -- event trigger parameters.
--- @param s SWIM instance.
+-- @param instance SWIM instance.
 -- @param callback User functions to call.
 -- @param ctx An optional parameter for @a callback passed as is.
 -- @return A function to set as a trigger.
 --
-local function swim_on_member_event_new(s, callback, ctx)
+local function swim_on_member_event_new(instance, callback, ctx)
     -- Do not keep a hard reference to a SWIM instance. Otherwise
     -- it is a cyclic reference, and both the instance and the
     -- trigger will never be GC-ed.
-    s = setmetatable({s}, {__mode = 'v'})
+    instance = setmetatable({instance}, {__mode = 'v'})
     return function(member_ptr, event_mask)
-        local s = s[1]
-        if s then
-            local m = swim_wrap_member(s, member_ptr)
+        local i = instance[1]
+        if i then
+            local m = swim_wrap_member(i, member_ptr)
             local event = setmetatable({event_mask}, swim_member_event_mt)
             return callback(m, event, ctx)
         end
diff --git a/src/lua/tap.lua b/src/lua/tap.lua
index 94b080d5a..04497386e 100644
--- a/src/lua/tap.lua
+++ b/src/lua/tap.lua
@@ -53,7 +53,7 @@ local function ok(test, cond, message, extra)
     io.write(string.format("not ok - %s\n", message))
     extra = extra or {}
     if test.trace then
-        local frame = debug.getinfo(3, "Sl")
+        debug.getinfo(3, "Sl")
         extra.trace = traceback()
         extra.filename = extra.trace[#extra.trace].filename
         extra.line = extra.trace[#extra.trace].line
@@ -76,9 +76,6 @@ local function skip(test, message, extra)
     ok(test, true, message.." # skip", extra)
 end
 
-
-local nan = 0/0
-
 local function cmpdeeply(got, expected, extra)
     if type(expected) == "number" or type(got) == "number" then
         extra.got = got
@@ -190,38 +187,38 @@ local function isboolean(test, v, message, extra)
     return is(test, type(v), 'boolean', message, extra)
 end
 
-local function isfunction(test, v, message, extra)
-    return is(test, type(v), 'function', message, extra)
+local function isfunction(testcase, v, message, extra)
+    return is(testcase, type(v), 'function', message, extra)
 end
 
-local function isudata(test, v, utype, message, extra)
+local function isudata(testcase, v, utype, message, extra)
     extra = extra or {}
     extra.expected = 'userdata<'..utype..'>'
     if type(v) == 'userdata' then
         extra.got = 'userdata<'..getmetatable(v)..'>'
-        return ok(test, getmetatable(v) == utype, message, extra)
+        return ok(testcase, getmetatable(v) == utype, message, extra)
     else
         extra.got = type(v)
-        return fail(test, message, extra)
+        return fail(testcase, message, extra)
     end
 end
 
-local function iscdata(test, v, ctype, message, extra)
+local function iscdata(testcase, v, ctype, message, extra)
     extra = extra or {}
     extra.expected = ffi.typeof(ctype)
     if type(v) == 'cdata' then
         extra.got = ffi.typeof(v)
-        return ok(test, ffi.istype(ctype, v), message, extra)
+        return ok(testcase, ffi.istype(ctype, v), message, extra)
     else
         extra.got = type(v)
-        return fail(test, message, extra)
+        return fail(testcase, message, extra)
     end
 end
 
 local test_mt
 local function test(parent, name, fun, ...)
     local level = parent ~= nil and parent.level + 1 or 0
-    local test = setmetatable({
+    local testcase = setmetatable({
         parent  = parent;
         name    = name;
         level   = level;
@@ -232,48 +229,48 @@ local function test(parent, name, fun, ...)
         strict = false;
     }, test_mt)
     if fun ~= nil then
-        test:diag('%s', test.name)
-        fun(test, ...)
-        test:diag('%s: end', test.name)
-        return test:check()
+        testcase:diag('%s', testcase.name)
+        fun(testcase, ...)
+        testcase:diag('%s: end', testcase.name)
+        return testcase:check()
     else
-        return test
+        return testcase
     end
 end
 
-local function plan(test, planned)
-    test.planned = planned
-    io.write(string.rep(' ', 4 * test.level), string.format("1..%d\n", planned))
+local function plan(testcase, planned)
+    testcase.planned = planned
+    io.write(string.rep(' ', 4 * testcase.level), string.format("1..%d\n", planned))
 end
 
-local function check(test)
-    if test.checked then
+local function check(testcase)
+    if testcase.checked then
         error('check called twice')
     end
-    test.checked = true
-    if test.planned ~= test.total then
-        if test.parent ~= nil then
-            ok(test.parent, false, "bad plan", { planned = test.planned;
-                run = test.total})
+    testcase.checked = true
+    if testcase.planned ~= testcase.total then
+        if testcase.parent ~= nil then
+            ok(testcase.parent, false, "bad plan", { planned = testcase.planned;
+                run = testcase.total})
         else
-            diag(test, string.format("bad plan: planned %d run %d",
-                test.planned, test.total))
+            diag(testcase, string.format("bad plan: planned %d run %d",
+                testcase.planned, testcase.total))
         end
-    elseif test.failed > 0 then
-        if test.parent ~= nil then
-            ok(test.parent, false, "failed subtests", {
-                failed = test.failed;
-                planned = test.planned;
+    elseif testcase.failed > 0 then
+        if testcase.parent ~= nil then
+            ok(testcase.parent, false, "failed subtests", {
+                failed = testcase.failed;
+                planned = testcase.planned;
             })
         else
-            diag(test, "failed subtest: %d", test.failed)
+            diag(testcase, "failed subtest: %d", testcase.failed)
         end
     else
-        if test.parent ~= nil then
-            ok(test.parent, true, test.name)
+        if testcase.parent ~= nil then
+            ok(testcase.parent, true, testcase.name)
         end
     end
-    return test.planned == test.total and test.failed == 0
+    return testcase.planned == testcase.total and testcase.failed == 0
 end
 
 test_mt = {
diff --git a/src/lua/trigger.lua b/src/lua/trigger.lua
index 76a582c47..1330ecdd4 100644
--- a/src/lua/trigger.lua
+++ b/src/lua/trigger.lua
@@ -1,7 +1,4 @@
 local fun = require('fun')
-local log = require('log')
-
-local table_clear = require('table.clear')
 
 --
 -- Checks that argument is a callable, i.e. a function or a table
-- 
2.23.0


-- 
sergeyb@


More information about the Tarantool-patches mailing list