* [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck @ 2020-04-14 7:55 Sergey Bronnikov 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov ` (7 more replies) 0 siblings, 8 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 7:55 UTC (permalink / raw) To: avtikhon, alexander.turenko, o.piskunov, tarantool-patches Changelog: - removed asserts in test/ to keep following diff-based approach with tests - added separate install target in .travis.mk - added comment regarding ENABLE_DIST in .travis.mk - enabled app-tap in .luacheckrc - removed duplicate warnings W212 and W122 - disabled checking of files in test/var directory GH issue: https://github.com/tarantool/tarantool/issues/4681 GitHub branch: https://github.com/tarantool/tarantool/tree/ligurio/gh-4681-fix-luacheck-warnings Sergey Bronnikov (6): Fix luacheck warnings in src/lua/ Fix luacheck warnings in test/ Fix luacheck warnings in src/box/lua/ Fix luacheck warnings in extra/dist/tarantoolctl.in Add luacheck config gitlab-ci: enable static analysis with luacheck .gitlab-ci.yml | 9 + .luacheckrc | 175 ++++++++++++++++++ .travis.mk | 15 +- extra/dist/tarantoolctl.in | 18 +- src/box/lua/upgrade.lua | 12 +- src/lua/argparse.lua | 6 +- 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/fio.lua | 25 +-- src/lua/httpc.lua | 3 - src/lua/init.lua | 7 +- src/lua/msgpackffi.lua | 16 +- src/lua/socket.lua | 65 ++++--- src/lua/string.lua | 1 - src/lua/swim.lua | 10 +- src/lua/tap.lua | 74 ++++---- src/lua/trigger.lua | 3 - test/app-tap/console.test.lua | 4 - test/app-tap/csv.test.lua | 28 +-- test/app-tap/logger.test.lua | 2 +- test/box-py/box.lua | 2 +- test/box-tap/gc.test.lua | 4 +- test/box/box.lua | 2 +- test/box/hash_multipart.result | 2 +- test/box/hash_multipart.test.lua | 2 +- 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/utils.lua | 3 +- 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 +- test/engine/tree_min_max_count.result | 2 +- test/engine/tree_min_max_count.test.lua | 2 +- test/replication-py/master.lua | 2 +- test/replication-py/panic.lua | 2 +- test/replication/master.lua | 2 +- test/replication/replicaset_ro_mostly.result | 2 +- .../replication/replicaset_ro_mostly.test.lua | 2 +- test/sql-tap/analyze3.test.lua | 6 +- test/sql-tap/analyze9.test.lua | 16 +- .../gh-4077-iproto-execute-no-bind.test.lua | 7 +- test/sql-tap/index1.test.lua | 1 - test/sql-tap/join3.test.lua | 2 +- test/sql-tap/select9.test.lua | 10 +- test/sql-tap/tkt-fa7bf5ec.test.lua | 6 +- test/sql-tap/where2.test.lua | 2 +- test/sql/lua/sql_tokenizer.lua | 2 +- test/sql/savepoints.result | 6 +- test/sql/savepoints.test.lua | 6 +- test/sql/triggers.result | 2 +- test/sql/triggers.test.lua | 2 +- test/vinyl/large.lua | 3 +- test/vinyl/txn_proxy.lua | 6 +- test/vinyl/vinyl.lua | 2 +- test/wal_off/rtree_benchmark.result | 2 +- test/wal_off/rtree_benchmark.test.lua | 2 +- test/xlog-py/box.lua | 2 +- test/xlog/panic.lua | 2 +- test/xlog/reader.result | 2 +- test/xlog/reader.test.lua | 2 +- test/xlog/snap_io_rate.test.lua | 2 +- test/xlog/transaction.result | 2 +- test/xlog/transaction.test.lua | 2 +- test/xlog/xlog.lua | 2 +- 76 files changed, 409 insertions(+), 243 deletions(-) create mode 100644 .luacheckrc -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov @ 2020-04-14 7:56 ` Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-15 20:51 ` Igor Munkin 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ Sergey Bronnikov ` (6 subsequent siblings) 7 siblings, 2 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 7:56 UTC (permalink / raw) To: tarantool-patches, avtikhon, alexander.turenko, o.piskunov Many warnings fixed with help from Vladislav Shpilevoy. Closes #4681 Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- src/lua/argparse.lua | 6 ++-- 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/fio.lua | 25 +++++++------- src/lua/httpc.lua | 3 -- src/lua/init.lua | 7 ++-- src/lua/msgpackffi.lua | 16 +++------ src/lua/socket.lua | 65 ++++++++++++++++++------------------- src/lua/string.lua | 1 - src/lua/swim.lua | 10 +++--- src/lua/tap.lua | 74 ++++++++++++++++++++---------------------- src/lua/trigger.lua | 3 -- 16 files changed, 105 insertions(+), 124 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..43c7e1170 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() 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..c0eb0d303 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() 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/fio.lua b/src/lua/fio.lua index 83fddaa0a..b2b4b4c77 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,20 +407,20 @@ fio.rmtree = function(path) if type(path) ~= 'string' then error("Usage: fio.rmtree(path)") end - local status, err + local status 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 @@ -471,10 +471,10 @@ fio.copytree = function(from, 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) + st = fio.lstat(ffrom) if st and st:is_dir() then status, reason = fio.copytree(ffrom, fto) if reason ~= nil then @@ -488,7 +488,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/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..a831549d1 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 @@ -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 diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index f01ffaef0..9105c3f23 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,7 +497,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, -- MP_UUID @@ -516,7 +509,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 +595,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..317acfe8e 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,10 +1311,9 @@ 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) check_socket(self) self.timeout = value - -- mode is effectively ignored return 1 end @@ -1467,7 +1466,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 +1534,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 +1558,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() 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..8e3b0ab13 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 @@ -462,7 +462,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 } @@ -793,9 +793,9 @@ local function swim_on_member_event_new(s, callback, ctx) -- trigger will never be GC-ed. s = setmetatable({s}, {__mode = 'v'}) return function(member_ptr, event_mask) - local s = s[1] - if s then - local m = swim_wrap_member(s, member_ptr) + local si = s[1] + if si then + local m = swim_wrap_member(si, 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..094eb883f 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 @@ -190,38 +186,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 +228,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@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov @ 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-15 20:51 ` Igor Munkin 2020-04-17 9:09 ` Sergey Bronnikov 2020-04-15 20:51 ` Igor Munkin 1 sibling, 2 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:29 UTC (permalink / raw) To: Sergey Bronnikov, tarantool-patches, avtikhon, alexander.turenko, o.piskunov Thanks for the patch! Consider more fixes below and on the branch in a separate commit. That allowed to remove some warning mutes from the luacheck config. ==================== Review fixes: src/lua diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua index 89c17f63d..692408e54 100644 --- a/src/lua/fiber.lua +++ b/src/lua/fiber.lua @@ -40,7 +40,7 @@ fiber.stall = nil local worker_next_task = nil local worker_last_task = nil -local worker_fiber = nil +local worker_fiber -- -- Worker is a singleton fiber for not urgent delayed execution of diff --git a/src/lua/help.lua b/src/lua/help.lua index 54ff1b5d0..f4041d4a4 100644 --- a/src/lua/help.lua +++ b/src/lua/help.lua @@ -11,9 +11,6 @@ help = { doc.help } tutorial = {} tutorial[1] = help[1] -local help_function_data = {}; -local help_object_data = {} - local function help_call(table, param) return help end diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index 9105c3f23..793f47854 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -501,7 +501,11 @@ local ext_decoder = { -- 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) ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-14 23:29 ` Vladislav Shpilevoy @ 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:40 ` Vladislav Shpilevoy 2020-04-17 9:07 ` Sergey Bronnikov 2020-04-17 9:09 ` Sergey Bronnikov 1 sibling, 2 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-15 20:51 UTC (permalink / raw) To: Vladislav Shpilevoy; +Cc: o.piskunov, tarantool-patches Vlad, Thanks for the fixes! On 15.04.20, Vladislav Shpilevoy wrote: > Thanks for the patch! > > Consider more fixes below and on the branch in a separate commit. > That allowed to remove some warning mutes from the luacheck > config. > > ==================== > > Review fixes: src/lua > > diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua > index 89c17f63d..692408e54 100644 > --- a/src/lua/fiber.lua > +++ b/src/lua/fiber.lua > @@ -40,7 +40,7 @@ fiber.stall = nil > > local worker_next_task = nil > local worker_last_task = nil It looks like this assignment can also be omitted (anyway luacheck also reports it as a warning). > -local worker_fiber = nil > +local worker_fiber > > -- > -- Worker is a singleton fiber for not urgent delayed execution of <snipped> > diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua > index 9105c3f23..793f47854 100644 > --- a/src/lua/msgpackffi.lua > +++ b/src/lua/msgpackffi.lua > @@ -501,7 +501,11 @@ local ext_decoder = { > -- MP_DECIMAL > [1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end, I guess MP_DECIMAL decoder can also be transformed to multiline function. > -- 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) -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-15 20:51 ` Igor Munkin @ 2020-04-15 21:40 ` Vladislav Shpilevoy 2020-04-17 9:07 ` Sergey Bronnikov 1 sibling, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-15 21:40 UTC (permalink / raw) To: Igor Munkin; +Cc: o.piskunov, tarantool-patches >> diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua >> index 89c17f63d..692408e54 100644 >> --- a/src/lua/fiber.lua >> +++ b/src/lua/fiber.lua >> @@ -40,7 +40,7 @@ fiber.stall = nil >> >> local worker_next_task = nil >> local worker_last_task = nil > > It looks like this assignment can also be omitted (anyway luacheck also > reports it as a warning). It didn't report for me. >> -local worker_fiber = nil >> +local worker_fiber >> >> -- >> -- Worker is a singleton fiber for not urgent delayed execution of > > <snipped> > >> diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua >> index 9105c3f23..793f47854 100644 >> --- a/src/lua/msgpackffi.lua >> +++ b/src/lua/msgpackffi.lua >> @@ -501,7 +501,11 @@ local ext_decoder = { >> -- MP_DECIMAL >> [1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end, > > I guess MP_DECIMAL decoder can also be transformed to multiline function. It can, but luacheck does not complain about it (on my machine), so I decided to keep it to reduce diff size. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:40 ` Vladislav Shpilevoy @ 2020-04-17 9:07 ` Sergey Bronnikov 1 sibling, 0 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-17 9:07 UTC (permalink / raw) To: Igor Munkin; +Cc: o.piskunov, tarantool-patches, Vladislav Shpilevoy Igor, thanks a lot for review. See my answers below. On 23:51 Wed 15 Apr , Igor Munkin wrote: <snipped> > > ==================== > > > > Review fixes: src/lua > > > > diff --git a/src/lua/fiber.lua b/src/lua/fiber.lua > > index 89c17f63d..692408e54 100644 > > --- a/src/lua/fiber.lua > > +++ b/src/lua/fiber.lua > > @@ -40,7 +40,7 @@ fiber.stall = nil > > > > local worker_next_task = nil > > local worker_last_task = nil > > It looks like this assignment can also be omitted (anyway luacheck also > reports it as a warning). Kept it as is because luacheck don't warn me about it. > > -local worker_fiber = nil > > +local worker_fiber > > > > -- > > -- Worker is a singleton fiber for not urgent delayed execution of > > <snipped> > > > diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua > > index 9105c3f23..793f47854 100644 > > --- a/src/lua/msgpackffi.lua > > +++ b/src/lua/msgpackffi.lua > > @@ -501,7 +501,11 @@ local ext_decoder = { > > -- MP_DECIMAL > > [1] = function(data, len) local num = ffi.new("decimal_t") builtin.decimal_unpack(data, len, num) return num end, > > I guess MP_DECIMAL decoder can also be transformed to multiline function. The same - kept it as is because luacheck don't warn me about it. S. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-15 20:51 ` Igor Munkin @ 2020-04-17 9:09 ` Sergey Bronnikov 1 sibling, 0 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-17 9:09 UTC (permalink / raw) To: Vladislav Shpilevoy; +Cc: o.piskunov, tarantool-patches Vladislav, thanks a lot for review and for the patch especially! I'll squash patch with mine if you have no objectives. On 01:29 Wed 15 Apr , Vladislav Shpilevoy wrote: > Thanks for the patch! > > Consider more fixes below and on the branch in a separate commit. > That allowed to remove some warning mutes from the luacheck > config. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy @ 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:46 ` Vladislav Shpilevoy 2020-04-17 9:26 ` Sergey Bronnikov 1 sibling, 2 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-15 20:51 UTC (permalink / raw) To: Sergey Bronnikov; +Cc: o.piskunov, tarantool-patches Sergey, Thanks for the patch! On 14.04.20, Sergey Bronnikov wrote: > Many warnings fixed with help from Vladislav Shpilevoy. > > Closes #4681 > > Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> > --- > > src/lua/argparse.lua | 6 ++-- > 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/fio.lua | 25 +++++++------- > src/lua/httpc.lua | 3 -- > src/lua/init.lua | 7 ++-- > src/lua/msgpackffi.lua | 16 +++------ > src/lua/socket.lua | 65 ++++++++++++++++++------------------- > src/lua/string.lua | 1 - > src/lua/swim.lua | 10 +++--- > src/lua/tap.lua | 74 ++++++++++++++++++++---------------------- > src/lua/trigger.lua | 3 -- > 16 files changed, 105 insertions(+), 124 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 {} I guess you can just give t__in a proper name, e.g. args, params, etc. > > -- Prepare a lookup table for options. An option name -> a > -- type name to convert a parameter into or true (which means <snipped> > diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua > index bf3064c70..c0eb0d303 100644 > --- a/src/lua/crypto.lua > +++ b/src/lua/crypto.lua <snipped> > @@ -428,7 +428,7 @@ local public_methods = { > } > > local module_mt = { > - __serialize = function(s) > + __serialize = function() > return public_methods > end, > __index = public_methods I see no reasons to leave other W212[unused argument self] occurences. Here is a diff: ================================================================================ diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua index c0eb0d303..6a7ee53f0 100644 --- a/src/lua/crypto.lua +++ b/src/lua/crypto.lua @@ -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 (_, str) 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(_, digest) 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 (_, key, str) if type(str) ~= 'string' then error("Usage: hmac."..class.."(key, string)") end @@ -356,12 +356,12 @@ for class, digest in pairs(hmacs) do if type(str) ~= 'string' then error("Usage: hmac."..class.."_hex(key, string)") end - return string.hex(hmac_api[class](key, str)) + return hmac_api[class](key, str):hex() end end hmac_api = setmetatable(hmac_api, - {__index = function(self, digest) + {__index = function(_, digest) 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(_, mode) error('Cipher mode ' .. mode .. ' is not supported') end } local crypto_api_mt = { - __index = function(self, cipher) + __index = function(_, cipher) 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(_, str, key, iv) local ctx = crypto_stream_new(algo_value, mode_value, key, iv, dir_value) local res = ctx:update(str) ================================================================================ <snipped> > 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 Fixed the remaining errors: ================================================================================ diff --git a/src/lua/digest.lua b/src/lua/digest.lua index 7f1aea8d0..6175228ab 100644 --- a/src/lua/digest.lua +++ b/src/lua/digest.lua @@ -91,7 +91,7 @@ PMurHash = { } setmetatable(PMurHash, { - __call = function(self, str) + __call = function(_, str) if type(str) ~= 'string' then error("Usage: digest.murhash(string)") end @@ -134,7 +134,7 @@ CRC32 = { } setmetatable(CRC32, { - __call = function(self, str) + __call = function(_, str) if type(str) ~= 'string' then error("Usage digest.crc32(string)") end ================================================================================ <snipped> Fixed the remaining errors in src/lua/errno.lua: ================================================================================ diff --git a/src/lua/errno.lua b/src/lua/errno.lua index db800ce30..9b8dd518a 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(_, ...) return ffi.errno(...) end }) ================================================================================ > diff --git a/src/lua/fio.lua b/src/lua/fio.lua > index 83fddaa0a..b2b4b4c77 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 It is a confusing noop, please drop it. > - local joined_path = '' > + local joined_path > local path_tab = {} > if string.sub(path, 1, 1) == '/' then > joined_path = path <snipped> > @@ -407,20 +407,20 @@ fio.rmtree = function(path) > if type(path) ~= 'string' then > error("Usage: fio.rmtree(path)") > end > - local status, err > + local status This value is unused (and the corresponding warning is reported). Consider the changes below: ================================================================================ diff --git a/src/lua/fio.lua b/src/lua/fio.lua index b2b4b4c77..e271eccf6 100644 --- a/src/lua/fio.lua +++ b/src/lua/fio.lua @@ -407,7 +407,6 @@ fio.rmtree = function(path) if type(path) ~= 'string' then error("Usage: fio.rmtree(path)") end - local status path = fio.abspath(path) local ls, err = fio.listdir(path) if err ~= nil then @@ -427,7 +426,8 @@ fio.rmtree = function(path) 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 ================================================================================ > 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 > @@ -471,10 +471,10 @@ fio.copytree = function(from, 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) > + st = fio.lstat(ffrom) > if st and st:is_dir() then > status, reason = fio.copytree(ffrom, fto) This value is unused (and the corresponding warning is reported). Consider the changes below: ================================================================================ diff --git a/src/lua/fio.lua b/src/lua/fio.lua index b2b4b4c77..5fc47b8fc 100644 --- a/src/lua/fio.lua +++ b/src/lua/fio.lua @@ -453,7 +453,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,7 +466,7 @@ 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 @@ -476,13 +475,13 @@ fio.copytree = function(from, to) local fto = fio.pathjoin(to, f) 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 @@ -493,7 +492,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 ================================================================================ > if reason ~= nil then <snipped> > diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua > index f01ffaef0..9105c3f23 100644 > --- a/src/lua/msgpackffi.lua > +++ b/src/lua/msgpackffi.lua <snipped> > @@ -504,7 +497,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, Again another suppressed warning, that can be simply fixed: ================================================================================ diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index 9105c3f23..786118d2d 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -499,9 +499,17 @@ local ext_decoder = { -- MP_UNKNOWN_EXTENSION [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, + [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) ================================================================================ > -- MP_UUID <snipped> > diff --git a/src/lua/socket.lua b/src/lua/socket.lua > index a334ad45b..317acfe8e 100644 > --- a/src/lua/socket.lua > +++ b/src/lua/socket.lua <snipped> Fixed the remaining errors: ================================================================================ diff --git a/src/lua/socket.lua b/src/lua/socket.lua index 317acfe8e..75a4e8fb5 100644 --- a/src/lua/socket.lua +++ b/src/lua/socket.lua @@ -1577,7 +1577,7 @@ return setmetatable({ iowait = internal.iowait, internal = internal, }, { - __call = function(self, ...) return socket_new(...) end; + __call = function(_, ...) return socket_new(...) end; __index = { tcp = lsocket_tcp; connect = lsocket_connect; ================================================================================ <snipped> > diff --git a/src/lua/tap.lua b/src/lua/tap.lua > index 94b080d5a..094eb883f 100644 > --- a/src/lua/tap.lua > +++ b/src/lua/tap.lua <snipped> > @@ -190,38 +186,38 @@ local function isboolean(test, v, message, extra) > return is(test, type(v), 'boolean', message, extra) > end > I don't get the difference between <isfunction> routine and <isboolean>, but you changed parameter name only in one of them. Please, choose the one naming and adjust everything considering it. > -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; <snipped> > -- > 2.23.0 > > > -- > sergeyb@ -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-15 20:51 ` Igor Munkin @ 2020-04-15 21:46 ` Vladislav Shpilevoy 2020-04-16 13:52 ` Igor Munkin 2020-04-17 9:26 ` Sergey Bronnikov 1 sibling, 1 reply; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-15 21:46 UTC (permalink / raw) To: Igor Munkin, Sergey Bronnikov; +Cc: o.piskunov, tarantool-patches >> @@ -428,7 +428,7 @@ local public_methods = { >> } >> >> local module_mt = { >> - __serialize = function(s) >> + __serialize = function() >> return public_methods >> end, >> __index = public_methods > > I see no reasons to leave other W212[unused argument self] occurences. > Here is a diff: > > ================================================================================ > > diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua > index c0eb0d303..6a7ee53f0 100644 > --- a/src/lua/crypto.lua > +++ b/src/lua/crypto.lua > @@ -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 (_, str) I would better avoid such changes. They make it harder to understand what the function takes as arguments. Luacheck in these cases basically dictates to us how to name variables, because nothing is removed here. The variable is just renamed to a less understandable name. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-15 21:46 ` Vladislav Shpilevoy @ 2020-04-16 13:52 ` Igor Munkin 0 siblings, 0 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-16 13:52 UTC (permalink / raw) To: Vladislav Shpilevoy; +Cc: o.piskunov, tarantool-patches Vlad, On 15.04.20, Vladislav Shpilevoy wrote: > >> @@ -428,7 +428,7 @@ local public_methods = { > >> } > >> > >> local module_mt = { > >> - __serialize = function(s) > >> + __serialize = function() > >> return public_methods > >> end, > >> __index = public_methods > > > > I see no reasons to leave other W212[unused argument self] occurences. > > Here is a diff: > > > > ================================================================================ > > > > diff --git a/src/lua/crypto.lua b/src/lua/crypto.lua > > index c0eb0d303..6a7ee53f0 100644 > > --- a/src/lua/crypto.lua > > +++ b/src/lua/crypto.lua > > @@ -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 (_, str) > > I would better avoid such changes. They make it harder to understand > what the function takes as arguments. Luacheck in these cases basically > dictates to us how to name variables, because nothing is removed here. > The variable is just renamed to a less understandable name. Well, your point also sounds rational and I agree with you since code is written for us not for luacheck. I guess we need investigate can we suppress globally only unused args with the name <self> but still reports others? Otherwise we can suppress it inline. Chunk-wide suppression can lead to masked/false-negative errors. -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:46 ` Vladislav Shpilevoy @ 2020-04-17 9:26 ` Sergey Bronnikov 2020-04-17 12:13 ` Igor Munkin 1 sibling, 1 reply; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-17 9:26 UTC (permalink / raw) To: Igor Munkin; +Cc: o.piskunov, tarantool-patches Igor, thanks for review! See my answers below. On 23:51 Wed 15 Apr , Igor Munkin wrote: > Sergey, > > Thanks for the patch! > > On 14.04.20, Sergey Bronnikov wrote: > > Many warnings fixed with help from Vladislav Shpilevoy. <snipped> > > 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 {} > > I guess you can just give t__in a proper name, e.g. args, params, etc. Agree with you, replaced it with 'param'. <snipped> > I see no reasons to leave other W212[unused argument self] occurences. > Here is a diff: Vladislav already told me in previous review iterations that '_' is less readable than 'self', so it was a reason why haven't fixed them. I have found a way to supress only W212 related to 'self' and applied it in branch. S. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ 2020-04-17 9:26 ` Sergey Bronnikov @ 2020-04-17 12:13 ` Igor Munkin 0 siblings, 0 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-17 12:13 UTC (permalink / raw) To: Sergey Bronnikov; +Cc: o.piskunov, tarantool-patches Sergey, On 17.04.20, Sergey Bronnikov wrote: > Igor, thanks for review! > See my answers below. > > On 23:51 Wed 15 Apr , Igor Munkin wrote: > > Sergey, > > > > Thanks for the patch! > > <snipped> > > I see no reasons to leave other W212[unused argument self] occurences. > > Here is a diff: > > Vladislav already told me in previous review iterations that '_' is less > readable than 'self', so it was a reason why haven't fixed them. I have > found a way to supress only W212 related to 'self' and applied it in > branch. Nice! That's exactly what we need for this issue! > > S. -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov @ 2020-04-14 7:57 ` Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-16 13:43 ` Igor Munkin 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ Sergey Bronnikov ` (5 subsequent siblings) 7 siblings, 2 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 7:57 UTC (permalink / raw) To: tarantool-patches, avtikhon, alexander.turenko, o.piskunov Closes #4681 Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- test/app-tap/console.test.lua | 4 --- test/app-tap/csv.test.lua | 28 +++++++++---------- test/app-tap/logger.test.lua | 2 +- test/box-py/box.lua | 2 +- test/box-tap/gc.test.lua | 4 +-- test/box/box.lua | 2 +- test/box/hash_multipart.result | 2 +- test/box/hash_multipart.test.lua | 2 +- 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/utils.lua | 3 +- 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 +-- test/engine/tree_min_max_count.result | 2 +- test/engine/tree_min_max_count.test.lua | 2 +- test/replication-py/master.lua | 2 +- test/replication-py/panic.lua | 2 +- test/replication/master.lua | 2 +- test/replication/replicaset_ro_mostly.result | 2 +- .../replication/replicaset_ro_mostly.test.lua | 2 +- test/sql-tap/analyze3.test.lua | 6 ++-- test/sql-tap/analyze9.test.lua | 16 +++++------ .../gh-4077-iproto-execute-no-bind.test.lua | 7 +++-- test/sql-tap/index1.test.lua | 1 - test/sql-tap/join3.test.lua | 2 +- test/sql-tap/select9.test.lua | 10 ++----- test/sql-tap/tkt-fa7bf5ec.test.lua | 6 ++-- test/sql-tap/where2.test.lua | 2 +- test/sql/lua/sql_tokenizer.lua | 2 +- test/sql/savepoints.result | 6 ++-- test/sql/savepoints.test.lua | 6 ++-- test/sql/triggers.result | 2 +- test/sql/triggers.test.lua | 2 +- test/vinyl/large.lua | 3 +- test/vinyl/txn_proxy.lua | 6 ++-- test/vinyl/vinyl.lua | 2 +- test/wal_off/rtree_benchmark.result | 2 +- test/wal_off/rtree_benchmark.test.lua | 2 +- test/xlog-py/box.lua | 2 +- test/xlog/panic.lua | 2 +- test/xlog/reader.result | 2 +- test/xlog/reader.test.lua | 2 +- test/xlog/snap_io_rate.test.lua | 2 +- test/xlog/transaction.result | 2 +- test/xlog/transaction.test.lua | 2 +- test/xlog/xlog.lua | 2 +- 55 files changed, 92 insertions(+), 102 deletions(-) diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua index 4feadfa5e..1f61ba837 100755 --- a/test/app-tap/console.test.lua +++ b/test/app-tap/console.test.lua @@ -5,7 +5,6 @@ local console = require('console') local socket = require('socket') local yaml = require('yaml') local fiber = require('fiber') -local ffi = require('ffi') local log = require('log') local fio = require('fio') @@ -95,12 +94,9 @@ test:is(#client:read(EOL) > 0, true, "_G") client:write("require('fiber').id()\n") local fid1 = yaml.decode(client:read(EOL))[1] local state = fiber.find(fid1).storage.console -local server_info = state.client:peer() local client_info = state.client:name() test:is(client_info.host, client_info.host, "state.socker:peer().host") test:is(client_info.port, client_info.port, "state.socker:peer().port") -server_info = nil -client_info = nil -- Check console.delimiter() client:write("require('console').delimiter(';')\n") diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua index a7f17b1ea..689db7997 100755 --- a/test/app-tap/csv.test.lua +++ b/test/app-tap/csv.test.lua @@ -2,9 +2,9 @@ local function table2str(t) local res = "" - for k, line in pairs(t) do + for _, line in pairs(t) do local s = "" - for k2, field in pairs(line) do + for _, field in pairs(line) do s = s .. '|' .. field .. '|\t' end res = res .. s .. '\n' @@ -12,9 +12,9 @@ local function table2str(t) return res end -local function myread(self, bytes) +local function myread(self, bytes) self.i = self.i + bytes - return self.v:sub(self.i - bytes + 1, self.i) + return self.v:sub(self.i - bytes + 1, self.i) end local csv = require('csv') local fio = require('fio') @@ -27,10 +27,10 @@ local test4_ans = '|123|\t|5|\t|92|\t|0|\t|0|\t\n|1|\t|12 34|\t|56|\t' .. local test5_ans = "|1|\t\n|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n" .. "|none|\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f" .. "3|\t|0|\t\n|local res = internal.pwrite(self.fh|\t|dat" .. - "a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." .. + "a|\t|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio." .. "c.flag[ flag ])|\t\n||\t||\t||\t\n" local test6_ans = "|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n|none|" .. - "\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" .. + "\t|none|\t|0|\t\n||\t||\t||\t\n|aba|\t|adda|\t|f3|\t|" .. "0|\t\n|local res = internal.pwrite(self.fh|\t|data|\t" .. "|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio.c.f" .. "lag[ flag ])|\t\n||\t||\t||\t\n" @@ -62,7 +62,7 @@ local f = fio.open(file1, { 'O_WRONLY', 'O_TRUNC', 'O_CREAT' }, tonumber('0777', f:write("123 , 5 , 92 , 0, 0\n" .. "1, 12 34, 56, \"quote , \", 66\nok") f:close() -f = fio.open(file1, {'O_RDONLY'}) +f = fio.open(file1, {'O_RDONLY'}) test:is(table2str(csv.load(f, {chunk_size = 10})), test4_ans, "fio test1") f:close() @@ -77,20 +77,20 @@ f:write("1\n23,456,abcac,\'multiword field 4\'\n" .. ",," ) f:close() -f = fio.open(file2, {'O_RDONLY'}) +f = fio.open(file2, {'O_RDONLY'}) --symbol by symbol reading -test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2") +test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2") f:close() -f = fio.open(file2, {'O_RDONLY'}) +f = fio.open(file2, {'O_RDONLY'}) opts = {chunk_size = 7, skip_head_lines = 1} --7 symbols per chunk -test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3") +test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3") f:close() t = { - {'quote" d', ',and, comma', 'both " of " t,h,e,m'}, - {'"""', ',","'}, + {'quote" d', ',and, comma', 'both " of " t,h,e,m'}, + {'"""', ',","'}, {'mul\nti\nli\r\nne\n\n', 'field'}, {""}, {'"'}, @@ -100,7 +100,7 @@ t = { f = require("fio").open(file3, { "O_WRONLY", "O_TRUNC" , "O_CREAT"}, 0x1FF) csv.dump(t, {}, f) f:close() -f = fio.open(file3, {'O_RDONLY'}) +f = fio.open(file3, {'O_RDONLY'}) t2 = csv.load(f, {chunk_size = 5}) f:close() diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua index 492d5ea0b..6ec85d0e0 100755 --- a/test/app-tap/logger.test.lua +++ b/test/app-tap/logger.test.lua @@ -57,7 +57,7 @@ file:close() test:ok(log.pid() >= 0, "pid()") -- logger uses 'debug', try to set it to nil -debug = nil +local debug = nil log.info("debug is nil") debug = require('debug') diff --git a/test/box-py/box.lua b/test/box-py/box.lua index e9403774c..35a087de9 100644 --- a/test/box-py/box.lua +++ b/test/box-py/box.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-tap/gc.test.lua b/test/box-tap/gc.test.lua index f88752e71..f0155779c 100755 --- a/test/box-tap/gc.test.lua +++ b/test/box-tap/gc.test.lua @@ -4,7 +4,7 @@ local fiber = require('fiber') box.cfg{} -local debug = type(box.error.injection) == "table" +local debug = type(box.error.injection) == "table" -- check box.info.gc() is false if snapshot is not in progress local test = tap.test('box.info.gc') @@ -19,7 +19,7 @@ test:is(gc.checkpoint_is_in_progress, false, "checkpoint is not in progress") if debug then box.error.injection.set("ERRINJ_SNAP_COMMIT_DELAY", true) local snapshot_f = function() - box.snapshot() + box.snapshot() end fiber.create(snapshot_f) local gc = box.info.gc() 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/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/utils.lua b/test/box/lua/utils.lua index 5f859fd19..058c4a471 100644 --- a/test/box/lua/utils.lua +++ b/test/box/lua/utils.lua @@ -212,10 +212,9 @@ function create_iterator(obj, key, opts) 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 diff --git a/test/engine/tree_min_max_count.result b/test/engine/tree_min_max_count.result index f55732aa6..9f1595a20 100644 --- a/test/engine/tree_min_max_count.result +++ b/test/engine/tree_min_max_count.result @@ -1189,7 +1189,7 @@ space6:drop() --- ... -- min max count after many inserts -string = require('string') +local string = require('string') --- ... space7 = box.schema.space.create('space7', { engine = engine }) diff --git a/test/engine/tree_min_max_count.test.lua b/test/engine/tree_min_max_count.test.lua index 0633c56b3..19b5fe92d 100644 --- a/test/engine/tree_min_max_count.test.lua +++ b/test/engine/tree_min_max_count.test.lua @@ -337,7 +337,7 @@ space6:drop() -- min max count after many inserts -string = require('string') +local string = require('string') space7 = box.schema.space.create('space7', { engine = engine }) index7 = space7:create_index('primary', { type = 'tree', parts = {1, 'scalar'} }) diff --git a/test/replication-py/master.lua b/test/replication-py/master.lua index e924b5495..b43bafd54 100644 --- a/test/replication-py/master.lua +++ b/test/replication-py/master.lua @@ -1,5 +1,5 @@ #!/usr/bin/env tarantool -os = require('os') +local os = require('os') box.cfg({ listen = os.getenv("LISTEN"), memtx_memory = 107374182, diff --git a/test/replication-py/panic.lua b/test/replication-py/panic.lua index 75a738cbb..e72d11419 100644 --- a/test/replication-py/panic.lua +++ b/test/replication-py/panic.lua @@ -1,5 +1,5 @@ #!/usr/bin/env tarantool -os = require('os') +local os = require('os') box.cfg({ listen = os.getenv("LISTEN"), memtx_memory = 107374182, diff --git a/test/replication/master.lua b/test/replication/master.lua index e924b5495..b43bafd54 100644 --- a/test/replication/master.lua +++ b/test/replication/master.lua @@ -1,5 +1,5 @@ #!/usr/bin/env tarantool -os = require('os') +local os = require('os') box.cfg({ listen = os.getenv("LISTEN"), memtx_memory = 107374182, diff --git a/test/replication/replicaset_ro_mostly.result b/test/replication/replicaset_ro_mostly.result index a471779d3..e509e0da0 100644 --- a/test/replication/replicaset_ro_mostly.result +++ b/test/replication/replicaset_ro_mostly.result @@ -35,7 +35,7 @@ test_run:cmd("setopt delimiter ';'") - true ... function create_cluster_uuid(servers, uuids) - for i, name in ipairs(servers) do + for _, name in ipairs(servers) do test_run:cmd(create_cluster_cmd1:format(name, name)) end for i, name in ipairs(servers) do diff --git a/test/replication/replicaset_ro_mostly.test.lua b/test/replication/replicaset_ro_mostly.test.lua index 19cd1fe4a..e06e29c8e 100644 --- a/test/replication/replicaset_ro_mostly.test.lua +++ b/test/replication/replicaset_ro_mostly.test.lua @@ -16,7 +16,7 @@ create_cluster_cmd2 = 'start server %s with args="%s", wait_load=False, wait=Fal test_run:cmd("setopt delimiter ';'") function create_cluster_uuid(servers, uuids) - for i, name in ipairs(servers) do + for _, name in ipairs(servers) do test_run:cmd(create_cluster_cmd1:format(name, name)) end for i, name in ipairs(servers) do diff --git a/test/sql-tap/analyze3.test.lua b/test/sql-tap/analyze3.test.lua index dcbea1da5..5c9c28601 100755 --- a/test/sql-tap/analyze3.test.lua +++ b/test/sql-tap/analyze3.test.lua @@ -23,15 +23,15 @@ testprefix = "analyze3" ------------------------------------------------------------------------ -- Test Organization: -- --- analyze3-1.*: Test that the values of bound parameters are considered +-- analyze3-1.*: Test that the values of bound parameters are considered -- in the same way as constants when planning queries that -- use range constraints. -- --- analyze3-2.*: Test that the values of bound parameters are considered +-- analyze3-2.*: Test that the values of bound parameters are considered -- in the same way as constants when planning queries that -- use LIKE expressions in the WHERE clause. -- --- analyze3-3.*: Test that binding to a variable does not invalidate the +-- analyze3-3.*: Test that binding to a variable does not invalidate the -- query plan when there is no way in which replanning the -- query may produce a superior outcome. -- diff --git a/test/sql-tap/analyze9.test.lua b/test/sql-tap/analyze9.test.lua index 02eb49f69..7412ba5fe 100755 --- a/test/sql-tap/analyze9.test.lua +++ b/test/sql-tap/analyze9.test.lua @@ -609,7 +609,7 @@ test:do_execsql_test( test:do_test( "10.1.2", function() - local a = 0 + local a for i = 1, 100 do if i > 90 then a = i @@ -657,7 +657,7 @@ test:do_execsql_test( test:do_test( "10.2.2", function() - local a = 0 + local a for i = 1, 100 do if i > 90 then a = i @@ -711,7 +711,7 @@ test:do_execsql_test( test:do_test( 11.1, function() - local a = 0 + local a for i = 0, 100 do if i % 10 == 0 then a = "\"ABC\"" @@ -762,7 +762,7 @@ test:do_execsql_test( test:do_test( 11.5, function() - local a = 0 + local a for i = 0, 100 do if i % 10 == 0 then a = "\"ABC\"" @@ -823,7 +823,7 @@ test:do_execsql_test( test:do_test( 12.1, function() - local a = 0 + local a for i = 0, 100 do if i % 10 == 0 then a = "\"ABC\"" @@ -874,7 +874,7 @@ test:do_execsql_test( test:do_test( 12.5, function() - local a = 0 + local a for i = 0, 100 do if i % 10 == 0 then a = "\"ABC\"" @@ -931,7 +931,7 @@ test:do_test( test:execsql("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a TEXT, b INT, c INT, d INT);") test:execsql("CREATE INDEX i1 ON t1(a);") test:execsql("CREATE INDEX i2 ON t1(b, c);") - local a = 0 + local a for i = 0, 100 do if i % 2 == 1 then a = "\"abc\"" @@ -1161,7 +1161,7 @@ test:do_test( INSERT INTO t1 SELECT null, 2*a,2*b,2*c,d FROM t1; INSERT INTO t1 SELECT null, 2*a,2*b,2*c,d FROM t1; ]]) - local b = 0 + local b for i = 0, 31 do if (i < 8) then b = 0 diff --git a/test/sql-tap/gh-4077-iproto-execute-no-bind.test.lua b/test/sql-tap/gh-4077-iproto-execute-no-bind.test.lua index d4b597e35..2f71a68ea 100755 --- a/test/sql-tap/gh-4077-iproto-execute-no-bind.test.lua +++ b/test/sql-tap/gh-4077-iproto-execute-no-bind.test.lua @@ -41,10 +41,11 @@ local size = msgpack.encode(header:len() + body:len()) sock:write(size .. header .. body) -- Read response. -local size = msgpack.decode(sock:read(5)) +size = msgpack.decode(sock:read(5)) local header_body = sock:read(size) -local header, header_len = msgpack.decode(header_body) -local body = msgpack.decode(header_body:sub(header_len)) +local header_len +header, header_len = msgpack.decode(header_body) +body = msgpack.decode(header_body:sub(header_len)) sock:close() -- Verify response. diff --git a/test/sql-tap/index1.test.lua b/test/sql-tap/index1.test.lua index e173e685c..4c4a37ca7 100755 --- a/test/sql-tap/index1.test.lua +++ b/test/sql-tap/index1.test.lua @@ -106,7 +106,6 @@ test:do_test( test:do_test( "index-2.2", function() - local msg local v , msg= pcall(function() test:execsql("CREATE INDEX index1 ON test1(f1, f2, f4, f3)") end) diff --git a/test/sql-tap/join3.test.lua b/test/sql-tap/join3.test.lua index 876b3121a..030fbaba3 100755 --- a/test/sql-tap/join3.test.lua +++ b/test/sql-tap/join3.test.lua @@ -49,7 +49,7 @@ for N=1, bitmask_size do end -- Joins with a comparison -- -local result = {} +result = {} --for _ in X(0, "X!for", [=[["set N 1","$N<=$bitmask_size","incr N"]]=]) do for N=1, bitmask_size do table.insert(result,N) diff --git a/test/sql-tap/select9.test.lua b/test/sql-tap/select9.test.lua index 1ae16a658..bcc270593 100755 --- a/test/sql-tap/select9.test.lua +++ b/test/sql-tap/select9.test.lua @@ -60,10 +60,8 @@ function subrange(t, first, last) end local function test_compound_select(testname, sql, result) - local nCol = 1 local A = box.execute(sql) --test.box(sql) - nCol = #A.metadata - A = A.rows + local nCol = #A.metadata local nRow = #result / nCol local compound_sql = sql test:do_execsql_test( @@ -274,10 +272,8 @@ test:do_execsql_test( -- </select9-2.0> }) -local t1_space_id = "" -local t2_space_id = "" -t1_space_id = test:execsql([[SELECT * from "_space" where "name"='T1']])["id"] -t2_space_id = test:execsql([[SELECT * from "_space" where "name"='T2']])["id"] +local t1_space_id = test:execsql([[SELECT * from "_space" where "name"='T1']])["id"] +local t2_space_id = test:execsql([[SELECT * from "_space" where "name"='T2']])["id"] --X(276, "X!cmd", [=[["db","eval","SELECT * from _space where name='t2'","data","\n set t2_space_id $data(id)\n"]]=]) --local function reverse(lhs, rhs) -- return X(283, "X!cmd", [=[["string","compare",["rhs"],["lhs"]]]=]) diff --git a/test/sql-tap/tkt-fa7bf5ec.test.lua b/test/sql-tap/tkt-fa7bf5ec.test.lua index 7152e028c..25d44c9d3 100755 --- a/test/sql-tap/tkt-fa7bf5ec.test.lua +++ b/test/sql-tap/tkt-fa7bf5ec.test.lua @@ -20,9 +20,9 @@ test:plan(1) -- The problem described by this ticket was that the sqlExprCompare() -- function was saying that expressions (x='a') and (x='A') were identical -- because it was using sqlStrICmp() instead of strcmp() to compare string --- literals. That was causing the query optimizer for aggregate queries to --- believe that both count() operations were identical, and thus only --- computing the first count() and making a copy of the result for the +-- literals. That was causing the query optimizer for aggregate queries to +-- believe that both count() operations were identical, and thus only +-- computing the first count() and making a copy of the result for the -- second count(). -- -- ["set","testdir",[["file","dirname",["argv0"]]]] diff --git a/test/sql-tap/where2.test.lua b/test/sql-tap/where2.test.lua index f267be8e6..f2db6fcee 100755 --- a/test/sql-tap/where2.test.lua +++ b/test/sql-tap/where2.test.lua @@ -115,7 +115,7 @@ local function queryplan(sql) table.insert(data, tab) table.insert(data, idx) else - as, tab = string.match(v, "TABLE (%w+ AS) (%w+)") + _, tab = string.match(v, "TABLE (%w+ AS) (%w+)") if tab == nil then tab = string.match(v, "TABLE (%w+)") end diff --git a/test/sql/lua/sql_tokenizer.lua b/test/sql/lua/sql_tokenizer.lua index 9922d792d..ffe4fb4e8 100644 --- a/test/sql/lua/sql_tokenizer.lua +++ b/test/sql/lua/sql_tokenizer.lua @@ -134,7 +134,7 @@ end -- @retval Token type. If the rest of the SQL request consists of -- spaces and comments, then return TK_EMPTY. local function get_next_token(context) - local c = '' + local c repeat local i = context.offset c = context.sql:sub(i, i) diff --git a/test/sql/savepoints.result b/test/sql/savepoints.result index 509c33e59..b0915f398 100644 --- a/test/sql/savepoints.result +++ b/test/sql/savepoints.result @@ -102,12 +102,12 @@ collision_sv_2 = function() box.begin() box.execute('SAVEPOINT t1;') box.execute('SAVEPOINT t2;') - local _,err = box.execute('SAVEPOINT t1;') + local _, err = box.execute('SAVEPOINT t1;') assert(err == nil) box.execute('RELEASE SAVEPOINT t1;') - local _,err = box.execute('RELEASE SAVEPOINT t1;') + _, err = box.execute('RELEASE SAVEPOINT t1;') assert(err ~= nil) - local _, err = box.execute('ROLLBACK TO t2;') + _, err = box.execute('ROLLBACK TO t2;') assert(err == nil) end; --- diff --git a/test/sql/savepoints.test.lua b/test/sql/savepoints.test.lua index f1b15c748..eb7bea37d 100644 --- a/test/sql/savepoints.test.lua +++ b/test/sql/savepoints.test.lua @@ -65,12 +65,12 @@ collision_sv_2 = function() box.begin() box.execute('SAVEPOINT t1;') box.execute('SAVEPOINT t2;') - local _,err = box.execute('SAVEPOINT t1;') + local _, err = box.execute('SAVEPOINT t1;') assert(err == nil) box.execute('RELEASE SAVEPOINT t1;') - local _,err = box.execute('RELEASE SAVEPOINT t1;') + _, err = box.execute('RELEASE SAVEPOINT t1;') assert(err ~= nil) - local _, err = box.execute('ROLLBACK TO t2;') + _, err = box.execute('ROLLBACK TO t2;') assert(err == nil) end; collision_sv_2(); diff --git a/test/sql/triggers.result b/test/sql/triggers.result index ceecb8ef2..e70d72947 100644 --- a/test/sql/triggers.result +++ b/test/sql/triggers.result @@ -11,7 +11,7 @@ _ = box.space._session_settings:update('sql_default_engine', {{'=', 2, engine}}) --- ... -- Get invariant part of the tuple; name and opts don't change. - function immutable_part(data) local r = {} for i, l in pairs(data) do table.insert(r, {l.name, l.opts}) end return r end + function immutable_part(data) local r = {} for _, l in pairs(data) do table.insert(r, {l.name, l.opts}) end return r end --- ... -- diff --git a/test/sql/triggers.test.lua b/test/sql/triggers.test.lua index f5c8a3961..bc694ebc4 100644 --- a/test/sql/triggers.test.lua +++ b/test/sql/triggers.test.lua @@ -4,7 +4,7 @@ engine = test_run:get_cfg('engine') _ = box.space._session_settings:update('sql_default_engine', {{'=', 2, engine}}) -- Get invariant part of the tuple; name and opts don't change. - function immutable_part(data) local r = {} for i, l in pairs(data) do table.insert(r, {l.name, l.opts}) end return r end + function immutable_part(data) local r = {} for _, l in pairs(data) do table.insert(r, {l.name, l.opts}) end return r end -- -- gh-3273: Move Triggers to server diff --git a/test/vinyl/large.lua b/test/vinyl/large.lua index e10e94c1a..a997aec7e 100644 --- a/test/vinyl/large.lua +++ b/test/vinyl/large.lua @@ -1,5 +1,4 @@ -fiber = require('fiber') -digest = require('digest') +local digest = require('digest') local PAGE_SIZE = 1024 local RANGE_SIZE = 64 * PAGE_SIZE diff --git a/test/vinyl/txn_proxy.lua b/test/vinyl/txn_proxy.lua index 7a4d0b865..15b0e4add 100644 --- a/test/vinyl/txn_proxy.lua +++ b/test/vinyl/txn_proxy.lua @@ -1,11 +1,11 @@ --- A fiber can't use multiple transactions simultaneously; +-- A fiber can't use multiple transactions simultaneously; -- i.e. [fiber] --? [transaction] in UML parlor. -- -- This module provides a simple transaction proxy facility --- to control multiple transactions at once. A proxy executes +-- to control multiple transactions at once. A proxy executes -- statements in a worker fiber in order to overcome -- "one transaction per fiber" limitation. --- +-- -- Ex: -- proxy = require('txn_proxy').new() -- proxy:begin() diff --git a/test/vinyl/vinyl.lua b/test/vinyl/vinyl.lua index 31307f4bc..02b5c010b 100644 --- a/test/vinyl/vinyl.lua +++ b/test/vinyl/vinyl.lua @@ -15,7 +15,7 @@ box.cfg { vinyl_max_tuple_size = 1024 * 1024 * 6, } -function box_info_sort(data) +local function box_info_sort(data) if type(data)~='table' then return data end diff --git a/test/wal_off/rtree_benchmark.result b/test/wal_off/rtree_benchmark.result index 8e01c9f2a..8deefca82 100644 --- a/test/wal_off/rtree_benchmark.result +++ b/test/wal_off/rtree_benchmark.result @@ -163,7 +163,7 @@ for i = 1, 0 do for j = 1, dimension do table.insert(rect, 180*math.random()) end - for k,v in pairs(s.index.spatial:select(rect, {limit = n_neighbors, iterator = 'NEIGHBOR'})) do + for _,_ in pairs(s.index.spatial:select(rect, {limit = n_neighbors, iterator = 'NEIGHBOR'})) do n = n + 1 end end; diff --git a/test/wal_off/rtree_benchmark.test.lua b/test/wal_off/rtree_benchmark.test.lua index 6fae977c9..6bdc0a758 100644 --- a/test/wal_off/rtree_benchmark.test.lua +++ b/test/wal_off/rtree_benchmark.test.lua @@ -96,7 +96,7 @@ for i = 1, 0 do for j = 1, dimension do table.insert(rect, 180*math.random()) end - for k,v in pairs(s.index.spatial:select(rect, {limit = n_neighbors, iterator = 'NEIGHBOR'})) do + for _,_ in pairs(s.index.spatial:select(rect, {limit = n_neighbors, iterator = 'NEIGHBOR'})) do n = n + 1 end end; diff --git a/test/xlog-py/box.lua b/test/xlog-py/box.lua index c87f7b94b..8b9e9434f 100644 --- a/test/xlog-py/box.lua +++ b/test/xlog-py/box.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/xlog/panic.lua b/test/xlog/panic.lua index 2d4eb8d2e..0fa855421 100644 --- a/test/xlog/panic.lua +++ b/test/xlog/panic.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/xlog/reader.result b/test/xlog/reader.result index 9985aa2ac..74ac3579e 100644 --- a/test/xlog/reader.result +++ b/test/xlog/reader.result @@ -40,7 +40,7 @@ trun:cmd("setopt delimiter ';'") ... function collect_results(file) local val = {} - for k, v in xlog(file) do + for _, v in xlog(file) do table.insert(val, setmetatable(v, { __serialize = "map"})) end return val diff --git a/test/xlog/reader.test.lua b/test/xlog/reader.test.lua index 327af54dd..707ba394b 100644 --- a/test/xlog/reader.test.lua +++ b/test/xlog/reader.test.lua @@ -21,7 +21,7 @@ pattern_ok_v13 = fio.pathjoin(pattern_prefix, "v13/") trun:cmd("setopt delimiter ';'") function collect_results(file) local val = {} - for k, v in xlog(file) do + for _, v in xlog(file) do table.insert(val, setmetatable(v, { __serialize = "map"})) end return val diff --git a/test/xlog/snap_io_rate.test.lua b/test/xlog/snap_io_rate.test.lua index f71296269..5626ea1f4 100644 --- a/test/xlog/snap_io_rate.test.lua +++ b/test/xlog/snap_io_rate.test.lua @@ -9,6 +9,6 @@ for i = 0, 127 do box.space.snap:replace({i, digest.urandom(512 * 1024)}) end t1 = fiber.time() box.snapshot() t2 = fiber.time() -t2 - t1 > 64 / box.cfg.snap_io_rate_limit * 0.95 +assert(t2 - t1 > 64 / box.cfg.snap_io_rate_limit * 0.95) box.space.snap:drop() diff --git a/test/xlog/transaction.result b/test/xlog/transaction.result index 63adb0f25..d45b60b0a 100644 --- a/test/xlog/transaction.result +++ b/test/xlog/transaction.result @@ -16,7 +16,7 @@ test_run:cmd("setopt delimiter ';'") ... function read_xlog(file) local val = {} - for k, v in xlog(file) do + for _, v in xlog(file) do table.insert(val, setmetatable(v, { __serialize = "map"})) end return val diff --git a/test/xlog/transaction.test.lua b/test/xlog/transaction.test.lua index 2d8090b4c..5fdeec625 100644 --- a/test/xlog/transaction.test.lua +++ b/test/xlog/transaction.test.lua @@ -6,7 +6,7 @@ test_run = env.new() test_run:cmd("setopt delimiter ';'") function read_xlog(file) local val = {} - for k, v in xlog(file) do + for _, v in xlog(file) do table.insert(val, setmetatable(v, { __serialize = "map"})) end return val diff --git a/test/xlog/xlog.lua b/test/xlog/xlog.lua index 004096d2d..aaf1a0ae6 100644 --- a/test/xlog/xlog.lua +++ b/test/xlog/xlog.lua @@ -1,5 +1,5 @@ #!/usr/bin/env tarantool -os = require('os') +local os = require('os') box.cfg{ listen = os.getenv("LISTEN"), -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ Sergey Bronnikov @ 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-17 12:05 ` Igor Munkin 2020-04-17 19:47 ` Sergey Bronnikov 2020-04-16 13:43 ` Igor Munkin 1 sibling, 2 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:29 UTC (permalink / raw) To: Sergey Bronnikov, tarantool-patches, avtikhon, alexander.turenko, o.piskunov Thanks for the patch! Consider more fixes below and on the branch in a separate commit. That allowed to remove some warning mutes from the luacheck config. ==================== Review fixes: test/ diff --git a/test/app-tap/console_lua.test.lua b/test/app-tap/console_lua.test.lua index 3ed6aad97..d0e290d9c 100755 --- a/test/app-tap/console_lua.test.lua +++ b/test/app-tap/console_lua.test.lua @@ -13,7 +13,7 @@ local CONSOLE_SOCKET = 'console-lua.sock' -- -- Set Lua output mode. local function set_lua_output(client, opts) - local opts = opts or {} + opts = opts or {} local mode = opts.block and 'lua,block' or 'lua' client:write(('\\set output %s\n'):format(mode)) assert(client:read(EOL), 'true' .. EOL, 'set lua output mode') diff --git a/test/app-tap/fail_main.test.lua b/test/app-tap/fail_main.test.lua index f8c45bf6f..917577f46 100755 --- a/test/app-tap/fail_main.test.lua +++ b/test/app-tap/fail_main.test.lua @@ -16,7 +16,7 @@ function run_script(code) script:close() local output_file = fio.pathjoin(fio.cwd(), 'out.txt') local cmd = [[/bin/sh -c 'cd "%s" && "%s" ./script.lua 0> %s 2> %s']] - local code = os.execute( + code = os.execute( string.format(cmd, dir, tarantool_bin, output_file, output_file) ) fio.rmtree(dir) diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 4d7059559..3fda53274 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -97,23 +97,14 @@ local function tctl_wait_start(dir, name) fiber.sleep(0.01) end ::again:: - while true do - local stat, nb = pcall(require('net.box').new, path, { - wait_connected = true, console = true - }) - if stat == false then - fiber.sleep(0.01) - goto again - else - break - end - local stat, msg = pcall(nb.eval, nb, 'require("fiber").time()') - if stat == false then - fiber.sleep(0.01) - else - break - end + local stat, nb = pcall(require('net.box').new, path, { + wait_connected = true, console = true + }) + if stat == false then + fiber.sleep(0.01) + goto again end + return end end ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-14 23:29 ` Vladislav Shpilevoy @ 2020-04-17 12:05 ` Igor Munkin 2020-04-17 19:51 ` Sergey Bronnikov 2020-04-17 19:47 ` Sergey Bronnikov 1 sibling, 1 reply; 28+ messages in thread From: Igor Munkin @ 2020-04-17 12:05 UTC (permalink / raw) To: Vladislav Shpilevoy; +Cc: o.piskunov, tarantool-patches Vlad, Thanks for the fixes! On 15.04.20, Vladislav Shpilevoy wrote: > Thanks for the patch! > > Consider more fixes below and on the branch in a separate commit. > That allowed to remove some warning mutes from the luacheck > config. > > ==================== > > Review fixes: test/ > <snipped> > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index 4d7059559..3fda53274 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -97,23 +97,14 @@ local function tctl_wait_start(dir, name) > fiber.sleep(0.01) > end > ::again:: > - while true do > - local stat, nb = pcall(require('net.box').new, path, { > - wait_connected = true, console = true > - }) > - if stat == false then > - fiber.sleep(0.01) > - goto again > - else > - break > - end > - local stat, msg = pcall(nb.eval, nb, 'require("fiber").time()') > - if stat == false then > - fiber.sleep(0.01) > - else > - break > - end > + local stat, nb = pcall(require('net.box').new, path, { I guess you can drop nb here, since it's unused. > + wait_connected = true, console = true > + }) > + if stat == false then > + fiber.sleep(0.01) > + goto again > end > + return > end > end > -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-17 12:05 ` Igor Munkin @ 2020-04-17 19:51 ` Sergey Bronnikov 0 siblings, 0 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-17 19:51 UTC (permalink / raw) To: Igor Munkin; +Cc: o.piskunov, tarantool-patches, Vladislav Shpilevoy Igor, On 15:05 Fri 17 Apr , Igor Munkin wrote: <snipped> > > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > > index 4d7059559..3fda53274 100755 > > --- a/test/app-tap/tarantoolctl.test.lua > > +++ b/test/app-tap/tarantoolctl.test.lua > > @@ -97,23 +97,14 @@ local function tctl_wait_start(dir, name) > > fiber.sleep(0.01) > > end > > ::again:: > > - while true do > > - local stat, nb = pcall(require('net.box').new, path, { > > - wait_connected = true, console = true > > - }) > > - if stat == false then > > - fiber.sleep(0.01) > > - goto again > > - else > > - break > > - end > > - local stat, msg = pcall(nb.eval, nb, 'require("fiber").time()') > > - if stat == false then > > - fiber.sleep(0.01) > > - else > > - break > > - end > > + local stat, nb = pcall(require('net.box').new, path, { > > I guess you can drop nb here, since it's unused. 'nb' variable has been removed and patch updated, thanks! <snipped> ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-17 12:05 ` Igor Munkin @ 2020-04-17 19:47 ` Sergey Bronnikov 1 sibling, 0 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-17 19:47 UTC (permalink / raw) To: Vladislav Shpilevoy; +Cc: o.piskunov, tarantool-patches Vladislav, thanks for review and patch! On 01:29 Wed 15 Apr , Vladislav Shpilevoy wrote: > Thanks for the patch! > > Consider more fixes below and on the branch in a separate commit. > That allowed to remove some warning mutes from the luacheck > config. > > ==================== > > Review fixes: test/ > > diff --git a/test/app-tap/console_lua.test.lua b/test/app-tap/console_lua.test.lua > index 3ed6aad97..d0e290d9c 100755 > --- a/test/app-tap/console_lua.test.lua > +++ b/test/app-tap/console_lua.test.lua > @@ -13,7 +13,7 @@ local CONSOLE_SOCKET = 'console-lua.sock' > -- > -- Set Lua output mode. > local function set_lua_output(client, opts) > - local opts = opts or {} > + opts = opts or {} > local mode = opts.block and 'lua,block' or 'lua' > client:write(('\\set output %s\n'):format(mode)) > assert(client:read(EOL), 'true' .. EOL, 'set lua output mode') > diff --git a/test/app-tap/fail_main.test.lua b/test/app-tap/fail_main.test.lua > index f8c45bf6f..917577f46 100755 > --- a/test/app-tap/fail_main.test.lua > +++ b/test/app-tap/fail_main.test.lua > @@ -16,7 +16,7 @@ function run_script(code) > script:close() > local output_file = fio.pathjoin(fio.cwd(), 'out.txt') > local cmd = [[/bin/sh -c 'cd "%s" && "%s" ./script.lua 0> %s 2> %s']] > - local code = os.execute( > + code = os.execute( > string.format(cmd, dir, tarantool_bin, output_file, output_file) > ) > fio.rmtree(dir) > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index 4d7059559..3fda53274 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -97,23 +97,14 @@ local function tctl_wait_start(dir, name) > fiber.sleep(0.01) > end > ::again:: > - while true do > - local stat, nb = pcall(require('net.box').new, path, { > - wait_connected = true, console = true > - }) > - if stat == false then > - fiber.sleep(0.01) > - goto again > - else > - break > - end > - local stat, msg = pcall(nb.eval, nb, 'require("fiber").time()') > - if stat == false then > - fiber.sleep(0.01) > - else > - break > - end > + local stat, nb = pcall(require('net.box').new, path, { > + wait_connected = true, console = true > + }) > + if stat == false then > + fiber.sleep(0.01) > + goto again > end > + return > end > end > -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy @ 2020-04-16 13:43 ` Igor Munkin 1 sibling, 0 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-16 13:43 UTC (permalink / raw) To: Sergey Bronnikov; +Cc: o.piskunov, tarantool-patches Sergey, Thanks for the patch! I left several comments and changes reducing amount of warnings, please consider them. On 14.04.20, Sergey Bronnikov wrote: > Closes #4681 > > Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> > --- > > test/app-tap/console.test.lua | 4 --- > test/app-tap/csv.test.lua | 28 +++++++++---------- > test/app-tap/logger.test.lua | 2 +- > test/box-py/box.lua | 2 +- > test/box-tap/gc.test.lua | 4 +-- > test/box/box.lua | 2 +- > test/box/hash_multipart.result | 2 +- > test/box/hash_multipart.test.lua | 2 +- > 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/utils.lua | 3 +- > 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 +-- > test/engine/tree_min_max_count.result | 2 +- > test/engine/tree_min_max_count.test.lua | 2 +- > test/replication-py/master.lua | 2 +- > test/replication-py/panic.lua | 2 +- > test/replication/master.lua | 2 +- > test/replication/replicaset_ro_mostly.result | 2 +- > .../replication/replicaset_ro_mostly.test.lua | 2 +- > test/sql-tap/analyze3.test.lua | 6 ++-- > test/sql-tap/analyze9.test.lua | 16 +++++------ > .../gh-4077-iproto-execute-no-bind.test.lua | 7 +++-- > test/sql-tap/index1.test.lua | 1 - > test/sql-tap/join3.test.lua | 2 +- > test/sql-tap/select9.test.lua | 10 ++----- > test/sql-tap/tkt-fa7bf5ec.test.lua | 6 ++-- > test/sql-tap/where2.test.lua | 2 +- > test/sql/lua/sql_tokenizer.lua | 2 +- > test/sql/savepoints.result | 6 ++-- > test/sql/savepoints.test.lua | 6 ++-- > test/sql/triggers.result | 2 +- > test/sql/triggers.test.lua | 2 +- > test/vinyl/large.lua | 3 +- > test/vinyl/txn_proxy.lua | 6 ++-- > test/vinyl/vinyl.lua | 2 +- > test/wal_off/rtree_benchmark.result | 2 +- > test/wal_off/rtree_benchmark.test.lua | 2 +- > test/xlog-py/box.lua | 2 +- > test/xlog/panic.lua | 2 +- > test/xlog/reader.result | 2 +- > test/xlog/reader.test.lua | 2 +- > test/xlog/snap_io_rate.test.lua | 2 +- > test/xlog/transaction.result | 2 +- > test/xlog/transaction.test.lua | 2 +- > test/xlog/xlog.lua | 2 +- > 55 files changed, 92 insertions(+), 102 deletions(-) > Fixed a single warning left in test/app-tap/cfg.test.lua: ================================================================================ diff --git a/test/app-tap/cfg.test.lua b/test/app-tap/cfg.test.lua index ba6b735ab..14e040f9f 100755 --- a/test/app-tap/cfg.test.lua +++ b/test/app-tap/cfg.test.lua @@ -12,7 +12,7 @@ test:plan(11) local nil_uuid = '00000000-0000-0000-0000-000000000000' local ok = pcall(box.cfg, {instance_uuid = nil_uuid}) test:ok(not ok, 'nil instance UUID is not allowed') -ok, err = pcall(box.cfg, {replicaset_uuid = nil_uuid}) +ok = pcall(box.cfg, {replicaset_uuid = nil_uuid}) test:ok(not ok, 'nil replicaset UUID is not allowed') test:is(type(box.ctl), "table", "box.ctl is available before box.cfg") ================================================================================ Fixed all warnings in test/app-tap/clock.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/clock.test.lua b/test/app-tap/clock.test.lua index fd1c4f272..d1ea4f0a8 100755 --- a/test/app-tap/clock.test.lua +++ b/test/app-tap/clock.test.lua @@ -1,7 +1,7 @@ #!/usr/bin/env tarantool -clock = require("clock") -test = require("tap").test("csv") +local clock = require("clock") +local test = require("tap").test("csv") test:plan(10) test:ok(clock.realtime() > 0, "realtime") test:ok(clock.thread() > 0, "thread") ================================================================================ Fixed a simple warning in test/app-tap/console_lua.test.lua: ================================================================================ diff --git a/test/app-tap/console_lua.test.lua b/test/app-tap/console_lua.test.lua index 3ed6aad97..24f9744bb 100755 --- a/test/app-tap/console_lua.test.lua +++ b/test/app-tap/console_lua.test.lua @@ -83,7 +83,7 @@ local function execute_and_verify(test, client, input, exp_output, name) test:ok(res ~= nil, ('-> [[%s]]'):format(input)) local exp = exp_output .. EOL - local res = client:read(EOL) + res = client:read(EOL) test:is(res, exp, ('<- [[%s]]'):format(exp:gsub('\n', '\\n'))) end) end ================================================================================ > diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua > index 4feadfa5e..1f61ba837 100755 > --- a/test/app-tap/console.test.lua > +++ b/test/app-tap/console.test.lua In addition to your changes the fix below solves 98/99 remaining warnings in this file: ================================================================================ diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua index 1f61ba837..65cf40485 100755 --- a/test/app-tap/console.test.lua +++ b/test/app-tap/console.test.lua @@ -18,7 +18,8 @@ os.remove(IPROTO_SOCKET) -- local EOL = "\n...\n" -test = tap.test("console") +local test = tap.test("console") +local _ test:plan(80) @@ -58,7 +59,8 @@ test:is(client:read(";"), 'true;', "pushed message") client:write('\\set output lua\n') client:read(";") -long_func_f = nil +local long_func_f +-- luacheck: globals long_func (is called via client socket) function long_func() long_func_f = fiber.self() box.session.push('push') @@ -229,13 +231,13 @@ box.cfg{listen = ''} os.remove(IPROTO_SOCKET) local s = console.listen('127.0.0.1:0') -addr = s:name() +local addr = s:name() test:is(addr.family, 'AF_INET', 'console.listen uri support') test:is(addr.host, '127.0.0.1', 'console.listen uri support') test:isnt(addr.port, 0, 'console.listen uri support') s:close() -local s = console.listen('console://unix/:'..CONSOLE_SOCKET) +s = console.listen('console://unix/:'..CONSOLE_SOCKET) addr = s:name() test:is(addr.family, 'AF_UNIX', 'console.listen uri support') test:is(addr.host, 'unix/', 'console.listen uri support') ================================================================================ <snipped> > diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua > index a7f17b1ea..689db7997 100755 > --- a/test/app-tap/csv.test.lua > +++ b/test/app-tap/csv.test.lua In addition to your changes the fix below solves all remaining warnings in this file: ================================================================================ diff --git a/test/app-tap/csv.test.lua b/test/app-tap/csv.test.lua index 689db7997..b17c48664 100755 --- a/test/app-tap/csv.test.lua +++ b/test/app-tap/csv.test.lua @@ -35,10 +35,10 @@ local test6_ans = "|23|\t|456|\t|abcac|\t|'multiword field 4'|\t\n|none|" .. "|len|\t|offset)|\t\n|iflag = bit.bor(iflag|\t|fio.c.f" .. "lag[ flag ])|\t\n||\t||\t||\t\n" -test = tap.test("csv") +local test = tap.test("csv") test:plan(12) -readable = {} +local readable = {} readable.read = myread readable.v = "a,b\n1,\"ha\n\"\"ha\"\"\nha\"\n3,4\n" readable.i = 0 @@ -52,11 +52,11 @@ readable.v = ", \r\nkp\"\"v" readable.i = 0 test:is(table2str(csv.load(readable, {chunk_size = 3})), test3_ans, "obj test3") -tmpdir = fio.tempdir() -file1 = fio.pathjoin(tmpdir, 'file.1') -file2 = fio.pathjoin(tmpdir, 'file.2') -file3 = fio.pathjoin(tmpdir, 'file.3') -file4 = fio.pathjoin(tmpdir, 'file.4') +local tmpdir = fio.tempdir() +local file1 = fio.pathjoin(tmpdir, 'file.1') +local file2 = fio.pathjoin(tmpdir, 'file.2') +local file3 = fio.pathjoin(tmpdir, 'file.3') +local file4 = fio.pathjoin(tmpdir, 'file.4') local f = fio.open(file1, { 'O_WRONLY', 'O_TRUNC', 'O_CREAT' }, tonumber('0777', 8)) f:write("123 , 5 , 92 , 0, 0\n" .. @@ -83,12 +83,12 @@ test:is(table2str(csv.load(f, {chunk_size = 1})), test5_ans, "fio test2") f:close() f = fio.open(file2, {'O_RDONLY'}) -opts = {chunk_size = 7, skip_head_lines = 1} +local opts = {chunk_size = 7, skip_head_lines = 1} --7 symbols per chunk test:is(table2str(csv.load(f, opts)), test6_ans, "fio test3") f:close() -t = { +local t = { {'quote" d', ',and, comma', 'both " of " t,h,e,m'}, {'"""', ',","'}, {'mul\nti\nli\r\nne\n\n', 'field'}, @@ -101,7 +101,7 @@ f = require("fio").open(file3, { "O_WRONLY", "O_TRUNC" , "O_CREAT"}, 0x1FF) csv.dump(t, {}, f) f:close() f = fio.open(file3, {'O_RDONLY'}) -t2 = csv.load(f, {chunk_size = 5}) +local t2 = csv.load(f, {chunk_size = 5}) f:close() test:is(table2str(t), table2str(t2), "test roundtrip") ================================================================================ <snipped> Fixed a couple warnings in test/app-tap/cfg.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/debug.test.lua b/test/app-tap/debug.test.lua index 0d199e55b..184bcc904 100755 --- a/test/app-tap/debug.test.lua +++ b/test/app-tap/debug.test.lua @@ -44,7 +44,7 @@ print(('debug.sourcefile() => %s; %s'):format(tostring(result), tostring(err))) assert(result == box.NULL, 'debug.sourcefile() returns box.NULL') assert(err == nil, 'debug.sourcefile() returns no error') -local result, err = conn:call('debug.sourcedir') +result, err = conn:call('debug.sourcedir') print(('debug.sourcedir() => %s; %s'):format(tostring(result), tostring(err))) assert(result == '.', 'debug.sourcedir() returns "."') assert(err == nil, 'debug.sourcedir() returns no error') @@ -74,7 +74,7 @@ if not dirstat then end assert(dirstat:is_dir(), dirname..' must be a directory') -local cmd = TNTBIN..' '..filename +cmd = TNTBIN..' '..filename print('======================================') print('When running lua code from script file') print('======================================') ================================================================================ Fixed all warnings in test/app-tap/fail_main.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/fail_main.test.lua b/test/app-tap/fail_main.test.lua index f8c45bf6f..3fe0971eb 100755 --- a/test/app-tap/fail_main.test.lua +++ b/test/app-tap/fail_main.test.lua @@ -7,7 +7,7 @@ local tarantool_bin = arg[-1] test:plan(1) -function run_script(code) +local function run_script(code) local dir = fio.tempdir() local script_path = fio.pathjoin(dir, 'script.lua') local script = fio.open(script_path, {'O_CREAT', 'O_WRONLY', 'O_APPEND'}, @@ -30,7 +30,7 @@ end -- gh-4382: an error in main script should be handled gracefully, -- with proper logging. -- -local code, output = run_script("error('Error in the main script')") +local _, output = run_script("error('Error in the main script')") test:ok(output:match("fatal error, exiting the event loop"), "main script error is handled gracefully") ================================================================================ Fixed all warnings in test/app-tap/gh-4761-json-per-call-options.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/gh-4761-json-per-call-options.test.lua b/test/app-tap/gh-4761-json-per-call-options.test.lua index 1fb24744e..6dfce51fd 100755 --- a/test/app-tap/gh-4761-json-per-call-options.test.lua +++ b/test/app-tap/gh-4761-json-per-call-options.test.lua @@ -12,24 +12,23 @@ local tap = require('tap') local res = tap.test('gh-4761-json-per-call-options', function(test) test:plan(2) + local ok, res, exp_res -- Preparation code: call :decode() with a custom option. - local ok, err = pcall(json.decode, '{"foo": {"bar": 1}}', - {decode_max_depth = 1}) + ok = pcall(json.decode, '{"foo": {"bar": 1}}', {decode_max_depth = 1}) assert(not ok, 'expect "too many nested data structures" error') -- Verify that the instance option remains unchanged. - local exp_res = {foo = {bar = 1}} - local ok, res = pcall(json.decode, '{"foo": {"bar": 1}}') + exp_res = {foo = {bar = 1}} + ok, res = pcall(json.decode, '{"foo": {"bar": 1}}') test:is_deeply({ok, res}, {true, exp_res}, 'json instance settings remain unchanged after :decode()') -- Same check for json.encode. local nan = 1/0 - local ok, err = pcall(json.encode, {a = nan}, - {encode_invalid_numbers = false}) + ok = pcall(json.encode, {a = nan}, {encode_invalid_numbers = false}) assert(not ok, 'expected "number must not be NaN or Inf" error') - local exp_res = '{"a":inf}' - local ok, res = pcall(json.encode, {a = nan}) + exp_res = '{"a":inf}' + ok, res = pcall(json.encode, {a = nan}) test:is_deeply({ok, res}, {true, exp_res}, 'json instance settings remain unchanged after :encode()') end) ================================================================================ Fixed several warnings in test/app-tap/http_client.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/http_client.test.lua b/test/app-tap/http_client.test.lua index b85b605cf..f5bfe9b2a 100755 --- a/test/app-tap/http_client.test.lua +++ b/test/app-tap/http_client.test.lua @@ -42,7 +42,7 @@ local function start_server(test, sock_family, sock_addr) test:is(server:read("*l"), "heartbeat", "server started") test:diag("trying to connect to %s", url) local r - for i=1,10 do + for _ = 1, 10 do r = client.get(url, merge(opts, {timeout = 0.01})) if r.status == 200 then break @@ -82,7 +82,7 @@ local function test_http_client(test, url, opts) "content-length > 0") test:is(client.get("http://localhost:1/").status, 595, 'cannot connect') - local r = client.request('GET', url, nil, opts) + r = client.request('GET', url, nil, opts) test:is(r.status, 200, 'request') -- XXX: enable after resolving of gh-4180: httpc: redirects @@ -120,7 +120,7 @@ end -- local function test_http_client_headers_redefine(test, url, opts) test:plan(9) - local opts = table.deepcopy(opts) + opts = table.deepcopy(opts) -- Test defaults opts.headers = {['Connection'] = nil, ['Accept'] = nil} local r = client.post(url, nil, opts) @@ -132,7 +132,7 @@ local function test_http_client_headers_redefine(test, url, opts) opts.headers={['Connection'] = 'close'} opts.keepalive_idle = 2 opts.keepalive_interval = 1 - local r = client.get(url, opts) + r = client.get(url, opts) test:is(r.status, 200, 'simple 200') test:is(r.headers['connection'], 'close', 'Redefined Connection header') test:is(r.headers['keep_alive'], 'timeout=2', @@ -140,7 +140,7 @@ local function test_http_client_headers_redefine(test, url, opts) -- Test that user-defined Connection and Acept headers -- are used opts.headers={['Connection'] = 'Keep-Alive', ['Accept'] = 'text/html'} - local r = client.get(url, opts) + r = client.get(url, opts) test:is(r.status, 200, 'simple 200') test:is(r.headers['accept'], 'text/html', 'Redefined Accept header') test:is(r.headers['connection'], 'Keep-Alive', 'Redefined Connection header') @@ -164,7 +164,7 @@ local function test_cancel_and_errinj(test, url, opts) local errinj = box.error.injection errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', true) local topts = merge(opts, {timeout = 1200}) - f = fiber.create(func, topts) + fiber.create(func, topts) r = ch:get() test:is(r.status, 200, "No hangs in errinj") errinj.set('ERRINJ_HTTP_RESPONSE_ADD_WAIT', false) @@ -180,7 +180,6 @@ local function test_post_and_get(test, url, opts) local my_body = { key = "value" } local json_body = json.encode(my_body) local responses = {} - local data = {a = 'b'} headers['Content-Type'] = 'application/json' local fibers = 7 local ch = fiber.channel(fibers) @@ -213,7 +212,7 @@ local function test_post_and_get(test, url, opts) responses.absent_get = http:get(url .. 'absent', opts) ch:put(1) end) - for i=1,fibers do + for _ = 1, fibers do ch:get() end local r = responses.good_get @@ -270,7 +269,6 @@ local function test_errors(test) test:ok(not status and string.find(json.encode(err), "Unsupported protocol"), "POST: exception on bad protocol") - local r = http:get("http://do_not_exist_8ffad33e0cb01e6a01a03d00089e71e5b2b7e9930dfcba.ru") end -- gh-3679 Check that opts.headers values can be strings only. @@ -395,7 +393,7 @@ local function test_headers(test, url, opts) test:isnil(r.headers["very_very_very_long_headers_name1"], "no long header name") test:is(r.headers["very_very_very_long_headers_name"], "true", "truncated name") opts["max_header_name_length"] = 64 - local r = http:get(url .. 'headers', opts) + r = http:get(url .. 'headers', opts) test:is(r.headers["very_very_very_long_headers_name1"], "true", "truncated max_header_name_length") opts["max_header_name_length"] = nil @@ -406,13 +404,13 @@ local function test_headers(test, url, opts) -- "${hname}: ${hvalue}" is 8192 bytes length local hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 2) local headers = {[hname] = hvalue} - local r = http:post(url, nil, merge(opts, {headers = headers})) + r = http:post(url, nil, merge(opts, {headers = headers})) test:is(r.headers[hname], hvalue, '8192 bytes header: success') -- "${hname}: ${hvalue}" is 8193 bytes length local exp_err = 'header is too large' - local hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 1) - local headers = {[hname] = hvalue} + hvalue = string.rep('x', MAX_HEADER_NAME - hname:len() - 1) + headers = {[hname] = hvalue} local ok, err = pcall(http.post, http, url, nil, merge(opts, {headers = headers})) test:is_deeply({ok, tostring(err)}, {false, exp_err}, @@ -425,7 +423,6 @@ local function test_special_methods(test, url, opts) local responses = {} local fibers = 7 local ch = fiber.channel(fibers) - local _ fiber.create(function() responses.patch_data = http:patch(url, "{\"key\":\"val\"}", opts) ch:put(1) @@ -454,7 +451,7 @@ local function test_special_methods(test, url, opts) responses.custom_data = http:request("CUSTOM", url, nil, opts) ch:put(1) end) - for i = 1, fibers do + for _ = 1, fibers do ch:get() end @@ -483,10 +480,6 @@ end local function test_concurrent(test, url, opts) test:plan(3) - local http = client.new() - local headers = { my_header = "1", my_header2 = "2" } - local my_body = { key = "value" } - local json_body = json.encode(my_body) local num_test = 10 local num_load = 10 local curls = { } @@ -497,7 +490,7 @@ local function test_concurrent(test, url, opts) headers["My-header" .. i] = "my-value" end - for i = 1, num_test do + for _ = 1, num_test do table.insert(curls, { url = url, http = client.new(), @@ -515,7 +508,7 @@ local function test_concurrent(test, url, opts) -- Creating concurrent clients for i=1,num_test do local obj = curls[i] - for j=1,num_load do + for _ = 1, num_load do fiber.create(function() local r = obj.http:post(obj.url, obj.body, merge(opts, { headers = obj.headers, @@ -540,13 +533,11 @@ local function test_concurrent(test, url, opts) end local ok_sockets_added = true local ok_active = true - local ok_timeout = true local ok_req = true -- Join test local rest = num_test while true do - local ticks = 0 for i = 1, num_load do local obj = curls[i] -- checking that stats in concurrent are ok @@ -582,7 +573,7 @@ local function test_concurrent(test, url, opts) test:ok(ok_active, "no active requests") end -function run_tests(test, sock_family, sock_addr) +local function run_tests(test, sock_family, sock_addr) test:plan(11) local server, url, opts = start_server(test, sock_family, sock_addr) test:test("http.client", test_http_client, url, opts) ================================================================================ Fixed all warnings in test/app-tap/iconv.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/iconv.test.lua b/test/app-tap/iconv.test.lua index 6f6a04b14..b4e8e7339 100755 --- a/test/app-tap/iconv.test.lua +++ b/test/app-tap/iconv.test.lua @@ -3,7 +3,7 @@ local tap = require('tap') local iconv = require('iconv') -test = tap.test("iconv") +local test = tap.test("iconv") test:plan(11) local simple_str = 'ascii string' @@ -34,7 +34,7 @@ test:is(c8_1251(c1251_16(c16_16be(c16be_8(cyrillic_str)))), cyrillic_str, 'complex multi-format conversion') -- test huge string -huge_str = string.rep(cyrillic_str, 50) +local huge_str = string.rep(cyrillic_str, 50) test:is(c16be_8(c8_16be(huge_str)), huge_str, "huge string") @@ -42,7 +42,7 @@ local stat, err = pcall(iconv.new, 'NOT EXISTS', 'UTF-8') test:is(stat, false, 'error was thrown on bad encoding') test:ok(err:match('Invalid') ~= nil, 'correct error') -local stat, err = pcall(c_ascii_8, cyrillic_str) +stat, err = pcall(c_ascii_8, cyrillic_str) test:is(stat, false, 'error was thrown on sequence') test:ok(err:match('Incomplete multibyte sequence') ~= nil, 'correct error') ================================================================================ Fixed all warnings in test/app-tap/init_script.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/init_script.test.lua b/test/app-tap/init_script.test.lua index 155f149a7..5831ffa77 100755 --- a/test/app-tap/init_script.test.lua +++ b/test/app-tap/init_script.test.lua @@ -9,14 +9,14 @@ box.cfg{ log="tarantool.log" } -yaml = require('yaml') -fiber = require('fiber') +local yaml = require('yaml') +local fiber = require('fiber') if box.space.tweedledum ~= nil then box.space.space1:drop() end -space = box.schema.space.create('tweedledum') +local space = box.schema.space.create('tweedledum') space:create_index('primary', { type = 'hash' }) print[[ @@ -24,7 +24,7 @@ print[[ -- Access to box.cfg from init script -- ]] -t = {} +local t = {} for k,v in pairs(box.cfg) do if k == 'listen' then @@ -44,7 +44,7 @@ local function do_insert() space:insert{1, 2, 4, 8} end -fiber1 = fiber.create(do_insert) +fiber.create(do_insert) print[[ -- @@ -71,12 +71,12 @@ print[[ -- Check that require function(math.floor) reachable in the init script -- ]] -floor = require("math").floor +local floor = require("math").floor print(floor(0.5)) print(floor(0.9)) print(floor(1.1)) -mod = require('require_mod') +local mod = require('require_mod') print(mod.test(10, 15)) -- -- A test case for https://github.com/tarantool/tarantool/issues/53 ================================================================================ Fixed all warnings in test/app-tap/inspector.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/inspector.test.lua b/test/app-tap/inspector.test.lua index ed10020a2..cda3eda2c 100755 --- a/test/app-tap/inspector.test.lua +++ b/test/app-tap/inspector.test.lua @@ -1,9 +1,6 @@ #!/usr/bin/env tarantool -local socket = require('socket') - -test_run = require('test_run') -inspector = test_run.new() +local inspector = require('test_run').new() print('create instance') print(inspector:cmd("create server replica with rpl_master=default, script='box/box.lua'\n")) ================================================================================ Fixed a single warning in test/app-tap/json.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/json.test.lua b/test/app-tap/json.test.lua index fadfc74ec..186d6ad46 100755 --- a/test/app-tap/json.test.lua +++ b/test/app-tap/json.test.lua @@ -2,7 +2,6 @@ package.path = "lua/?.lua;"..package.path -local ffi = require('ffi') local tap = require('tap') local common = require('serializer_test') ================================================================================ > diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua > index 492d5ea0b..6ec85d0e0 100755 > --- a/test/app-tap/logger.test.lua > +++ b/test/app-tap/logger.test.lua <snipped> In addition to your changes the fix below solves several remaining warnings in this file: ================================================================================ diff --git a/test/app-tap/logger.test.lua b/test/app-tap/logger.test.lua index 6ec85d0e0..8f43b1fb3 100755 --- a/test/app-tap/logger.test.lua +++ b/test/app-tap/logger.test.lua @@ -26,7 +26,7 @@ end log.info(message) local line = file:read() test:is(line:sub(-message:len()), message, "message") -s, err = pcall(json.decode, line) +local s = pcall(json.decode, line) test:ok(not s, "plain") -- -- gh-700: Crash on calling log.info() with formatting characters @@ -45,7 +45,7 @@ test:is(file:read():match('I>%s+(.*)'), '{"key":"value"}', "table is handled as log.info({message="value"}) test:is(file:read():match('I>%s+(.*)'), '{"message":"value"}', "table is handled as json") -function help() log.info("gh-2340: %s %s", 'help') end +local function help() log.info("gh-2340: %s %s", 'help') end xpcall(help, function(err) test:ok(err:match("bad argument #3"), "found error string") @@ -56,14 +56,14 @@ file:close() test:ok(log.pid() >= 0, "pid()") --- logger uses 'debug', try to set it to nil +-- luacheck: ignore (logger uses 'debug', try to set it to nil) local debug = nil log.info("debug is nil") debug = require('debug') test:ok(log.info(true) == nil, 'check tarantool crash (gh-2516)') -s, err = pcall(box.cfg, {log_format='json', log="syslog:identity:tarantool"}) +s = pcall(box.cfg, {log_format='json', log="syslog:identity:tarantool"}) test:ok(not s, "check json not in syslog") box.cfg{log=filename, ================================================================================ Fixed all warnings in test/app-tap/minimal.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/minimal.test.lua b/test/app-tap/minimal.test.lua index e44a0f6a7..8b261a03e 100755 --- a/test/app-tap/minimal.test.lua +++ b/test/app-tap/minimal.test.lua @@ -24,13 +24,13 @@ os.execute("tarantool ./script-args.lua 1 2 3") -- -- LUA_PATH and LUA_CPATH argument handling -- -local script = io.open('script-path.lua', 'w') +script = io.open('script-path.lua', 'w') script:write([[ print(package.path) os.exit(0) ]]) script:close() -local script = io.open('script-cpath.lua', 'w') +script = io.open('script-cpath.lua', 'w') script:write([[ print(package.cpath) os.exit(0) ================================================================================ Fixed all warnings in test/app-tap/module_api.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/module_api.test.lua b/test/app-tap/module_api.test.lua index a6658cc61..d7be56a9b 100755 --- a/test/app-tap/module_api.test.lua +++ b/test/app-tap/module_api.test.lua @@ -5,7 +5,7 @@ local fio = require('fio') box.cfg{log = "tarantool.log"} -- Use BUILDDIR passed from test-run or cwd when run w/o -- test-run to find test/app-tap/module_api.{so,dylib}. -build_path = os.getenv("BUILDDIR") or '.' +local build_path = os.getenv("BUILDDIR") or '.' package.cpath = fio.pathjoin(build_path, 'test/app-tap/?.so' ) .. ';' .. fio.pathjoin(build_path, 'test/app-tap/?.dylib') .. ';' .. package.cpath @@ -17,10 +17,10 @@ local function test_pushcdata(test, module) local gc_counter = 0; local ct = ffi.typeof('struct module_api_test') ffi.metatype(ct, { - __tostring = function(obj) + __tostring = function() return 'ok' end; - __gc = function(obj) + __gc = function() gc_counter = gc_counter + 1; end }) @@ -33,7 +33,7 @@ local function test_pushcdata(test, module) test:is(ctid, ctid2, 'checkcdata type') test:is(ptr, ptr2, 'checkcdata value') test:is(gc_counter, 0, 'pushcdata gc') - obj = nil + obj = nil -- luacheck: ignore collectgarbage('collect') test:is(gc_counter, 1, 'pushcdata gc') end @@ -116,7 +116,7 @@ local function test_iscallable(test, module) end end -local test = require('tap').test("module_api", function(test) +require('tap').test("module_api", function(test) test:plan(24) local status, module = pcall(require, 'module_api') test:is(status, true, "module") @@ -138,7 +138,7 @@ local test = require('tap').test("module_api", function(test) end end - local status, msg = pcall(module.check_error) + local _, msg = pcall(module.check_error) test:like(msg, 'luaT_error', 'luaT_error') test:test("pushcdata", test_pushcdata, module) ================================================================================ Fixed all warnings in test/app-tap/msgpackffi.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/msgpackffi.test.lua b/test/app-tap/msgpackffi.test.lua index 0ee5f5edc..058b74f3d 100755 --- a/test/app-tap/msgpackffi.test.lua +++ b/test/app-tap/msgpackffi.test.lua @@ -4,7 +4,6 @@ package.path = "lua/?.lua;"..package.path local tap = require('tap') local common = require('serializer_test') -local ffi = require('ffi') local function is_map(s) local b = string.byte(string.sub(s, 1, 1)) @@ -76,7 +75,7 @@ local function test_other(test, s) -- local function check_depth(depth_to_try) local t = nil - for i = 1, depth_to_try do t = {t} end + for _ = 1, depth_to_try do t = {t} end t = s.decode_unchecked(s.encode(t)) local level = 0 while t ~= nil do level = level + 1 t = t[1] end ================================================================================ Fixed all warnings in test/app-tap/pcall.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/pcall.test.lua b/test/app-tap/pcall.test.lua index 30163a41a..3ae16c8aa 100755 --- a/test/app-tap/pcall.test.lua +++ b/test/app-tap/pcall.test.lua @@ -12,7 +12,7 @@ box.cfg{ log="tarantool.log", memtx_memory=107374182, } -function pcalltest() +local function pcalltest() local ERRMSG = "module 'some_invalid_module' not found" local status, msg = pcall(require, 'some_invalid_module') if status == false and msg ~= nil and msg:match(ERRMSG) ~= nil then @@ -27,10 +27,10 @@ local status, msg = xpcall(pcalltest, function(msg) end) print('pcall inside xpcall:', status, msg) -local status, msg = pcall(function() error('some message') end) +status, msg = pcall(function() error('some message') end) print('pcall with Lua error():', status, msg:match('some message')) -local status, msg = pcall(function() +status, msg = pcall(function() box.error(box.error.ILLEGAL_PARAMS, 'some message') end) print('pcall with box.error():', status, msg) ================================================================================ Fixed all warnings in test/app-tap/snapshot.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/snapshot.test.lua b/test/app-tap/snapshot.test.lua index 587f8279b..6cae662c6 100755 --- a/test/app-tap/snapshot.test.lua +++ b/test/app-tap/snapshot.test.lua @@ -3,7 +3,6 @@ local math = require('math') local fiber = require('fiber') local tap = require('tap') -local ffi = require('ffi') local fio = require('fio') box.cfg{ log="tarantool.log", memtx_memory=107374182} @@ -75,18 +74,18 @@ snap_chan:get() test:ok(true, 'gh-695: avoid overwriting tuple data necessary for smfree()') ------------------------------------------------------------------------------- --- gh-1185: Crash in matras_touch in snapshot_daemon.test +-- gh-1185: Crash in matras_touch in snapshot_daemon.test ------------------------------------------------------------------------------- local s1 = box.schema.create_space('test1', { engine = 'memtx'}) -local i1 = s1:create_index('test', { type = 'tree', parts = {1, 'unsigned'} }) +s1:create_index('test', { type = 'tree', parts = {1, 'unsigned'} }) local s2 = box.schema.create_space('test2', { engine = 'memtx'}) -local i2 = s2:create_index('test', { type = 'tree', parts = {1, 'unsigned'} }) +s2:create_index('test', { type = 'tree', parts = {1, 'unsigned'} }) for i = 1,1000 do s1:insert{i, i, i} end -local snap_chan = fiber.channel() +snap_chan = fiber.channel() fiber.create(function () box.snapshot() snap_chan:put(true) end) fiber.sleep(0) @@ -126,11 +125,11 @@ local function gh1094() break end end - local sf, mf = pcall(box.snapshot) - for i, f in pairs(files) do + local sf = pcall(box.snapshot) + for _, f in pairs(files) do f:close() end - local ss, ms = pcall(box.snapshot) + local ss = pcall(box.snapshot) test:ok(not sf and ss, msg) end gh1094() @@ -141,7 +140,7 @@ box.snapshot() box.snapshot() box.snapshot() test:ok(true, 'No crash for second snapshot w/o any changes') -files = fio.glob(box.cfg.memtx_dir .. '/*.snap') +local files = fio.glob(box.cfg.memtx_dir .. '/*.snap') table.sort(files) fio.unlink(files[#files]) box.snapshot() ================================================================================ Fixed several warnings in test/app-tap/string.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/string.test.lua b/test/app-tap/string.test.lua index 02a1a84d7..431e96899 100755 --- a/test/app-tap/string.test.lua +++ b/test/app-tap/string.test.lua @@ -127,9 +127,9 @@ test:test("fromhex", function(test) local _, err = pcall(string.fromhex, "aaa") test:ok(err and err:match("(even amount of chars expected," .. " got odd amount)")) - local _, err = pcall(string.fromhex, "qq") + _, err = pcall(string.fromhex, "qq") test:ok(err and err:match("(hex string expected, got non hex chars)")) - local _, err = pcall(string.fromhex, 795) + _, err = pcall(string.fromhex, 795) test:ok(err and err:match("(string expected, got number)")) end) @@ -216,10 +216,9 @@ test:test("unicode", function(test) test:is(s, lower_res, 'default locale lower') test:is(utf8.upper(''), '', 'empty string upper') test:is(utf8.lower(''), '', 'empty string lower') - local err - s, err = pcall(utf8.upper, true) + local _, err = pcall(utf8.upper, true) test:isnt(err:find('Usage'), nil, 'upper usage is checked') - s, err = pcall(utf8.lower, true) + _, err = pcall(utf8.lower, true) test:isnt(err:find('Usage'), nil, 'lower usage is checked') test:is(utf8.isupper('a'), false, 'isupper("a")') @@ -247,9 +246,9 @@ test:test("unicode", function(test) test:isnil(c, 'middle of symbol offset is error') test:is(err, 4, 'error on 4 byte') test:is(utf8.len(s, 5), 4, 'start 5') - c, err = utf8.len(s, 6) + _, err = utf8.len(s, 6) test:is(err, 6, 'error on 6 byte') - c, err = utf8.len(s, 0) + _, err = utf8.len(s, 0) test:is(err, 'position is out of string', 'range is out of string') test:is(utf8.len(s, #s), 1, 'start from the end') test:is(utf8.len(s, #s + 1), 0, 'position is out of string') @@ -262,14 +261,14 @@ test:test("unicode", function(test) test:is(utf8.len(s, 1, -7), 4, 'end -7') test:is(utf8.len(s, 2, -7), 3, '[2, -7]') test:is(utf8.len(s, 3, -7), 2, '[3, -7]') - c, err = utf8.len(s, 4, -7) + _, err = utf8.len(s, 4, -7) test:is(err, 4, '[4, -7] is error - start from the middle of symbol') test:is(utf8.len(s, 10, -100), 0, 'it is ok to be out of str by end pos') test:is(utf8.len(s, 10, -10), 0, 'it is ok to swap end and start pos') test:is(utf8.len(''), 0, 'empty len') test:is(utf8.len(s, -6, -1), 3, 'pass both negative offsets') test:is(utf8.len(s, 3, 3), 1, "end in the middle on the same symbol as start") - c, err = utf8.len('a\xF4') + _, err = utf8.len('a\xF4') test:is(err, 2, "invalid unicode in the middle of the string") local chars = {} @@ -279,11 +278,11 @@ test:test("unicode", function(test) table.insert(codes, code) end test:is(table.concat(chars), s, "next and char works") - c, err = pcall(utf8.char, 'kek') + _, err = pcall(utf8.char, 'kek') test:isnt(err:find('bad argument'), nil, 'char usage is checked') - c, err = pcall(utf8.next, true) + _, err = pcall(utf8.next, true) test:isnt(err:find('Usage'), nil, 'next usage is checked') - c, err = pcall(utf8.next, '1234', true) + _, err = pcall(utf8.next, '1234', true) test:isnt(err:find('bad argument'), nil, 'next usage is checked') local offset offset, c = utf8.next('') @@ -338,15 +337,15 @@ test:test("unicode", function(test) test:is(utf8.sub(s, -2, 2), '', 'sub [-2:2]') test:is(utf8.sub(s, -1, 8), '8', 'sub [-1:8]') - c, err = pcall(utf8.sub) + _, err = pcall(utf8.sub) test:isnt(err:find('Usage'), nil, 'usage is checked') - c, err = pcall(utf8.sub, true) + _, err = pcall(utf8.sub, true) test:isnt(err:find('Usage'), nil, 'usage is checked') - c, err = pcall(utf8.sub, '123') + _, err = pcall(utf8.sub, '123') test:isnt(err:find('Usage'), nil, 'usage is checked') - c, err = pcall(utf8.sub, '123', true) + _, err = pcall(utf8.sub, '123', true) test:isnt(err:find('bad argument'), nil, 'usage is checked') - c, err = pcall(utf8.sub, '123', 1, true) + _, err = pcall(utf8.sub, '123', 1, true) test:isnt(err:find('bad argument'), nil, 'usage is checked') local s1 = '☢' ================================================================================ Fixed several warnings in test/app-tap/table.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/table.test.lua b/test/app-tap/table.test.lua index 60c095fdf..7279b07ed 100755 --- a/test/app-tap/table.test.lua +++ b/test/app-tap/table.test.lua @@ -145,7 +145,7 @@ end do -- check usage of __copy metamethod local copy_mt = nil; copy_mt = { - __copy = function(self) + __copy = function() local new_self = { a = 1} return setmetatable(new_self, copy_mt) end @@ -164,7 +164,7 @@ end do -- check usage of __copy metamethod + shallow local copy_mt = nil; copy_mt = { - __copy = function(self) + __copy = function() local new_self = { a = 1} return setmetatable(new_self, copy_mt) end @@ -191,7 +191,7 @@ end do -- check usage of not __copy metamethod on second level + shallow local copy_mt = nil; copy_mt = { - __copy = function(self) + __copy = function() local new_self = { a = 1 } return setmetatable(new_self, copy_mt) end ================================================================================ Fixed 53/57 warnings in test/app-tap/tap.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/tap.test.lua b/test/app-tap/tap.test.lua index e2a78f630..0e184782a 100755 --- a/test/app-tap/tap.test.lua +++ b/test/app-tap/tap.test.lua @@ -11,7 +11,7 @@ local tap = require "tap" -- -- Create a root test -- -test = tap.test("root test") +local test = tap.test("root test") -- Disable stack traces for this test because Tarantool test system also -- checks test output. test.trace = false @@ -88,7 +88,7 @@ end) -- -- Subtest without callbacks. -- -sub2 = test:test("subtest 2") +local sub2 = test:test("subtest 2") sub2:plan(1) sub2:ok(true, 'true in subtest') sub2:diag('hello from subtest') ================================================================================ Fixed 23/35 warnings (including one suppressed semantic error!) in test/app-tap/tarantoolctl.test.lua with the diff below (there are more fixed with the Vlad's patch in his reply): ================================================================================ diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 4d7059559..f5638d330 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -4,7 +4,6 @@ local ffi = require('ffi') local fio = require('fio') local tap = require('tap') local uuid = require('uuid') -local yaml = require('yaml') local errno = require('errno') local fiber = require('fiber') local ok, test_run = pcall(require, 'test_run') @@ -33,7 +32,7 @@ local function recursive_rmdir(path) end end if fio.rmdir(path) == false then - print(string.format('!!! failed to rmdir path "%s"', file)) + print(string.format('!!! failed to rmdir path "%s"', path)) print(string.format('!!! [errno %s]: %s', errno(), errno.strerror())) end end @@ -51,7 +50,7 @@ int execvp(const char *file, char *const argv[]); ]] -- background checks -tctlcfg_code = [[default_cfg = { +local tctlcfg_code = [[default_cfg = { pid_file = '.', wal_dir = '.', memtx_dir = '.' , vinyl_dir = '.', log = '.', background = true, } @@ -124,8 +123,7 @@ local function tctl_wait_stop(dir, name) end end -local function tctl_command(dir, cmd, args, name) - local pid = nil +local function tctl_command(dir, cmd, args) if not fio.stat(fio.pathjoin(dir, '.tarantoolctl')) then create_script(dir, '.tarantoolctl', tctlcfg_code) end @@ -224,7 +222,7 @@ do -- bad code local code = [[ box.cfg{ ]] create_script(dir, 'bad_script.lua', code) - local code = [[ box.cfg{memtx_memory = 104857600} ]] + code = [[ box.cfg{memtx_memory = 104857600} ]] create_script(dir, 'good_script.lua', code) local status, err = pcall(function() @@ -258,9 +256,9 @@ do -- bad code local code = [[ error('help'); return 1]] create_script(dir, 'bad_script.lua', code) - local code = [[ return 1]] + code = [[ return 1]] create_script(dir, 'ok_script.lua', code) - local code = [[ box.cfg{memtx_memory = 104857600} box.once('help', function() end)]] + code = [[ box.cfg{memtx_memory = 104857600} box.once('help', function() end)]] create_script(dir, 'good_script.lua', code) local status, err = pcall(function() @@ -330,7 +328,7 @@ do local function test_help(test, dir, cmd, e_stderr) local desc = dir and 'with config' or 'without config' dir = dir or './' - local res, stdout, stderr = run_command(dir, cmd) + local _, _, stderr = run_command(dir, cmd) if e_stderr ~= nil then if not test:ok(stderr:find(e_stderr), ("check stderr of '%s' %s"):format(cmd, desc)) then print(("Expected to find '%s' in '%s'"):format(e_stderr, stderr)) @@ -385,7 +383,7 @@ do local command_base = 'tarantoolctl cat filler/00000000000000000000.xlog' local desc = args and "cat + " .. args or "cat" args = args and " " .. args or "" - local res, stdout, stderr = run_command(dir, command_base .. args) + local res, stdout = run_command(dir, command_base .. args) test:is(res, 0, desc .. " result") test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count") end @@ -394,7 +392,7 @@ do local command_base = 'tarantoolctl cat filler/00000000000000000000.snap' local desc = args and "cat + " .. args or "cat" args = args and " " .. args or "" - local res, stdout, stderr = run_command(dir, command_base .. args) + local res, stdout = run_command(dir, command_base .. args) test:is(res, 0, desc .. " result") test:is(select(2, stdout:gsub(delim, delim)), lc, desc .. " line count") end @@ -413,6 +411,7 @@ do check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=6 --to=3 --format=json --show-system", "\n", 0) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1", "\n", 3) + -- luacheck: ignore (it's more convenient to not breaking the line). check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0) check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 25) @@ -478,10 +477,10 @@ else check_ok(test_i, dir, 'start', 'filler', 0) local lsn_before = test_run:get_lsn("remote", 1) test_i:is(lsn_before, 4, "check lsn before") - local res, stdout, stderr = run_command(dir, command_base) + local res = run_command(dir, command_base) test_i:is(res, 0, "execution result") test_i:is(test_run:get_lsn("remote", 1), 10, "check lsn after") - local res, stdout, stderr = run_command(dir, command_base) + res = run_command(dir, command_base) test_i:is(res, 0, "execution result") test_i:is(test_run:get_lsn("remote", 1), 16, "check lsn after") end) @@ -621,7 +620,7 @@ test:test('filter_xlog', function(test) local tarantoolctl = dofile(TARANTOOLCTL_PATH) -- Like xlog.pairs(). - local function gen(param, lsn) + local function gen(param) local row = param.data[param.idx] if row == nil then return ================================================================================ Fixed 6/8 warnings in test/app-tap/trigger.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/trigger.test.lua b/test/app-tap/trigger.test.lua index a31d45e5f..6cf3fbe53 100755 --- a/test/app-tap/trigger.test.lua +++ b/test/app-tap/trigger.test.lua @@ -45,7 +45,7 @@ test:test("simple trigger test", function(test) -- Check that we've failed to delete trigger - local stat, err = pcall(getmetatable(trigger_list).__call, trigger_list, + local _, err = pcall(getmetatable(trigger_list).__call, trigger_list, nil, trigger_cnt) test:ok(string.find(err, "is not found"), "check error") end) @@ -69,18 +69,18 @@ test:test("errored trigger test", function(test) test:is(cnt, 1, "check simple trigger") -- Append errored trigger trigger_list(trigger_errored) - local status = pcall(function() trigger_list:run() end) + pcall(function() trigger_list:run() end) test:is(cnt, 2, "check simple+error trigger") -- Flush triggers table_clear(trigger_list) test:is(#trigger_list(), 0, "successfull flush") -- Append first trigger trigger_list(trigger_errored) - local status = pcall(function() trigger_list:run() end) + pcall(function() trigger_list:run() end) test:is(cnt, 2, "check error trigger") -- Append errored trigger trigger_list(trigger_cnt) - local status = pcall(function() trigger_list:run() end) + pcall(function() trigger_list:run() end) test:is(cnt, 2, "check error+simple trigger") end) ================================================================================ Fixed all warnings in test/app-tap/yaml.test.lua with the diff below: ================================================================================ diff --git a/test/app-tap/yaml.test.lua b/test/app-tap/yaml.test.lua index 4669b6102..82fcb90c0 100755 --- a/test/app-tap/yaml.test.lua +++ b/test/app-tap/yaml.test.lua @@ -37,8 +37,6 @@ local function test_compact(test, s) "---\n- {'k': 'v'}\n...\n", "flow map") test:is(getmetatable(ss.decode(ss.encode({k = 'v'}))).__serialize, "map", "decoded __serialize is map") - - ss = nil end local function test_output(test, s) @@ -83,11 +81,11 @@ local function test_tagged(test, s) -- Test encoding tags. -- local prefix = 'tag:tarantool.io/push,2018' - local ok, err = pcall(s.encode, 200, {tag_handle = true, tag_prefix = 100}) + local _, err = pcall(s.encode, 200, {tag_handle = true, tag_prefix = 100}) test:isnt(err:find('Usage'), nil, "encode usage") - ok, err = pcall(s.encode, 100, {tag_handle = 'handle'}) + _, err = pcall(s.encode, 100, {tag_handle = 'handle'}) test:isnt(err:find('Usage'), nil, "encode usage, no prefix") - ok, err = pcall(s.encode, 100, {tag_prefix = 'prefix'}) + _, err = pcall(s.encode, 100, {tag_prefix = 'prefix'}) test:isnt(err:find('Usage'), nil, "encode usage, no handle") local ret ret, err = s.encode(300, {tag_handle = '!push', tag_prefix = prefix}) @@ -100,11 +98,12 @@ local function test_tagged(test, s) -- -- Test decoding tags. -- - ok, err = pcall(s.decode) + _, err = pcall(s.decode) test:isnt(err:find('Usage'), nil, "decode usage") - ok, err = pcall(s.decode, false) + _, err = pcall(s.decode, false) test:isnt(err:find('Usage'), nil, "decode usage") - local handle, prefix = s.decode(ret, {tag_only = true}) + local handle + handle, prefix = s.decode(ret, {tag_only = true}) test:is(handle, "!print!", "handle is decoded ok") test:is(prefix, "tag:tarantool.io/push,2018", "prefix is decoded ok") local several_tags = @@ -114,6 +113,7 @@ local function test_tagged(test, s) - 100 ... ]] + local ok ok, err = s.decode(several_tags, {tag_only = true}) test:is(ok, nil, "can not decode multiple tags") test:is(err, "can not decode multiple tags", "same") ================================================================================ OK, here are some stats before and after my changes applied on this patch: | State | Before | After* | |-------|------------|------------| | Codes | 50 (W111) | | | | 10 (W112) | | | | 472 (W113) | 103 (W113) | | | 70 (W143) | 70 (W143) | | | 37 (W211) | 1 (W211) | | | 7 (W212) | | | | 7 (W213) | | | | 1 (W231) | | | | 22 (W311) | | | | 47 (W411) | 1 (W411) | | | 3 (W412) | 1 (W412) | | | 2 (W421) | 2 (W421) | | | 1 (W422) | 1 (W422) | | | 32 (W431) | 32 (W431) | | | 6 (W432) | 6 (W432) | | | 1 (W511) | | | | 1 (W614) | | | | 1 (W631) | | |-------|------------|------------| | Total | 770 / 0 | 217 / 0 | *In addition to the changes I set <box>, <utf>, <jit> as globals. I can agree with the fact that *not all* changes need to be applied, but there are definitely useful and trivial ones above and I see no reasons to omit and suppress the corresponding warnings. Considering the results it looks like we can fix other sources with this approach to reduce the amout of warnings to be suppressed by .luacheckrc. > <snipped> > 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 OK, we already discussed it in brief, but let's point it one more time: diff based tests (and especially the corresponding results) *are not Lua sources* but console input and output. Thereby these chunks *don't need to be checked* via luacheckrc. It might be useful to write a separate checker, but I see no benefits to it (since AFAIR we're going to reduce the amount of diff-based patches, but I might be wrong). <snipped> > -- > 2.23.0 > > > -- > sergeyb@ -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ Sergey Bronnikov @ 2020-04-14 7:57 ` Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-14 7:58 ` [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in Sergey Bronnikov ` (4 subsequent siblings) 7 siblings, 1 reply; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 7:57 UTC (permalink / raw) To: tarantool-patches, avtikhon, alexander.turenko, o.piskunov Closes #4681 Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- src/box/lua/upgrade.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 075cc236e..6b8ece513 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -173,7 +173,7 @@ local function initial_1_7_5() format[5] = {name='field_count', type='unsigned'} format[6] = {name='flags', type='map'} format[7] = {name='format', type='array'} - local def = _space:insert{_space.id, ADMIN, '_space', 'memtx', 0, MAP, format} + _space:insert{_space.id, ADMIN, '_space', 'memtx', 0, MAP, format} -- space name is unique log.info("create index primary on _space") _index:insert{_space.id, 0, 'primary', 'tree', { unique = true }, {{0, 'unsigned'}}} @@ -194,7 +194,7 @@ local function initial_1_7_5() format[4] = {name = 'type', type = 'string'} format[5] = {name = 'opts', type = 'map'} format[6] = {name = 'parts', type = 'array'} - def = _space:insert{_index.id, ADMIN, '_index', 'memtx', 0, MAP, format} + _space:insert{_index.id, ADMIN, '_index', 'memtx', 0, MAP, format} -- index name is unique within a space log.info("create index primary on _index") _index:insert{_index.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}, {1, 'unsigned'}}} @@ -211,7 +211,7 @@ local function initial_1_7_5() format[2] = {name='owner', type='unsigned'} format[3] = {name='name', type='string'} format[4] = {name='setuid', type='unsigned'} - def = _space:insert{_func.id, ADMIN, '_func', 'memtx', 0, MAP, format} + _space:insert{_func.id, ADMIN, '_func', 'memtx', 0, MAP, format} -- function name and id are unique log.info("create index _func:primary") _index:insert{_func.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}}} @@ -231,7 +231,7 @@ local function initial_1_7_5() format[3] = {name='name', type='string'} format[4] = {name='type', type='string'} format[5] = {name='auth', type='map'} - def = _space:insert{_user.id, ADMIN, '_user', 'memtx', 0, MAP, format} + _space:insert{_user.id, ADMIN, '_user', 'memtx', 0, MAP, format} -- user name and id are unique log.info("create index _func:primary") _index:insert{_user.id, 0, 'primary', 'tree', {unique = true}, {{0, 'unsigned'}}} @@ -251,7 +251,7 @@ local function initial_1_7_5() format[3] = {name='object_type', type='string'} format[4] = {name='object_id', type='unsigned'} format[5] = {name='privilege', type='unsigned'} - def = _space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, MAP, format} + _space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, MAP, format} -- user id, object type and object id are unique log.info("create index primary on _priv") _index:insert{_priv.id, 0, 'primary', 'tree', {unique = true}, {{1, 'unsigned'}, {2, 'string'}, {3, 'unsigned'}}} @@ -580,7 +580,7 @@ local function upgrade_to_2_1_0() -- Now, abscent field means NULL, so we can safely set second -- field in format, marking it nullable. log.info("Add nullable value field to space _schema") - local format = {} + format = {} format[1] = {type='string', name='key'} format[2] = {type='any', name='value', is_nullable=true} box.space._schema:format(format) -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ Sergey Bronnikov @ 2020-04-14 23:30 ` Vladislav Shpilevoy 0 siblings, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:30 UTC (permalink / raw) To: Sergey Bronnikov, tarantool-patches, avtikhon, alexander.turenko, o.piskunov Thanks for the patch! Consider more fixes below and on the branch in a separate commit. That allowed to remove some warning mutes from the luacheck config. Also luacheck discovered two bugs, which were muted in luacheck config. I fixed them in 2 separate commits so as they could be backported. So in total there are +1 commit with review fixes and +2 self sufficient commits, which should not be squashed. The 2 new commits I sent as separate letters. ==================== Review fixes: src/box/lua diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 2add9a79d..5fd8b5e4e 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -465,7 +465,7 @@ local text_connection_mt = { -- Make sure it is exactly "\set output" command. if operators[items[1]] == set_param and param_handlers[items[2]] == set_output then - local err, fmt, opts = parse_output(items[3]) + local err, fmt = parse_output(items[3]) if not err then self.fmt = fmt self.eos = output_eos[fmt] @@ -489,7 +489,7 @@ local text_connection_mt = { break end if fmt == "yaml" then - local handle, prefix = yaml.decode(rc, {tag_only = true}) + local handle = yaml.decode(rc, {tag_only = true}) if not handle then -- Can not fail - tags are encoded with no -- user participation and are correct always. @@ -869,7 +869,7 @@ local function listen(uri) host = u.host port = u.service or 3313 end - local s, addr = socket.tcp_server(host, port, { handler = client_handler, + local s = socket.tcp_server(host, port, { handler = client_handler, name = 'console'}) if not s then error(string.format('failed to create server %s:%s: %s', diff --git a/src/box/lua/feedback_daemon.lua b/src/box/lua/feedback_daemon.lua index ad71a3fe2..06bf3f281 100644 --- a/src/box/lua/feedback_daemon.lua +++ b/src/box/lua/feedback_daemon.lua @@ -60,7 +60,7 @@ local function guard_loop(self) self.fiber = fiber.create(feedback_loop, self) log.verbose("%s restarted", PREFIX) end - local st, err = pcall(fiber.sleep, self.interval) + local st = pcall(fiber.sleep, self.interval) if not st then -- fiber was cancelled break diff --git a/src/box/lua/key_def.lua b/src/box/lua/key_def.lua index 586005709..a1b61441e 100644 --- a/src/box/lua/key_def.lua +++ b/src/box/lua/key_def.lua @@ -15,5 +15,5 @@ ffi.metatype(key_def_t, { __index = function(self, key) return methods[key] end, - __tostring = function(key_def) return "<struct key_def &>" end, + __tostring = function() return "<struct key_def &>" end, }) diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua index b671eb7a2..8d5dfa590 100644 --- a/src/box/lua/load_cfg.lua +++ b/src/box/lua/load_cfg.lua @@ -430,7 +430,6 @@ local function prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg, prefix) else local good_types = string.gsub(template_cfg[k], ' ', ''); if (string.find(',' .. good_types .. ',', ',' .. type(v) .. ',') == nil) then - good_types = string.gsub(good_types, ',', ', '); box.error(box.error.CFG, readable_name, "should be one of types ".. template_cfg[k]) end diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 07fa54c38..1e351bb31 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -38,10 +38,6 @@ local IPROTO_STATUS_KEY = 0x00 local IPROTO_ERRNO_MASK = 0x7FFF local IPROTO_SYNC_KEY = 0x01 local IPROTO_SCHEMA_VERSION_KEY = 0x05 -local IPROTO_METADATA_KEY = 0x32 -local IPROTO_SQL_INFO_KEY = 0x42 -local SQL_INFO_ROW_COUNT_KEY = 0 -local IPROTO_FIELD_NAME_KEY = 0 local IPROTO_DATA_KEY = 0x30 local IPROTO_ERROR_KEY = 0x31 local IPROTO_ERROR_STACK = 0x52 @@ -155,7 +151,7 @@ local function next_id(id) return band(id + 1, 0x7FFFFFFF) end -- @retval two non-nils A connected socket and a decoded greeting. -- local function establish_connection(host, port, timeout) - local timeout = timeout or DEFAULT_CONNECT_TIMEOUT + timeout = timeout or DEFAULT_CONNECT_TIMEOUT local begin = fiber.clock() local s = socket.tcp_connect(host, port, timeout) if not s then @@ -425,7 +421,7 @@ local function create_transport(host, port, user, password, callback, state = new_state last_errno = new_errno last_error = new_error - callback('state_changed', new_state, new_errno, new_error) + callback('state_changed', new_state, new_error) state_cond:broadcast() if state == 'error' or state == 'error_reconnect' or state == 'closed' then @@ -647,7 +643,7 @@ local function create_transport(host, port, user, password, callback, local function send_and_recv_iproto(timeout) local data_len = recv_buf.wpos - recv_buf.rpos - local required = 0 + local required if data_len < 5 then required = 5 else @@ -711,7 +707,8 @@ local function create_transport(host, port, user, password, callback, "please use require('console').connect() instead") local setup_delimiter = 'require("console").delimiter("$EOF$")\n' method_encoder.inject(send_buf, nil, setup_delimiter) - local err, response = send_and_recv_console() + local response + err, response = send_and_recv_console() if err then return error_sm(err, response) elseif response ~= '---\n...\n' then @@ -729,7 +726,6 @@ local function create_transport(host, port, user, password, callback, end console_sm = function(rid) - local delim = '\n...\n' local err, response = send_and_recv_console() if err then return error_sm(err, response) @@ -803,8 +799,7 @@ local function create_transport(host, port, user, password, callback, local status = hdr[IPROTO_STATUS_KEY] local response_schema_version = hdr[IPROTO_SCHEMA_VERSION_KEY] if status ~= 0 then - local body - body, body_end = decode(body_rpos) + local body = decode(body_rpos) return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_KEY]) end if schema_version == nil then @@ -813,8 +808,7 @@ local function create_transport(host, port, user, password, callback, -- schema changed while fetching schema; restart loader return iproto_schema_sm() end - local body - body, body_end = decode(body_rpos) + local body = decode(body_rpos) response[id] = body[IPROTO_DATA_KEY] end until response[select1_id] and response[select2_id] and @@ -830,14 +824,11 @@ local function create_transport(host, port, user, password, callback, local err, hdr, body_rpos, body_end = send_and_recv_iproto() if err then return error_sm(err, hdr) end dispatch_response_iproto(hdr, body_rpos, body_end) - local status = hdr[IPROTO_STATUS_KEY] local response_schema_version = hdr[IPROTO_SCHEMA_VERSION_KEY] if response_schema_version > 0 and response_schema_version ~= schema_version then -- schema_version has been changed - start to load a new version. -- Sic: self.schema_version will be updated only after reload. - local body - body, body_end = decode(body_rpos) set_state('fetch_schema') return iproto_schema_sm(schema_version) end @@ -954,7 +945,7 @@ local function new_sm(host, port, opts, connection, greeting) local remote = {host = host, port = port, opts = opts, state = 'initial'} local function callback(what, ...) if what == 'state_changed' then - local state, errno, err = ... + local state, err = ... local was_connected = remote._is_connected if state == 'active' then if not was_connected then @@ -1601,7 +1592,6 @@ this_module.self = { rollback() return box.error() -- re-throw end - local result if obj ~= nil then return handle_eval_result(pcall(proc, obj, unpack(args))) else diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 85fcca562..545abe714 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -2,7 +2,6 @@ -- local ffi = require('ffi') local msgpack = require('msgpack') -local msgpackffi = require('msgpackffi') local fun = require('fun') local log = require('log') local fio = require('fio') @@ -274,7 +273,6 @@ local function check_param_table(table, template) local haystack = ',' .. good_types .. ',' local needle = ',' .. param_type(v) .. ',' if (string.find(haystack, needle) == nil) then - good_types = string.gsub(good_types, ',', ', ') box.error(box.error.ILLEGAL_PARAMS, "options parameter '" .. k .. "' should be one of types: " .. template[k]) @@ -582,9 +580,9 @@ end -- local function format_field_resolve(format, path, what) assert(type(path) == 'number' or type(path) == 'string') - local idx = nil + local idx local relative_path = nil - local field_name = nil + local field_name -- Path doesn't require resolve. if type(path) == 'number' then idx = path @@ -844,7 +842,7 @@ local function space_sequence_alter_prepare(format, parts, options, if id == nil then box.error(box.error.NO_SUCH_SEQUENCE, new_sequence.id) end - local tuple = _space_sequence.index.sequence:select(id)[1] + tuple = _space_sequence.index.sequence:select(id)[1] if tuple ~= nil and tuple.is_generated then box.error(box.error.ALTER_SPACE, space_name, "can not attach generated sequence") @@ -1281,7 +1279,6 @@ end -- global struct port instance to use by select()/get() local port_tuple = ffi.new('struct port_tuple') -local port_tuple_entry_t = ffi.typeof('struct port_tuple_entry') -- Helper function to check space:method() usage local function check_space_arg(space, method) @@ -1499,7 +1496,8 @@ end base_index_mt.get_ffi = function(index, key) check_index_arg(index, 'get') - local key, key_end = tuple_encode(key) + local key_end + key, key_end = tuple_encode(key) if builtin.box_index_get(index.space_id, index.id, key, key_end, ptuple) ~= 0 then return box.error() -- error @@ -1532,7 +1530,8 @@ end base_index_mt.select_ffi = function(index, key, opts) check_index_arg(index, 'select') - local key, key_end = tuple_encode(key) + local key_end + key, key_end = tuple_encode(key) local iterator, offset, limit = check_select_opts(opts, key + 1 >= key_end) local port = ffi.cast('struct port *', port_tuple) @@ -1554,7 +1553,7 @@ end base_index_mt.select_luac = function(index, key, opts) check_index_arg(index, 'select') - local key = keify(key) + key = keify(key) local iterator, offset, limit = check_select_opts(opts, #key == 0) return internal.select(index.space_id, index.id, iterator, offset, limit, key) @@ -2680,7 +2679,7 @@ box.once = function(key, func, ...) box.error(box.error.ILLEGAL_PARAMS, "Usage: box.once(key, func, ...)") end - local key = "once"..key + key = "once"..key if box.space._schema:get{key} ~= nil then return end diff --git a/src/box/lua/tuple.lua b/src/box/lua/tuple.lua index f97aa1579..6d5df1ae7 100644 --- a/src/box/lua/tuple.lua +++ b/src/box/lua/tuple.lua @@ -1,7 +1,6 @@ -- tuple.lua (internal file) local ffi = require('ffi') -local yaml = require('yaml') local msgpackffi = require('msgpackffi') local fun = require('fun') local buffer = require('buffer') @@ -81,7 +80,6 @@ local tuple_encode = function(obj) encode_r(tmpbuf, obj, 1) elseif type(obj) == "table" then encode_array(tmpbuf, #obj) - local i for i = 1, #obj, 1 do encode_r(tmpbuf, obj[i], 1) end @@ -232,7 +230,7 @@ local function tuple_update(tuple, expr) error("Usage: tuple:update({ { op, field, arg}+ })") end local pexpr, pexpr_end = tuple_encode(expr) - local tuple = builtin.box_tuple_update(tuple, pexpr, pexpr_end) + tuple = builtin.box_tuple_update(tuple, pexpr, pexpr_end) if tuple == nil then return box.error() end @@ -245,7 +243,7 @@ local function tuple_upsert(tuple, expr) error("Usage: tuple:upsert({ { op, field, arg}+ })") end local pexpr, pexpr_end = tuple_encode(expr) - local tuple = builtin.box_tuple_upsert(tuple, pexpr, pexpr_end) + tuple = builtin.box_tuple_upsert(tuple, pexpr, pexpr_end) if tuple == nil then return box.error() end diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 6b8ece513..f95b1ae4a 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -52,7 +52,6 @@ end local function truncate(space) local pk = space.index[0] while pk:len() > 0 do - local state, t for state, t in pk:pairs() do local key = {} for _k2, parts in ipairs(pk.parts) do ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov ` (2 preceding siblings ...) 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ Sergey Bronnikov @ 2020-04-14 7:58 ` Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-15 15:35 ` Igor Munkin 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 5/6] Add luacheck config Sergey Bronnikov ` (3 subsequent siblings) 7 siblings, 2 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 7:58 UTC (permalink / raw) To: tarantool-patches, avtikhon, alexander.turenko, o.piskunov Closes #4681 Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- extra/dist/tarantoolctl.in | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index f5a912ccd..d7f098735 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -46,7 +46,6 @@ local instance_dir local default_cfg local positional_arguments local keyword_arguments -local lua_arguments = arg local language -- function for printing usage reference @@ -64,7 +63,7 @@ end local function check_user_level() local uid = os.getenv('UID') - local udir = nil + local udir if uid == 0 or os.getenv("NOTIFY_SOCKET") then return nil end @@ -790,7 +789,7 @@ end local function eval() local console_sock_path = uri.parse(console_sock).service local filename = arg[3] - local code = nil + local code if filename == nil then if stdin_isatty() then log.error("Usage:") @@ -848,7 +847,6 @@ end -- xlog / snap file, so even when it stops on LSN >= @a opts.to on -- a current file a next file will be processed. local function filter_xlog(gen, param, state, opts, cb) - local spaces = opts.spaces local from, to, spaces = opts.from, opts.to, opts.space local show_system, replicas = opts['show-system'], opts.replica @@ -875,7 +873,7 @@ local function cat() local cat_format = opts.format local format_cb = cat_formats[cat_format] local is_printed = false - for id, file in ipairs(positional_arguments) do + for _, file in ipairs(positional_arguments) do log.error("Processing file '%s'", file) local gen, param, state = xlog.pairs(file) filter_xlog(gen, param, state, opts, function(record) @@ -901,7 +899,7 @@ local function play() if not remote:wait_connected() then error(("Error while connecting to host '%s'"):format(uri)) end - for id, file in ipairs(positional_arguments) do + for _, file in ipairs(positional_arguments) do log.info(("Processing file '%s'"):format(file)) local gen, param, state = xlog.pairs(file) filter_xlog(gen, param, state, opts, function(record) @@ -923,7 +921,7 @@ local function play() end local function find_arg(name_arg) - for i, key in ipairs(arg) do + for _, key in ipairs(arg) do if key:find(name_arg) ~= nil then return key end @@ -937,7 +935,7 @@ local function rocks() local util = require("luarocks.util") local command_line = require("luarocks.cmd") local options = keyword_arguments - local key = nil + local key if options["only-server"] ~= nil then key = find_arg("only%-server") else @@ -954,7 +952,7 @@ local function rocks() end -- Tweak help messages - util.see_help = function(command, program) + util.see_help = function() -- TODO: print extended help message here return "See Tarantool documentation for help." end @@ -1321,7 +1319,7 @@ local function usage_command(name, cmd) if type(header) == 'string' then header = { header } end - for no, line in ipairs(header) do + for _, line in ipairs(header) do log.error(" " .. line, name) end end -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in 2020-04-14 7:58 ` [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in Sergey Bronnikov @ 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-15 15:35 ` Igor Munkin 1 sibling, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:30 UTC (permalink / raw) To: Sergey Bronnikov, tarantool-patches, avtikhon, alexander.turenko, o.piskunov Thanks for the patch! Consider more fixes below and on the branch in a separate commit. That allowed to remove some warning mutes from the luacheck config. ==================== Review fixes: tarantoolctl.in diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index d7f098735..b8e8d0632 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -132,7 +132,8 @@ local function load_default_file(default_file) log.error("Failed to load defaults file: %s", msg) end debug.setfenv(ufunc, env) - local state, msg = pcall(ufunc) + local state + state, msg = pcall(ufunc) if not state then log.error('Failed to execute defaults file: %s', msg) end ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in 2020-04-14 7:58 ` [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy @ 2020-04-15 15:35 ` Igor Munkin 1 sibling, 0 replies; 28+ messages in thread From: Igor Munkin @ 2020-04-15 15:35 UTC (permalink / raw) To: Sergey Bronnikov; +Cc: o.piskunov, tarantool-patches Sergey, Thanks for the patch! I started with this one, since it's simple and I can point the general issues related to the fix. I see the following approach to fix the errors and warning found by luacheck in *Lua sources*: * If the fix is obvious and simple -- please do it. * If the warning/erro fix leads to code complication or reduce readability (e.g. empty if branch) -- let's add an inline ignore comment, since it unlikely to be fixed and just burdens .luacheckrc. * If none of the above -- add the corresponding rule to .luacheckrc. I left inline comments for your patch and added the fix I made for tarantoolctl at the end. Please consider them. On 14.04.20, Sergey Bronnikov wrote: > Closes #4681 > > Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> > --- > > extra/dist/tarantoolctl.in | 18 ++++++++---------- > 1 file changed, 8 insertions(+), 10 deletions(-) > > diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in > index f5a912ccd..d7f098735 100755 > --- a/extra/dist/tarantoolctl.in > +++ b/extra/dist/tarantoolctl.in <snipped> > @@ -64,7 +63,7 @@ end > > local function check_user_level() > local uid = os.getenv('UID') > - local udir = nil > + local udir Minor: I looked at the code nearby and it looks like this initialization can be moved below, since udir is unused prior it (consider the changes below). > if uid == 0 or os.getenv("NOTIFY_SOCKET") then > return nil > end <snipped> > -- > 2.23.0 > > > -- > sergeyb@ I tried to fix the issues by myself and dumped my step-by-step activity below. At first let's see what luacheck reports for tarantoolctl source: | $ luacheck --codes extra/dist/tarantoolctl.in | tail -1 | Total: 35 warnings / 0 errors in 1 file | $ luacheck --codes extra/dist/tarantoolctl.in | \ | grep -vP '^(Total:|Checking|$)' | cut -f 6 -d ' ' | sort | uniq -c | 1 (W112) | 5 (W113) | 1 (W122) | 2 (W211) | 3 (W212) | 4 (W213) | 3 (W311) | 2 (W411) | 13 (W431) | 1 (W542) According to the list of warnings[1] W113 is reported when accessing an undefined global variable is detected. At the same time W112 is reported when mutating an undefined global variable is detected. Considering output these are well known Tarantool globals: box and _TARANTOOL. Let's suppress them (now with CLI option and globally in .luacheckrc further): | $ luacheck --codes extra/dist/tarantoolctl.in --globals box --globals _TARANTOOL | \ | grep -vP '^(Total:|Checking|$)' | cut -f 6 -d ' ' | sort | uniq -c | 1 (W122) | 2 (W211) | 3 (W212) | 4 (W213) | 3 (W311) | 2 (W411) | 13 (W431) | 1 (W542) Well, 6 false-positive warnings are suppressed, 29 others left. Let's see the remaining ones: | $ luacheck --codes extra/dist/tarantoolctl.in --globals box --globals _TARANTOOL | Checking extra/dist/tarantoolctl.in 29 warnings | | extra/dist/tarantoolctl.in:49:7: (W211) unused variable 'lua_arguments' | extra/dist/tarantoolctl.in:67:11: (W311) value assigned to variable 'udir' is unused | extra/dist/tarantoolctl.in:127:34: (W431) shadowing upvalue 'default_file' on line 38 | extra/dist/tarantoolctl.in:136:22: (W411) variable 'msg' was previously defined on line 130 | extra/dist/tarantoolctl.in:217:5: (W122) setting read-only field '?' of global 'arg' | extra/dist/tarantoolctl.in:423:24: (W212) unused argument 'self' | extra/dist/tarantoolctl.in:440:15: (W431) shadowing upvalue 'console_sock' on line 42 | extra/dist/tarantoolctl.in:573:11: (W431) shadowing upvalue 'console_sock' on line 42 | extra/dist/tarantoolctl.in:634:11: (W431) shadowing upvalue 'console_sock' on line 42 | extra/dist/tarantoolctl.in:695:31: (W431) shadowing upvalue 'uri' on line 9 | extra/dist/tarantoolctl.in:759:11: (W431) shadowing upvalue 'console_sock' on line 42 | extra/dist/tarantoolctl.in:793:11: (W311) value assigned to variable 'code' is unused | extra/dist/tarantoolctl.in:819:11: (W431) shadowing upvalue 'status' on line 750 | extra/dist/tarantoolctl.in:851:11: (W211) unused variable 'spaces' | extra/dist/tarantoolctl.in:852:21: (W411) variable 'spaces' was previously defined on line 851 | extra/dist/tarantoolctl.in:865:59: (W542) empty if branch | extra/dist/tarantoolctl.in:878:9: (W213) unused loop variable 'id' | extra/dist/tarantoolctl.in:895:11: (W431) shadowing upvalue 'uri' on line 9 | extra/dist/tarantoolctl.in:904:9: (W213) unused loop variable 'id' | extra/dist/tarantoolctl.in:926:9: (W213) unused loop variable 'i' | extra/dist/tarantoolctl.in:940:11: (W311) value assigned to variable 'key' is unused | extra/dist/tarantoolctl.in:957:30: (W212) unused argument 'command' | extra/dist/tarantoolctl.in:957:39: (W212) unused argument 'program' | extra/dist/tarantoolctl.in:1324:9: (W213) unused loop variable 'no' | extra/dist/tarantoolctl.in:1333:31: (W431) shadowing upvalue 'commands' on line 1019 | extra/dist/tarantoolctl.in:1335:18: (W431) shadowing upvalue 'self_name' on line 30 | extra/dist/tarantoolctl.in:1387:15: (W431) shadowing upvalue 'command_name' on line 32 | extra/dist/tarantoolctl.in:1388:15: (W431) shadowing upvalue 'positional_arguments' on line 47 | extra/dist/tarantoolctl.in:1388:37: (W431) shadowing upvalue 'keyword_arguments' on line 48 | | Total: 29 warnings / 0 errors in 1 file Considering your patch you've already fixed all W211[unused local variable], W212[unused argument] (considering the fix proposed by Oleg) and W213[unused loop variable] warnings. The fixes are obvious and good. Furthermore, you've successfully fixed all W311[value assigned to a local variable is unused] warnings (but I fixed one of them in a slightly different way below). If I didn't miss anything, only the following warnings are left: | $ luacheck --codes extra/dist/tarantoolctl.in --globals box --globals _TARANTOOL | \ | grep -vP '^(Total:|Checking|$)' | cut -f 6 -d ' ' | sort | uniq -c | 1 (W122) | 1 (W411) | 13 (W431) | 1 (W542) * extra/dist/tarantoolctl.in:136:22: (W411) variable 'msg' was previously defined on line 130 Both msg values are well-localized, so I guess we can simply rename both occurences (consider the changes below). * extra/dist/tarantoolctl.in:865:59: (W542) empty if branch This warning is also false-positive, since the way the branches are organized makes code clearer. Thereby this warning looks unlikely to be fixed, so I added an inline suppression. The remaining errors (read-only arg table modification and upvalue shadowing) can be placed to .luacheckrc to be fixed in future, since fixes seem to be non-trivial and some of them introduce changes to function contracts/behaviour. Omitting few lines to be added to .luacheckrc, here are my changes: ================================================================================ diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index f5a912ccd..a80ecc057 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -46,7 +46,6 @@ local instance_dir local default_cfg local positional_arguments local keyword_arguments -local lua_arguments = arg local language -- function for printing usage reference @@ -64,13 +63,12 @@ end local function check_user_level() local uid = os.getenv('UID') - local udir = nil if uid == 0 or os.getenv("NOTIFY_SOCKET") then return nil end -- local dir configuration local pwd = os.getenv('PWD') - udir = pwd and pwd .. '/.tarantoolctl' + local udir = pwd and pwd .. '/.tarantoolctl' or nil udir = udir and fio.stat(udir) and udir or nil -- or home dir configuration local homedir = os.getenv('HOME') @@ -127,15 +125,15 @@ end local function load_default_file(default_file) if default_file then local env = setmetatable({}, { __index = _G }) - local ufunc, msg = loadfile(default_file) + local ufunc, loaderr = loadfile(default_file) -- if load fails - show the last 10 lines of the log file if not ufunc then - log.error("Failed to load defaults file: %s", msg) + log.error("Failed to load defaults file: %s", loaderr) end debug.setfenv(ufunc, env) - local state, msg = pcall(ufunc) + local state, err = pcall(ufunc) if not state then - log.error('Failed to execute defaults file: %s', msg) + log.error('Failed to execute defaults file: %s', err) end default_cfg = env.default_cfg instance_dir = env.instance_dir @@ -420,7 +418,7 @@ local cat_formats = setmetatable({ json = cat_json_cb, lua = cat_lua_cb, }, { - __index = function(self, cmd) + __index = function(_, cmd) error(("Unknown formatter '%s'"):format(cmd)) end }) @@ -790,7 +788,7 @@ end local function eval() local console_sock_path = uri.parse(console_sock).service local filename = arg[3] - local code = nil + local code if filename == nil then if stdin_isatty() then log.error("Usage:") @@ -848,7 +846,6 @@ end -- xlog / snap file, so even when it stops on LSN >= @a opts.to on -- a current file a next file will be processed. local function filter_xlog(gen, param, state, opts, cb) - local spaces = opts.spaces local from, to, spaces = opts.from, opts.to, opts.space local show_system, replicas = opts['show-system'], opts.replica @@ -862,7 +859,7 @@ local function filter_xlog(gen, param, state, opts, cb) elseif (lsn < from) or (lsn >= to) or (not spaces and sid and sid < 512 and not show_system) or (spaces and (sid == nil or not find_in_list(sid, spaces))) or - (replicas and not find_in_list(rid, replicas)) then + (replicas and not find_in_list(rid, replicas)) then -- luacheck: ignore -- pass this tuple else cb(record) @@ -875,7 +872,7 @@ local function cat() local cat_format = opts.format local format_cb = cat_formats[cat_format] local is_printed = false - for id, file in ipairs(positional_arguments) do + for _, file in ipairs(positional_arguments) do log.error("Processing file '%s'", file) local gen, param, state = xlog.pairs(file) filter_xlog(gen, param, state, opts, function(record) @@ -901,7 +898,7 @@ local function play() if not remote:wait_connected() then error(("Error while connecting to host '%s'"):format(uri)) end - for id, file in ipairs(positional_arguments) do + for _, file in ipairs(positional_arguments) do log.info(("Processing file '%s'"):format(file)) local gen, param, state = xlog.pairs(file) filter_xlog(gen, param, state, opts, function(record) @@ -923,7 +920,7 @@ local function play() end local function find_arg(name_arg) - for i, key in ipairs(arg) do + for _, key in ipairs(arg) do if key:find(name_arg) ~= nil then return key end @@ -937,7 +934,7 @@ local function rocks() local util = require("luarocks.util") local command_line = require("luarocks.cmd") local options = keyword_arguments - local key = nil + local key if options["only-server"] ~= nil then key = find_arg("only%-server") else @@ -954,7 +951,7 @@ local function rocks() end -- Tweak help messages - util.see_help = function(command, program) + util.see_help = function() -- TODO: print extended help message here return "See Tarantool documentation for help." end @@ -1321,7 +1318,7 @@ local function usage_command(name, cmd) if type(header) == 'string' then header = { header } end - for no, line in ipairs(header) do + for _, line in ipairs(header) do log.error(" " .. line, name) end end ================================================================================ [1]: https://luacheck.readthedocs.io/en/stable/warnings.html -- Best regards, IM ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 5/6] Add luacheck config 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov ` (3 preceding siblings ...) 2020-04-14 7:58 ` [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in Sergey Bronnikov @ 2020-04-14 8:01 ` Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 6/6] gitlab-ci: enable static analysis with luacheck Sergey Bronnikov ` (2 subsequent siblings) 7 siblings, 1 reply; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 8:01 UTC (permalink / raw) To: tarantool-patches, avtikhon, alexander.turenko, o.piskunov From the beginning we haven't use static analysis for Lua source code and therefore now we have about 32k warnings and errors produced by luacheck. Sure these issues are not real bugs but fixing them will make source code better and clear. Aim to fix all of them at once looks insane and perhaps it is not worth it. Summary of static analysis: There were no errors found by luacheck in production source code (src/), many warnings were fixed in previous commits and non-interested warnings were supressed using luacheck config. Lua source code in test/ directory contains both errors and warnings and there are a lot of them. Some of these warnings were fixed by previous commits and most part of warnings and errors supressed in luacheck config. Regarding errors: all found errors belongs to a single error class - "Syntax error" (E011). All of them have a single root cause - at the of testscases we write conditions without assignments and it is confuses luacheck. Usually such conditions used together with asserts, but in our tests we uses reference outputs instead of asserts. How-to check: $ tarantoolctl rocks install luacheck $ .rocks/bin/luacheck --codes --config .luacheckrc . Closes #4681 Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> --- .luacheckrc | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 000000000..83774d3f7 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,175 @@ +include_files = { + "**/*.lua", + "extra/dist/tarantoolctl.in", +} + +exclude_files = { + "third_party/**/*.lua", + "test/wal_off/*.lua", -- E011 + "test/xlog/*.lua", -- E011 + "test/vinyl/*.lua", -- E011 + "test/sql/*.lua", -- E011 + "test/replication/*.lua", -- E011 + "test/engine/*.lua", -- E011 + "test/swim/*.lua", -- E011 + "test/box/*.lua", -- E011 + "test/app/*.lua", -- E011 + "test/app-tap/lua/serializer_test.lua", -- E011 + "test/var/**/*.lua", + "test-run/lib/tarantool-python/test-run/**/*.lua", + "build/**/*.lua", + ".rocks/**/*.lua", + ".git/**/*.lua", +} + +files["**/*.lua"] = {ignore = {"212", "122"}} +files["extra/dist/tarantoolctl.in"] = {ignore = {"431", "411", "122", "542", "212"}} +files["src/lua/help.lua"] = {globals = {"help", "tutorial"}, ignore = {"113", "211"}} +files["src/lua/swim.lua"] = {ignore = {"431"}} +files["src/lua/fio.lua"] = {ignore = {"231"}} +files["src/lua/init.lua"] = {ignore = {"121"}} +files["src/lua/fiber.lua"] = {ignore = {"331", "311"}} +files["src/box/lua/serpent.lua"] = {globals = {"_ENV"}, ignore = {"431", "421", "631", "432", "542", "412", "422"}} +files["src/box/lua/load_cfg.lua"] = {ignore = {"431", "143", "311", "542"}} +files["src/box/lua/net_box.lua"] = {ignore = {"431", "211", "421", "432", "311", "231", "411", "412"}} +files["src/box/lua/schema.lua"] = {globals = {"update_format", "iid", "role_check_grant_revoke_of_sys_priv"}, ignore = {"431", "211", "421", "213", "432", "311", "542", "412"}} +files["src/box/lua/key_def.lua"] = {ignore = {"431"}} +files["src/box/lua/feedback_daemon.lua"] = {ignore = {"211"}} +files["src/box/lua/tuple.lua"] = {ignore = {"211", "421", "412"}} +files["src/box/lua/upgrade.lua"] = {ignore = {"211", "421", "213"}} +files["src/box/lua/console.lua"] = {globals = {"help"}, ignore = {"211", "143"}} +files["test-run/test_run.lua"] = {ignore = {"412", "211", "431"}} +files["test-run/lib/tarantool-python/test/cluster-py/master.lua"] = {ignore = {"121"}} +files["test-run/lib/tarantool-python/unit/suites/box.lua"] = {ignore = {"121"}} +files["test/**/*.lua"] = {ignore = {"631", "611", "614", "613", "612", "621", "112", "211", "432"}} +files["test/app/*.lua"] = {ignore = {"111", "113"}} +files["test/app/lua/fiber.lua"] = {ignore = {"111"}} +files["test/app-tap/*.lua"] = {ignore = {"111", "113", "411", "431"}} +files["test/app-tap/yaml.test.lua"] = {ignore = {"311"}} +files["test/app-tap/module_api.test.lua"] = {ignore = {"311"}} +files["test/app-tap/debug.test.lua"] = {ignore = {"421"}} +files["test/app-tap/console_lua.test.lua"] = {ignore = {"412"}} +files["test/app-tap/string.test.lua"] = {ignore = {"311"}} +files["test/app-tap/logger.test.lua"] = {ignore = {"231"}} +files["test/app-tap/snapshot.test.lua"] = {ignore = {"213"}} +files["test/app-tap/msgpackffi.test.lua"] = {ignore = {"213"}} +files["test/app-tap/http_client.test.lua"] = {ignore = {"213", "422", "412", "311"}} +files["test/app-tap/fail_main.test.lua"] = {ignore = {"412"}} +files["test/app-tap/tarantoolctl.test.lua"] = {ignore = {"511", "421"}} +files["test/app-tap/lua/require_mod.lua"] = {ignore = {"113", "111"}} +files["test/box/admin.test.lua"] = {ignore = {"213"}} +files["test/box/lua/*.lua"] = {ignore = {"111"}} +files["test/box/*.lua"] = {ignore = {"111", "113"}} +files["test/box/lua/utils.lua"] = {ignore = {"421", "113", "213", "412"}} +files["test/box/lua/bitset.lua"] = {ignore = {"113", "213"}} +files["test/box/lua/fifo.lua"] = {ignore = {"113", "213"}} +files["test/box/lua/identifier.lua"] = {ignore = {"113"}} +files["test/box/lua/require_mod.lua"] = {ignore = {"113"}} +files["test/box/lua/require_init.lua"] = {ignore = {"412", "143"}} +files["test/box/lua/test_init.lua"] = {ignore = {"113", "412", "143"}} +files["test/box/lua/index_random_test.lua"] = {ignore = {"213"}} +files["test/box-tap/*.lua"] = {ignore = {"111"}} +files["test/box-tap/auth.test.lua"] = {ignore = {"311", "411", "113"}} +files["test/box-tap/cfg.test.lua"] = {ignore = {"311", "411", "113"}} +files["test/box-tap/cfgup.test.lua"] = {ignore = {"113"}} +files["test/box-tap/feedback_daemon.test.lua"] = {ignore = {"411"}} +files["test/box-tap/gc.test.lua"] = {ignore = {"421"}} +files["test/box-tap/on_schema_init.test.lua"] = {ignore = {"113"}} +files["test/box-tap/schema_mt.test.lua"] = {ignore = {"113"}} +files["test/box-tap/key_def.test.lua"] = {ignore = {"411", "431"}} +files["test/box-tap/merger.test.lua"] = {ignore = {"411", "431", "412", "213"}} +files["test/box-tap/session.storage.test.lua"] = {ignore = {"113"}} +files["test/box-tap/session.test.lua"] = {ignore = {"411", "113", "412", "143"}} +files["test/box-tap/trigger_atexit.test.lua"] = {ignore = {"113"}} +files["test/box-tap/trigger_yield.test.lua"] = {ignore = {"213", "113"}} +files["test/luajit-tap/fix_string_find_recording.test.lua"] = {ignore = {"111", "113", "231"}} +files["test/luajit-tap/gh-4476-fix-string-find-recording.test.lua"] = {ignore = {"231"}} +files["test/luajit-tap/fold_bug_LuaJIT_505.test.lua"] = {ignore = {"111", "113"}} +files["test/luajit-tap/gh.test.lua"] = {ignore = {"111", "113"}} +files["test/luajit-tap/table_chain_bug_LuaJIT_494.test.lua"] = {ignore = {"111", "113"}} +files["test/luajit-tap/unsink_64_kptr.test.lua"] = {ignore = {"111", "113", "551", "542"}} +files["test/luajit-tap/or-232-unsink-64-kptr.test.lua"] = {ignore = {"542"}} +files["test/luajit-tap/lj-494-table-chain-infinite-loop.test.lua"] = {ignore = {"111", "113", "213"}} +files["test/engine/*.lua"] = {ignore = {"111", "113"}} +files["test/engine_long/suite.lua"] = {ignore = {"421", "111", "213"}} +files["test/engine_long/delete_replace_update.test.lua"] = {ignore = {"113", "111"}} +files["test/engine_long/delete_insert.test.lua"] = {ignore = {"113", "111"}} +files["test/long_run-py/suite.lua"] = {ignore = {"421", "111", "113", "213"}} +files["test/long_run-py/lua/finalizers.lua"] = {ignore = {"241", "511", "111", "113"}} +files["test/replication/*.lua"] = {ignore = {"113", "111"}} +files["test/replication/lua/fast_replica.lua"] = {ignore = {"113", "213"}} +files["test/replication/lua/rlimit.lua"] = {ignore = {"113"}} +files["test/replication-py/replica.lua"] = {ignore = {"111"}} +files["test/replication/lua/fast_replica.lua"] = {ignore = {"113", "111", "213"}} +files["test/replication/lua/rlimit.lua"] = {ignore = {"113", "111"}} +files["test/sql/*.lua"] = {ignore = {"113", "111"}} +files["test/sql/triggers.test.lua"] = {ignore = {"631", "113", "111"}} +files["test/sql/tokenizer.test.lua"] = {ignore = {"113", "111"}} +files["test/sql/transitive-transactions.test.lua"] = {ignore = {"113", "111"}} +files["test/sql/savepoints.test.lua"] = {ignore = {"113", "111"}} +files["test/sql/persistency.test.lua"] = {ignore = {"113", "111"}} +files["test/sql-tap/*.lua"] = {ignore = {"113", "111"}} +files["test/sql-tap/lua_sql.test.lua"] = {ignore = {"412"}} +files["test/sql-tap/subquery.test.lua"] = {ignore = {"412", "143"}} +files["test/sql-tap/alias.test.lua"] = {ignore = {"412", "143"}} +files["test/sql-tap/analyze9.test.lua"] = {ignore = {"213", "411"}} +files["test/sql-tap/between.test.lua"] = {ignore = {"421", "213"}} +files["test/sql-tap/check.test.lua"] = {ignore = {"412", "143"}} +files["test/sql-tap/date.test.lua"] = {ignore = {"511"}} +files["test/sql-tap/e_expr.test.lua"] = {ignore = {"512", "431", "213", "411"}} +files["test/sql-tap/func.test.lua"] = {ignore = {"412", "143"}} +files["test/sql-tap/func5.test.lua"] = {ignore = {"412", "143"}} +files["test/sql-tap/misc1.test.lua"] = {ignore = {"411"}} +files["test/sql-tap/select1.test.lua"] = {ignore = {"511", "213"}} +files["test/sql-tap/select2.test.lua"] = {ignore = {"421"}} +files["test/sql-tap/select4.test.lua"] = {ignore = {"421"}} +files["test/sql-tap/select5.test.lua"] = {ignore = {"421"}} +files["test/sql-tap/selectA.test.lua"] = {ignore = {"542"}} +files["test/sql-tap/selectB.test.lua"] = {ignore = {"213", "542"}} +files["test/sql-tap/selectG.test.lua"] = {ignore = {"421"}} +files["test/sql-tap/table.test.lua"] = {ignore = {"511"}} +files["test/sql-tap/tkt-bd484a090c.test.lua"] = {ignore = {"511"}} +files["test/sql-tap/tkt-38cb5df375.test.lua"] = {ignore = {"421"}} +files["test/sql-tap/tkt-91e2e8ba6f.test.lua"] = {ignore = {"542"}} +files["test/sql-tap/tkt-9a8b09f8e6.test.lua"] = {ignore = {"542"}} +files["test/sql-tap/tkt2192.test.lua"] = {ignore = {"511"}} +files["test/sql-tap/tkt3493.test.lua"] = {ignore = {"542"}} +files["test/sql-tap/triggerA.test.lua"] = {ignore = {"311"}} +files["test/sql-tap/trigger2.test.lua"] = {ignore = {"213"}} +files["test/sql-tap/trigger9.test.lua"] = {ignore = {"143", "412"}} +files["test/sql-tap/update.test.lua"] = {ignore = {"611"}} +files["test/sql-tap/whereB.test.lua"] = {ignore = {"611"}} +files["test/sql-tap/with1.test.lua"] = {ignore = {"542"}} +files["test/sql-tap/with2.test.lua"] = {ignore = {"213", "412"}} +files["test/sql-tap/lua_sql.test.lua"] = {ignore = {"143"}} +files["test/sql-tap/lua/sqltester.lua"] = {ignore = {"111", "113", "431", "213"}} +files["test/sql-tap/gh-2723-concurrency.test.lua"] = {ignore = {"213"}} +files["test/sql-tap/gh-3307-xfer-optimization-issue.test.lua"] = {ignore = {"412", "213"}} +files["test/sql-tap/gh-3083-ephemeral-unref-tuples.test.lua"] = {ignore = {"213"}} +files["test/sql-tap/gh-3332-tuple-format-leak.test.lua"] = {ignore = {"213"}} +files["test/sql-tap/gh2127-indentifier-max-length.test.lua"] = {ignore = {"213"}} +files["test/sql-tap/misc5.test.lua"] = {ignore = {"213"}} +files["test/wal_off/rtree_benchmark.test.lua"] = {ignore = {"213", "113", "111"}} +files["test/wal_off/func_max.test.lua"] = {ignore = {"511", "113", "111"}} +files["test/vinyl/upgrade/fill.lua"] = {ignore = {"111", "113"}} +files["test/vinyl/write_iterator_rand.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/savepoint.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/replica_quota.test.lua"] = {ignore = {"113", "111", "213"}} +files["test/vinyl/stress.test.lua"] = {ignore = {"431", "213"}} +files["test/vinyl/hermitage.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/dump_stress.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/constraint.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/large.test.lua"] = {ignore = {"113", "111"}} +files["test/vinyl/options.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/upgrade/2.1.3/gh-4771-upgrade-sequence/fill.lua"] = {ignore = {"111", "113"}} +files["test/xlog/transaction.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/snap_io_rate.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/reader.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/panic_on_broken_lsn.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/gh1433.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/header.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/errinj.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/force_recovery.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/big_tx.test.lua"] = {ignore = {"113", "111"}} +files["test/xlog/checkpoint_threshold.test.lua"] = {ignore = {"113", "111", "213"}} +files["test/swim/box.lua"] = {ignore = {"113", "111"}} -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [Tarantool-patches] [PATCH 5/6] Add luacheck config 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 5/6] Add luacheck config Sergey Bronnikov @ 2020-04-14 23:30 ` Vladislav Shpilevoy 0 siblings, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:30 UTC (permalink / raw) To: Sergey Bronnikov, tarantool-patches, avtikhon, alexander.turenko, o.piskunov Thanks for the patch! Consider more fixes below and on the branch in a separate commit. ==================== Review fixes: luacheck diff --git a/.luacheckrc b/.luacheckrc index 83774d3f7..0862f7f2a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -22,41 +22,36 @@ exclude_files = { ".git/**/*.lua", } -files["**/*.lua"] = {ignore = {"212", "122"}} -files["extra/dist/tarantoolctl.in"] = {ignore = {"431", "411", "122", "542", "212"}} -files["src/lua/help.lua"] = {globals = {"help", "tutorial"}, ignore = {"113", "211"}} +files["**/*.lua"] = { + globals = {"box", "_TARANTOOL", "help", "tutorial"}, + ignore = {"212", "122"} +} +files["extra/dist/tarantoolctl.in"] = {ignore = {"431", "122", "542", "212"}} files["src/lua/swim.lua"] = {ignore = {"431"}} files["src/lua/fio.lua"] = {ignore = {"231"}} files["src/lua/init.lua"] = {ignore = {"121"}} -files["src/lua/fiber.lua"] = {ignore = {"331", "311"}} +files["src/lua/fiber.lua"] = {ignore = {"331"}} files["src/box/lua/serpent.lua"] = {globals = {"_ENV"}, ignore = {"431", "421", "631", "432", "542", "412", "422"}} -files["src/box/lua/load_cfg.lua"] = {ignore = {"431", "143", "311", "542"}} -files["src/box/lua/net_box.lua"] = {ignore = {"431", "211", "421", "432", "311", "231", "411", "412"}} -files["src/box/lua/schema.lua"] = {globals = {"update_format", "iid", "role_check_grant_revoke_of_sys_priv"}, ignore = {"431", "211", "421", "213", "432", "311", "542", "412"}} -files["src/box/lua/key_def.lua"] = {ignore = {"431"}} -files["src/box/lua/feedback_daemon.lua"] = {ignore = {"211"}} -files["src/box/lua/tuple.lua"] = {ignore = {"211", "421", "412"}} -files["src/box/lua/upgrade.lua"] = {ignore = {"211", "421", "213"}} -files["src/box/lua/console.lua"] = {globals = {"help"}, ignore = {"211", "143"}} +files["src/box/lua/load_cfg.lua"] = {ignore = {"431", "143", "542"}} +files["src/box/lua/net_box.lua"] = {ignore = {"431", "432", "231", "411",}} +files["src/box/lua/schema.lua"] = {ignore = {"431", "213", "432", "542"}} +files["src/box/lua/upgrade.lua"] = {ignore = {"213"}} files["test-run/test_run.lua"] = {ignore = {"412", "211", "431"}} files["test-run/lib/tarantool-python/test/cluster-py/master.lua"] = {ignore = {"121"}} files["test-run/lib/tarantool-python/unit/suites/box.lua"] = {ignore = {"121"}} files["test/**/*.lua"] = {ignore = {"631", "611", "614", "613", "612", "621", "112", "211", "432"}} -files["test/app/*.lua"] = {ignore = {"111", "113"}} files["test/app/lua/fiber.lua"] = {ignore = {"111"}} files["test/app-tap/*.lua"] = {ignore = {"111", "113", "411", "431"}} files["test/app-tap/yaml.test.lua"] = {ignore = {"311"}} files["test/app-tap/module_api.test.lua"] = {ignore = {"311"}} files["test/app-tap/debug.test.lua"] = {ignore = {"421"}} -files["test/app-tap/console_lua.test.lua"] = {ignore = {"412"}} files["test/app-tap/string.test.lua"] = {ignore = {"311"}} files["test/app-tap/logger.test.lua"] = {ignore = {"231"}} files["test/app-tap/snapshot.test.lua"] = {ignore = {"213"}} files["test/app-tap/msgpackffi.test.lua"] = {ignore = {"213"}} files["test/app-tap/http_client.test.lua"] = {ignore = {"213", "422", "412", "311"}} -files["test/app-tap/fail_main.test.lua"] = {ignore = {"412"}} -files["test/app-tap/tarantoolctl.test.lua"] = {ignore = {"511", "421"}} -files["test/app-tap/lua/require_mod.lua"] = {ignore = {"113", "111"}} +files["test/app-tap/tarantoolctl.test.lua"] = {ignore = {"421"}} +files["test/app-tap/lua/require_mod.lua"] = {globals = {"exports"}} files["test/box/admin.test.lua"] = {ignore = {"213"}} files["test/box/lua/*.lua"] = {ignore = {"111"}} files["test/box/*.lua"] = {ignore = {"111", "113"}} ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH 6/6] gitlab-ci: enable static analysis with luacheck 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov ` (4 preceding siblings ...) 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 5/6] Add luacheck config Sergey Bronnikov @ 2020-04-14 8:01 ` Sergey Bronnikov 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index Vladislav Shpilevoy 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 8/6] schema: fix internal symbols dangling in _G Vladislav Shpilevoy 7 siblings, 0 replies; 28+ messages in thread From: Sergey Bronnikov @ 2020-04-14 8:01 UTC (permalink / raw) To: tarantool-patches, avtikhon, o.piskunov, alexander.turenko Closes #4681 --- .gitlab-ci.yml | 9 +++++++++ .travis.mk | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd710027f..adbd892c8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,4 +1,5 @@ stages: + - static_analysis - test - perf - cleanup @@ -96,6 +97,14 @@ variables: script: - ${GITLAB_MAKE} perf_run +# Static Analysis + +luacheck: + <<: *docker_test_definition + stage: static_analysis + script: + - ${GITLAB_MAKE} test_debian_luacheck + # Tests release: diff --git a/.travis.mk b/.travis.mk index f709a18b6..d917a1694 100644 --- a/.travis.mk +++ b/.travis.mk @@ -77,9 +77,13 @@ deps_buster_clang_8: deps_debian # Release build_debian: - cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_WERROR=ON ${CMAKE_EXTRA_PARAMS} + # ENABLE_DIST required to enable tarantoolctl for test_debian_luacheck + cmake . -DENABLE_DIST=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_WERROR=ON ${CMAKE_EXTRA_PARAMS} make -j +build_debian_install: build_debian + sudo make install + test_debian_no_deps: build_debian cd test && /usr/bin/python test-run.py --force $(TEST_RUN_EXTRA_PARAMS) @@ -145,6 +149,15 @@ test_static_build: deps_debian_static test_static_docker_build: docker build --network=host --build-arg RUN_TESTS=ON -f Dockerfile.staticbuild . +# ################### +# Static Analysis +# ################### + +test_debian_luacheck: build_debian_install + tarantoolctl rocks install luacheck + # TODO: run in parallel with LuaLanes + .rocks/bin/luacheck --codes --config .luacheckrc . + ####### # OSX # ####### -- 2.23.0 -- sergeyb@ ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov ` (5 preceding siblings ...) 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 6/6] gitlab-ci: enable static analysis with luacheck Sergey Bronnikov @ 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 8/6] schema: fix internal symbols dangling in _G Vladislav Shpilevoy 7 siblings, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:30 UTC (permalink / raw) To: Sergey Bronnikov, avtikhon, alexander.turenko, o.piskunov, tarantool-patches When index:alter() was called on a non-functional index with specified 'func', it led to accessing a not declared variable in schema.lua. diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 545abe714..ad4a5470b 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -1210,7 +1210,7 @@ box.schema.index.alter = function(space_id, index_id, options) index_opts, parts} if index_opts.func ~= nil then local _func_index = box.space[box.schema.FUNC_INDEX_ID] - _func_index:insert{space_id, iid, index_opts.func} + _func_index:insert{space_id, index_id, index_opts.func} end space_sequence_alter_commit(sequence_proxy) end diff --git a/test/engine/func_index.result b/test/engine/func_index.result index a827c929f..dfa609ce8 100644 --- a/test/engine/func_index.result +++ b/test/engine/func_index.result @@ -847,3 +847,42 @@ s:drop() box.func.extr:drop() | --- | ... + +-- +-- Function is added at alter. +-- +s = box.schema.space.create('withdata', {engine = engine}) + | --- + | ... +lua_code = [[function(tuple) return {tuple[2] >= 0 and tuple[2] or -tuple[2]} end]] + | --- + | ... +box.schema.func.create('second_field_module', {body = lua_code, is_deterministic = true, is_sandboxed = true}) + | --- + | ... +pk = s:create_index('pk') + | --- + | ... +sk = s:create_index('sk', {parts = {{2, 'unsigned'}}}) + | --- + | ... +sk:alter({func = 'second_field_module', parts = {{1, 'unsigned'}}}) + | --- + | ... +s:insert({1, -3}) + | --- + | - [1, -3] + | ... +sk:get{3} + | --- + | - [1, -3] + | ... +s:drop() + | --- + | ... +box.schema.func.drop('second_field_module') + | --- + | ... diff --git a/test/engine/func_index.test.lua b/test/engine/func_index.test.lua index 5db588c1f..98df886f4 100644 --- a/test/engine/func_index.test.lua +++ b/test/engine/func_index.test.lua @@ -294,3 +294,18 @@ idx:get({3}) s:drop() box.func.extr:drop() + +-- +-- Function is added at alter. +-- +s = box.schema.space.create('withdata', {engine = engine}) +lua_code = [[function(tuple) return {tuple[2] >= 0 and tuple[2] or -tuple[2]} end]] +box.schema.func.create('second_field_module', {body = lua_code, is_deterministic = true, is_sandboxed = true}) +pk = s:create_index('pk') +sk = s:create_index('sk', {parts = {{2, 'unsigned'}}}) +sk:alter({func = 'second_field_module', parts = {{1, 'unsigned'}}}) +s:insert({1, -3}) +sk:get{3} +s:drop() +box.schema.func.drop('second_field_module') ^ permalink raw reply [flat|nested] 28+ messages in thread
* [Tarantool-patches] [PATCH v3 8/6] schema: fix internal symbols dangling in _G 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov ` (6 preceding siblings ...) 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index Vladislav Shpilevoy @ 2020-04-14 23:30 ` Vladislav Shpilevoy 7 siblings, 0 replies; 28+ messages in thread From: Vladislav Shpilevoy @ 2020-04-14 23:30 UTC (permalink / raw) To: Sergey Bronnikov, avtikhon, alexander.turenko, o.piskunov, tarantool-patches A couple of functions were mistakenly declared as 'function' instead of 'local function' in schema.lua. That led to their presence in the global namespace. diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index ad4a5470b..80e67a82a 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -350,7 +350,7 @@ end -- box.commit yields, so it's defined as Lua/C binding -- box.rollback and box.rollback_to_savepoint yields as well -function update_format(format) +local function update_format(format) local result = {} for i, given in ipairs(format) do local field = {} @@ -2639,7 +2639,7 @@ box.schema.role.drop = function(name, opts) return drop(uid) end -function role_check_grant_revoke_of_sys_priv(priv) +local function role_check_grant_revoke_of_sys_priv(priv) priv = string.lower(priv) if (type(priv) == 'string' and (priv:match("session") or priv:match("usage"))) or (type(priv) == "number" and (bit.band(priv, 8) ~= 0 or bit.band(priv, 16) ~= 0)) then ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2020-04-17 19:51 UTC | newest] Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-04-14 7:55 [Tarantool-patches] [PATCH v3 0/6] Add static analysis with luacheck Sergey Bronnikov 2020-04-14 7:56 ` [Tarantool-patches] [PATCH 1/6] Fix luacheck warnings in src/lua/ Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:40 ` Vladislav Shpilevoy 2020-04-17 9:07 ` Sergey Bronnikov 2020-04-17 9:09 ` Sergey Bronnikov 2020-04-15 20:51 ` Igor Munkin 2020-04-15 21:46 ` Vladislav Shpilevoy 2020-04-16 13:52 ` Igor Munkin 2020-04-17 9:26 ` Sergey Bronnikov 2020-04-17 12:13 ` Igor Munkin 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 2/6] Fix luacheck warnings in test/ Sergey Bronnikov 2020-04-14 23:29 ` Vladislav Shpilevoy 2020-04-17 12:05 ` Igor Munkin 2020-04-17 19:51 ` Sergey Bronnikov 2020-04-17 19:47 ` Sergey Bronnikov 2020-04-16 13:43 ` Igor Munkin 2020-04-14 7:57 ` [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-14 7:58 ` [Tarantool-patches] [PATCH 4/6] Fix luacheck warnings in extra/dist/tarantoolctl.in Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-15 15:35 ` Igor Munkin 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 5/6] Add luacheck config Sergey Bronnikov 2020-04-14 23:30 ` Vladislav Shpilevoy 2020-04-14 8:01 ` [Tarantool-patches] [PATCH 6/6] gitlab-ci: enable static analysis with luacheck Sergey Bronnikov 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 7/6] schema: fix index promotion to functional index Vladislav Shpilevoy 2020-04-14 23:30 ` [Tarantool-patches] [PATCH v3 8/6] schema: fix internal symbols dangling in _G Vladislav Shpilevoy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox