[Tarantool-patches] [PATCH 6/6] Fix luacheck warnings in src/box/lua/

sergeyb at tarantool.org sergeyb at tarantool.org
Thu Jun 4 11:39:13 MSK 2020


From: Sergey Bronnikov <sergeyb at tarantool.org>

Part of #4681

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
Co-authored-by: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
---
 .luacheckrc                     | 10 +++++--
 src/box/lua/console.lua         | 10 +++----
 src/box/lua/feedback_daemon.lua |  2 +-
 src/box/lua/key_def.lua         |  2 +-
 src/box/lua/load_cfg.lua        | 11 ++++---
 src/box/lua/net_box.lua         | 52 +++++++++++++--------------------
 src/box/lua/schema.lua          | 44 +++++++++++++---------------
 src/box/lua/tuple.lua           |  8 ++---
 src/box/lua/upgrade.lua         | 19 ++++++------
 9 files changed, 73 insertions(+), 85 deletions(-)

diff --git a/.luacheckrc b/.luacheckrc
index fb8b9dfb3..9fd017629 100644
--- a/.luacheckrc
+++ b/.luacheckrc
@@ -1,11 +1,12 @@
 std = "luajit"
-globals = {"box", "_TARANTOOL"}
+globals = {"box", "_TARANTOOL", "tonumber64"}
 ignore = {
     "143/debug",  -- Accessing an undefined field of a global variable <debug>.
     "143/string", -- Accessing an undefined field of a global variable <string>.
     "143/table",  -- Accessing an undefined field of a global variable <table>.
     "212/self",   -- Unused argument <self>.
     "411",        -- Redefining a local variable.
+    "412",        -- Redefining an argument.
     "421",        -- Shadowing a local variable.
     "431",        -- Shadowing an upvalue.
     "432",        -- Shadowing an upvalue argument.
@@ -19,7 +20,7 @@ include_files = {
 
 exclude_files = {
     "build/**/*.lua",
-    "src/box/**/*.lua",
+    "src/box/lua/serpent.lua", -- third-party source code
     "test-run/**/*.lua",
     "test/**/*.lua",
     "third_party/**/*.lua",
@@ -47,3 +48,8 @@ files["src/lua/swim.lua"] = {
         "212/m", -- respect swim module code style.
     },
 }
+files["src/box/lua/console.lua"] = {
+    ignore = {
+        "212", -- https://github.com/tarantool/tarantool/issues/5032
+    }
+}
diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
index 6ea27a393..5743d2481 100644
--- a/src/box/lua/console.lua
+++ b/src/box/lua/console.lua
@@ -17,7 +17,6 @@ ffi.cdef[[
     console_set_output_format(enum output_format output_format);
 ]]
 
-local serpent = require('serpent')
 local internal = require('console')
 local session_internal = require('box.internal.session')
 local fiber = require('fiber')
@@ -28,6 +27,7 @@ local urilib = require('uri')
 local yaml = require('yaml')
 local net_box = require('net.box')
 local box_internal = require('box.internal')
+local help = require('help').help
 
 local PUSH_TAG_HANDLE = '!push!'
 
@@ -313,7 +313,7 @@ local function set_param(storage, func, param, value)
 end
 
 local function help_wrapper(storage)
-    return format(true, help()) -- defined in help.lua
+    return format(true, help())
 end
 
 local function quit(storage)
@@ -455,7 +455,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]
@@ -479,7 +479,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.
@@ -859,7 +859,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 95130d696..db74f558b 100644
--- a/src/box/lua/feedback_daemon.lua
+++ b/src/box/lua/feedback_daemon.lua
@@ -61,7 +61,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..97905eebf 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(self) return "<struct key_def &>" end,
 })
diff --git a/src/box/lua/load_cfg.lua b/src/box/lua/load_cfg.lua
index 5d818addf..dd77f66bc 100644
--- a/src/box/lua/load_cfg.lua
+++ b/src/box/lua/load_cfg.lua
@@ -272,8 +272,8 @@ local dynamic_cfg = {
     sql_cache_size          = private.cfg_set_sql_cache_size,
 }
 
-ifdef_feedback = nil
-ifdef_feedback_set_params = nil
+ifdef_feedback = nil -- luacheck: ignore
+ifdef_feedback_set_params = nil -- luacheck: ignore
 
 --
 -- For some options it is important in which order they are set.
@@ -431,7 +431,7 @@ local function prepare_cfg(cfg, default_cfg, template_cfg, modify_cfg, prefix)
         elseif v == "" or v == nil then
             -- "" and NULL = ffi.cast('void *', 0) set option to default value
             v = default_cfg[k]
-        elseif template_cfg[k] == 'any' then
+        elseif template_cfg[k] == 'any' then -- luacheck: ignore
             -- any type is ok
         elseif type(template_cfg[k]) == 'table' then
             if type(v) ~= 'table' then
@@ -447,7 +447,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
@@ -544,7 +543,7 @@ for k, v in pairs(box) do
 end
 
 setmetatable(box, {
-    __index = function(table, index)
+    __index = function(table, index) -- luacheck: no unused args
         error(debug.traceback("Please call box.cfg{} first"))
         error("Please call box.cfg{} first")
      end
@@ -568,7 +567,7 @@ local function load_cfg(cfg)
     box_configured = nil
     box.cfg = setmetatable(cfg,
         {
-            __newindex = function(table, index)
+            __newindex = function(table, index) -- luacheck: no unused args
                 error('Attempt to modify a read-only table')
             end,
             __call = locked(reload_cfg),
diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
index 9560bfdd4..f71744014 100644
--- a/src/box/lua/net_box.lua
+++ b/src/box/lua/net_box.lua
@@ -39,10 +39,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_24      = 0x31
 local IPROTO_ERROR         = 0x52
@@ -68,18 +64,18 @@ error_unref(struct error *e);
 -- utility tables
 local is_final_state         = {closed = 1, error = 1}
 
-local function decode_nil(raw_data, raw_data_end)
+local function decode_nil(raw_data, raw_data_end) -- luacheck: no unused args
     return nil, raw_data_end
 end
 local function decode_data(raw_data)
     local response, raw_end = decode(raw_data)
     return response[IPROTO_DATA_KEY], raw_end
 end
-local function decode_tuple(raw_data, raw_data_end, format)
+local function decode_tuple(raw_data, raw_data_end, format) -- luacheck: no unused args
     local response, raw_end = internal.decode_select(raw_data, nil, format)
     return response[1], raw_end
 end
-local function decode_get(raw_data, raw_data_end, format)
+local function decode_get(raw_data, raw_data_end, format) -- luacheck: no unused args
     local body, raw_end = internal.decode_select(raw_data, nil, format)
     if body[2] then
         return nil, raw_end, box.error.MORE_THAN_ONE_TUPLE
@@ -122,7 +118,7 @@ local method_encoder = {
     max     = internal.encode_select,
     count   = internal.encode_call,
     -- inject raw data into connection, used by console and tests
-    inject = function(buf, id, bytes)
+    inject = function(buf, id, bytes) -- luacheck: no unused args
         local ptr = buf:reserve(#bytes)
         ffi.copy(ptr, bytes, #bytes)
         buf.wpos = ptr + #bytes
@@ -187,7 +183,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
@@ -212,7 +208,7 @@ end
 -- Default action on push during a synchronous request -
 -- ignore.
 --
-local function on_push_sync_default(...) end
+local function on_push_sync_default() end
 
 --
 -- Basically, *transport* is a TCP connection speaking one of
@@ -253,7 +249,7 @@ local function on_push_sync_default(...) end
 --
 -- The following events are delivered, with arguments:
 --
---  'state_changed', state, errno, error
+--  'state_changed', state, error
 --  'handshake', greeting -> nil (accept) / errno, error (reject)
 --  'will_fetch_schema'   -> true (approve) / false (skip fetch)
 --  'did_fetch_schema', schema_version, spaces, indices
@@ -449,7 +445,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
@@ -598,7 +594,7 @@ local function create_transport(host, port, user, password, callback,
             -- Handle errors
             requests[id] = nil
             request.id = nil
-            local map_len, key, skip
+            local map_len, key
             map_len, body_rpos = decode_map_header(body_rpos, body_len)
             -- Reserve for 2 keys and 2 array indexes. Because no
             -- any guarantees how Lua will decide to save the
@@ -610,7 +606,7 @@ local function create_transport(host, port, user, password, callback,
                 if rdec then
                     body[key], body_rpos = rdec(body_rpos)
                 else
-                    skip, body_rpos = decode(body_rpos)
+                    _, body_rpos = decode(body_rpos)
                 end
             end
             assert(body_end == body_rpos, "invalid xrow length")
@@ -689,7 +685,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
@@ -771,7 +767,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)
@@ -795,13 +790,12 @@ local function create_transport(host, port, user, password, callback,
             return iproto_schema_sm()
         end
         encode_auth(send_buf, new_request_id(), user, password, salt)
-        local err, hdr, body_rpos, body_end = send_and_recv_iproto()
+        local err, hdr, body_rpos = send_and_recv_iproto()
         if err then
             return error_sm(err, hdr)
         end
         if hdr[IPROTO_STATUS_KEY] ~= 0 then
-            local body
-            body, body_end = decode(body_rpos)
+            local body = decode(body_rpos)
             return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24])
         end
         set_state('fetch_schema')
@@ -852,8 +846,7 @@ local function create_transport(host, port, user, password, callback,
                         peer_has_vcollation = false
                         goto continue
                     end
-                    local body
-                    body, body_end = decode(body_rpos)
+                    local body = decode(body_rpos)
                     return error_sm(E_NO_CONNECTION, body[IPROTO_ERROR_24])
                 end
                 if schema_version == nil then
@@ -862,8 +855,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
             ::continue::
@@ -880,14 +872,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
@@ -926,7 +915,7 @@ end
 -- Now it is necessary to have a strong ref to callback somewhere or
 -- it is GC-ed prematurely. We wrap stop() method, stashing the
 -- ref in an upvalue (stop() performance doesn't matter much.)
-local create_transport = function(host, port, user, password, callback,
+local create_transport = function(host, port, user, password, callback, -- luacheck: ignore
                                   connection, greeting)
     local weak_refs = setmetatable({callback = callback}, {__mode = 'v'})
     local function weak_callback(...)
@@ -1004,7 +993,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
@@ -1275,7 +1264,7 @@ function remote_methods:execute(query, parameters, sql_opts, netbox_opts)
                          sql_opts or {})
 end
 
-function remote_methods:prepare(query, parameters, sql_opts, netbox_opts)
+function remote_methods:prepare(query, parameters, sql_opts, netbox_opts) -- luacheck: no unused args
     check_remote_arg(self, "prepare")
     if type(query) ~= "string" then
         box.error(box.error.SQL_PREPARE, "expected string as SQL statement")
@@ -1640,7 +1629,7 @@ this_module.self = {
     timeout = function(self) return self end,
     wait_connected = function(self) return true end,
     is_connected = function(self) return true end,
-    call = function(_box, proc_name, args, opts)
+    call = function(_box, proc_name, args)
         check_remote_arg(_box, 'call')
         check_call_args(args)
         args = args or {}
@@ -1651,14 +1640,13 @@ 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
             return handle_eval_result(pcall(proc, unpack(args)))
         end
     end,
-    eval = function(_box, expr, args, opts)
+    eval = function(_box, expr, args)
         check_remote_arg(_box, 'eval')
         check_eval_args(args)
         args = args or {}
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index cdfbb65f7..4fe0ff8da 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 buffer = require('buffer')
@@ -212,7 +211,7 @@ local function revoke_object_privs(object_type, object_id)
     local _vpriv = box.space[box.schema.VPRIV_ID]
     local _priv = box.space[box.schema.PRIV_ID]
     local privs = _vpriv.index.object:select{object_type, object_id}
-    for k, tuple in pairs(privs) do
+    for _, tuple in pairs(privs) do
         local uid = tuple.grantee
         _priv:delete{uid, object_type, object_id}
     end
@@ -262,7 +261,7 @@ local function check_param_table(table, template)
         if template[k] == nil then
             box.error(box.error.ILLEGAL_PARAMS,
                       "unexpected option '" .. k .. "'")
-        elseif template[k] == 'any' then
+        elseif template[k] == 'any' then -- luacheck: ignore
             -- any type is ok
         elseif (string.find(template[k], ',') == nil) then
             -- one type
@@ -276,7 +275,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])
@@ -584,9 +582,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
@@ -846,7 +844,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")
@@ -1146,7 +1144,7 @@ box.schema.index.alter = function(space_id, index_id, options)
         local can_update_field = {id = true, name = true, type = true }
         local can_update = true
         local cant_update_fields = ''
-        for k,v in pairs(options) do
+        for k, _ in pairs(options) do
             if not can_update_field[k] then
                 can_update = false
                 cant_update_fields = cant_update_fields .. ' ' .. k
@@ -1190,7 +1188,7 @@ box.schema.index.alter = function(space_id, index_id, options)
     if options.type == nil then
         options.type = tuple.type
     end
-    for k, t in pairs(index_options) do
+    for k, _ in pairs(index_options) do
         if options[k] ~= nil then
             index_opts[k] = options[k]
         end
@@ -1233,12 +1231,12 @@ end
 
 local iterator_t = ffi.typeof('struct iterator')
 ffi.metatype(iterator_t, {
-    __tostring = function(iterator)
+    __tostring = function(self)
         return "<iterator state>"
     end;
 })
 
-local iterator_gen = function(param, state)
+local iterator_gen = function(param, state) -- luacheck: no unused args
     --[[
         index:pairs() mostly conforms to the Lua for-in loop conventions and
         tries to follow the best practices of Lua community.
@@ -1272,7 +1270,7 @@ local iterator_gen = function(param, state)
     end
 end
 
-local iterator_gen_luac = function(param, state)
+local iterator_gen_luac = function(param, state) -- luacheck: no unused args
     local tuple = internal.iterator_next(state)
     if tuple ~= nil then
         return state, tuple -- new state, value
@@ -1555,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)
@@ -1775,9 +1773,9 @@ local function wrap_schema_object_mt(name)
         __pairs = global_mt.__pairs
     }
     local mt_mt = {}
-    mt_mt.__newindex = function(t, k, v)
+    mt_mt.__newindex = function(self, k, v)
         mt_mt.__newindex = nil
-        mt.__index = function(t, k)
+        mt.__index = function(self, k)
             return mt[k] or box.schema[name][k]
         end
         rawset(mt, k, v)
@@ -2486,24 +2484,24 @@ local function revoke(uid, name, privilege, object_type, object_name, options)
     end
 end
 
-local function drop(uid, opts)
+local function drop(uid)
     -- recursive delete of user data
     local _vpriv = box.space[box.schema.VPRIV_ID]
     local spaces = box.space[box.schema.VSPACE_ID].index.owner:select{uid}
-    for k, tuple in pairs(spaces) do
+    for _, tuple in pairs(spaces) do
         box.space[tuple.id]:drop()
     end
     local funcs = box.space[box.schema.VFUNC_ID].index.owner:select{uid}
-    for k, tuple in pairs(funcs) do
+    for _, tuple in pairs(funcs) do
         box.schema.func.drop(tuple.id)
     end
     -- if this is a role, revoke this role from whoever it was granted to
     local grants = _vpriv.index.object:select{'role', uid}
-    for k, tuple in pairs(grants) do
+    for _, tuple in pairs(grants) do
         revoke(tuple.grantee, tuple.grantee, uid)
     end
     local sequences = box.space[box.schema.VSEQUENCE_ID].index.owner:select{uid}
-    for k, tuple in pairs(sequences) do
+    for _, tuple in pairs(sequences) do
         box.schema.sequence.drop(tuple.id)
     end
     -- xxx: hack, we have to revoke session and usage privileges
@@ -2515,7 +2513,7 @@ local function drop(uid, opts)
     end
     local privs = _vpriv.index.primary:select{uid}
 
-    for k, tuple in pairs(privs) do
+    for _, tuple in pairs(privs) do
         -- we need an additional box.session.su() here, because of
         -- unnecessary check for privilege PRIV_REVOKE in priv_def_check()
         box.session.su("admin", revoke, uid, uid, tuple.privilege,
@@ -2565,7 +2563,7 @@ box.schema.user.drop = function(name, opts)
             box.error(box.error.DROP_USER, name,
                       "the user is active in the current session")
         end
-        return drop(uid, opts)
+        return drop(uid)
     end
     if not opts.if_exists then
         box.error(box.error.NO_SUCH_USER, name)
@@ -2681,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..87f53258b 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
@@ -339,7 +337,7 @@ ffi.metatype(tuple_t, {
 
 ffi.metatype(tuple_iterator_t, {
     __call = tuple_iterator_next;
-    __tostring = function(it) return "<tuple iterator>" end;
+    __tostring = function(self) return "<tuple iterator>" end;
 })
 
 -- Free methods, which are not needed anymore.
diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index 075cc236e..208b53f15 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -52,10 +52,9 @@ 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
+        for _, t in pk:pairs() do
             local key = {}
-            for _k2, parts in ipairs(pk.parts) do
+            for _, parts in ipairs(pk.parts) do
                 table.insert(key, t[parts.fieldno])
             end
             space:delete(key)
@@ -173,7 +172,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 +193,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 +210,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 +230,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 +250,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 +579,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)
@@ -734,7 +733,7 @@ local function upgrade_collation_to_2_1_3()
 
     local id = 4
     for _, collation in ipairs(coll_lst) do
-        for i, strength in ipairs(coll_strengths) do
+        for _, strength in ipairs(coll_strengths) do
             local coll_name = 'unicode_' .. collation.name .. "_" .. strength.s
             log.info("creating collation %s", coll_name)
             box.space._collation:replace{id, coll_name, ADMIN, "ICU", collation.loc_str, strength.opt }
-- 
2.23.0



More information about the Tarantool-patches mailing list