From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp57.i.mail.ru (smtp57.i.mail.ru [217.69.128.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EDE314696C2 for ; Thu, 4 Jun 2020 11:41:21 +0300 (MSK) From: sergeyb@tarantool.org Date: Thu, 4 Jun 2020 11:39:11 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 5/6] Fix luacheck warnings in src/lua/ List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, imun@tarantool.org, v.shpilevoy@tarantool.org Cc: alexander.turenko@tarantool.org From: Sergey Bronnikov Part of #4681 Reviewed-by: Vladislav Shpilevoy Reviewed-by: Igor Munkin Co-authored-by: Vladislav Shpilevoy Co-authored-by: Igor Munkin --- .luacheckrc | 28 ++++++++++++++++++++++++---- src/lua/argparse.lua | 3 ++- src/lua/buffer.lua | 4 ++-- src/lua/clock.lua | 2 +- src/lua/crypto.lua | 4 ++-- src/lua/csv.lua | 5 ++--- src/lua/digest.lua | 2 +- src/lua/env.lua | 2 +- src/lua/fiber.lua | 4 ++-- src/lua/fio.lua | 30 ++++++++++++++---------------- src/lua/help.lua | 7 ++----- src/lua/httpc.lua | 3 --- src/lua/init.lua | 4 ++-- src/lua/msgpackffi.lua | 22 +++++++++------------- src/lua/socket.lua | 16 ++++++++-------- src/lua/string.lua | 1 - src/lua/swim.lua | 2 +- src/lua/tap.lua | 4 ---- src/lua/trigger.lua | 3 --- 19 files changed, 73 insertions(+), 73 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index b917eb927..fb8b9dfb3 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -1,9 +1,14 @@ std = "luajit" globals = {"box", "_TARANTOOL"} ignore = { - "212/self", -- Unused argument . - "411", -- Redefining a local variable. - "431", -- Shadowing an upvalue. + "143/debug", -- Accessing an undefined field of a global variable . + "143/string", -- Accessing an undefined field of a global variable . + "143/table", -- Accessing an undefined field of a global variable . + "212/self", -- Unused argument . + "411", -- Redefining a local variable. + "421", -- Shadowing a local variable. + "431", -- Shadowing an upvalue. + "432", -- Shadowing an upvalue argument. } @@ -14,7 +19,7 @@ include_files = { exclude_files = { "build/**/*.lua", - "src/**/*.lua", + "src/box/**/*.lua", "test-run/**/*.lua", "test/**/*.lua", "third_party/**/*.lua", @@ -27,3 +32,18 @@ files["extra/dist/tarantoolctl.in"] = { "122", -- https://github.com/tarantool/tarantool/issues/4929 }, } +files["src/lua/help.lua"] = { + globals = {"help", "tutorial"}, -- globals defined for interactive mode. +} +files["src/lua/init.lua"] = { + globals = {"dostring"}, -- miscellaneous global function definition. + ignore = { + "122/os", -- set tarantool specific behaviour for os.exit. + "142/package", -- add custom functions into Lua package namespace. + }, +} +files["src/lua/swim.lua"] = { + ignore = { + "212/m", -- respect swim module code style. + }, +} diff --git a/src/lua/argparse.lua b/src/lua/argparse.lua index faa0ae130..6c8f10fc1 100644 --- a/src/lua/argparse.lua +++ b/src/lua/argparse.lua @@ -91,7 +91,8 @@ local function convert_parameter(name, convert_from, convert_to) end local function parameters_parse(t_in, options) - local t_out, t_in = {}, t_in or {} + 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 diff --git a/src/lua/buffer.lua b/src/lua/buffer.lua index 9aac82b39..00846bb20 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(self) return '' 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..f31708e29 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', @@ -428,7 +428,7 @@ local public_methods = { } local module_mt = { - __serialize = function(s) + __serialize = function(self) 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..7f1aea8d0 100644 --- a/src/lua/digest.lua +++ b/src/lua/digest.lua @@ -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..a31b7098f 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 if value ~= nil then rv = ffi.C.setenv(key, value, 1) else diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua index 89c17f63d..b14117714 100644 --- a/src/lua/fiber.lua +++ b/src/lua/fiber.lua @@ -39,8 +39,8 @@ local stall = fiber.stall fiber.stall = nil local worker_next_task = nil -local worker_last_task = nil -local worker_fiber = nil +local worker_last_task +local worker_fiber -- -- Worker is a singleton fiber for not urgent delayed execution of diff --git a/src/lua/fio.lua b/src/lua/fio.lua index 83fddaa0a..b31311b7b 100644 --- a/src/lua/fio.lua +++ b/src/lua/fio.lua @@ -329,7 +329,7 @@ fio.abspath = function(path) error("Usage: fio.abspath(path)") end path = path - local joined_path = '' + local joined_path local path_tab = {} if string.sub(path, 1, 1) == '/' then joined_path = path @@ -366,7 +366,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 @@ -378,15 +378,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, @@ -407,27 +407,26 @@ fio.rmtree = function(path) if type(path) ~= 'string' then error("Usage: fio.rmtree(path)") end - local status, err 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 end end end - status, err = fio.rmdir(path) + local _, err = fio.rmdir(path) if err ~= nil then return false, string.format("failed to remove %s: %s", path, err) end @@ -453,7 +452,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) @@ -467,22 +465,22 @@ fio.copytree = function(from, to) end -- create tree of destination - status, reason = fio.mktree(to) + local _, reason = fio.mktree(to) 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) if st and st:is_dir() then - status, reason = fio.copytree(ffrom, fto) + _, reason = fio.copytree(ffrom, fto) if reason ~= nil then return false, reason end end if st:is_reg() then - status, reason = fio.copyfile(ffrom, fto) + _, reason = fio.copyfile(ffrom, fto) if reason ~= nil then return false, reason end @@ -492,7 +490,7 @@ fio.copytree = function(from, to) if reason ~= nil then return false, reason end - status, reason = fio.symlink(link_to, fto) + _, reason = fio.symlink(link_to, fto) if reason ~= nil then return false, "can't create symlink in place of existing file "..fto end diff --git a/src/lua/help.lua b/src/lua/help.lua index 54ff1b5d0..4f024832d 100644 --- a/src/lua/help.lua +++ b/src/lua/help.lua @@ -11,10 +11,7 @@ help = { doc.help } tutorial = {} tutorial[1] = help[1] -local help_function_data = {}; -local help_object_data = {} - -local function help_call(table, param) +local function help_call() return help end @@ -22,7 +19,7 @@ setmetatable(help, { __call = help_call }) local screen_id = 1; -local function tutorial_call(table, action) +local function tutorial_call(self, action) if action == 'start' then screen_id = 1; elseif action == 'next' or action == 'more' then 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..aea7a7491 100644 --- a/src/lua/init.lua +++ b/src/lua/init.lua @@ -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 diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index f01ffaef0..cb7ad5b88 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -302,10 +302,6 @@ local function encode(obj) return r end -local function encode_ibuf(obj, ibuf) - encode_r(ibuf, obj, 0) -end - on_encode(ffi.typeof('uint8_t'), encode_int) on_encode(ffi.typeof('uint16_t'), encode_int) on_encode(ffi.typeof('uint32_t'), encode_int) @@ -332,7 +328,6 @@ local decode_r -- See similar constants in utils.cc local DBL_INT_MAX = 1e14 - 1 -local DBL_INT_MIN = -1e14 + 1 local function decode_u8(data) local num = ffi.cast(uint8_ptr_t, data[0])[0] @@ -477,8 +472,7 @@ end local function decode_array(data, size) assert (type(size) == "number") local arr = {} - local i - for i=1,size,1 do + for _ = 1, size do table.insert(arr, decode_r(data)) end if not msgpack.cfg.decode_save_metatables then @@ -490,8 +484,7 @@ end local function decode_map(data, size) assert (type(size) == "number") local map = {} - local i - for i=1,size,1 do + for _ = 1, size do local key = decode_r(data); local val = decode_r(data); map[key] = val @@ -504,11 +497,15 @@ end local ext_decoder = { -- MP_UNKNOWN_EXTENSION - [0] = function(data, len) error("unsupported extension type") end, + [0] = function(data, len) error("unsupported extension type") end, -- luacheck: no unused args -- MP_DECIMAL [1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end, -- MP_UUID - [2] = function(data, len) local uuid = ffi.new("struct tt_uuid") builtin.uuid_unpack(data, len, uuid) return uuid end, + [2] = function(data, len) + local uuid = ffi.new("struct tt_uuid") + builtin.uuid_unpack(data, len, uuid) + return uuid + end, } local function decode_ext(data) @@ -516,7 +513,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 @@ -603,7 +599,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 bbdef01e3..2a2c7a32c 100644 --- a/src/lua/socket.lua +++ b/src/lua/socket.lua @@ -177,7 +177,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 @@ -665,7 +665,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 @@ -1044,7 +1044,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' }) @@ -1052,7 +1052,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) @@ -1319,7 +1319,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: no unused args check_socket(self) self.timeout = value -- mode is effectively ignored @@ -1475,7 +1475,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) @@ -1543,7 +1543,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) @@ -1567,7 +1567,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(s) return backlog end -- luacheck: no unused args local s = tcp_server_bind(host, port, prepare) if not s then return nil, boxerrno.strerror() 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 0859915c9..cdf9d7df0 100644 --- a/src/lua/swim.lua +++ b/src/lua/swim.lua @@ -371,7 +371,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 diff --git a/src/lua/tap.lua b/src/lua/tap.lua index 94b080d5a..346724d84 100644 --- a/src/lua/tap.lua +++ b/src/lua/tap.lua @@ -53,7 +53,6 @@ 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") extra.trace = traceback() extra.filename = extra.trace[#extra.trace].filename extra.line = extra.trace[#extra.trace].line @@ -76,9 +75,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 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