Skip to content

Commit

Permalink
Fix luacheck warnings in src/box/lua/
Browse files Browse the repository at this point in the history
Part of #4681

Reviewed-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Co-authored-by: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
  • Loading branch information
2 people authored and kyukhin committed Jul 15, 2020
1 parent 3af79e7 commit 0ab21ac
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 76 deletions.
9 changes: 8 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ include_files = {

exclude_files = {
"build/**/*.lua",
"src/box/**/*.lua",
-- Third-party source code.
"src/box/lua/serpent.lua",
"test-run/**/*.lua",
"test/**/*.lua",
"third_party/**/*.lua",
Expand All @@ -50,3 +51,9 @@ files["src/lua/init.lua"] = {
-- Miscellaneous global function definition.
globals = {"dostring"},
}
files["src/box/lua/console.lua"] = {
ignore = {
-- https://github.com/tarantool/tarantool/issues/5032
"212",
}
}
10 changes: 5 additions & 5 deletions src/box/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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!'

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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.
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/box/lua/feedback_daemon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,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
Expand Down
2 changes: 1 addition & 1 deletion src/box/lua/key_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
11 changes: 5 additions & 6 deletions src/box/lua/load_cfg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,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.
Expand Down Expand Up @@ -459,7 +459,7 @@ local function prepare_cfg(cfg, default_cfg, template_cfg,
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
Expand Down Expand Up @@ -488,7 +488,6 @@ local function prepare_cfg(cfg, default_cfg, template_cfg,
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
Expand Down Expand Up @@ -596,7 +595,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
Expand Down Expand Up @@ -650,7 +649,7 @@ local function load_cfg(cfg)
setmetatable(box, 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),
Expand Down
48 changes: 18 additions & 30 deletions src/box/lua/net_box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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::
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -1642,7 +1631,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 {}
Expand All @@ -1653,14 +1642,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 {}
Expand Down

0 comments on commit 0ab21ac

Please sign in to comment.