From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id DC3A54696C3 for ; Wed, 15 Apr 2020 02:30:12 +0300 (MSK) References: From: Vladislav Shpilevoy Message-ID: Date: Wed, 15 Apr 2020 01:30:10 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Tarantool-patches] [PATCH 3/6] Fix luacheck warnings in src/box/lua/ List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Sergey Bronnikov , tarantool-patches@dev.tarantool.org, avtikhon@tarantool.org, alexander.turenko@tarantool.org, o.piskunov@tarantool.org 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 "" end, + __tostring = function() return "" 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