[Tarantool-patches] [PATCH v6 05/25] Fix luacheck warnings in src/lua/

Alexander Turenko alexander.turenko at tarantool.org
Mon Jun 1 17:47:41 MSK 2020


> -local function parameters_parse(t_in, options)
> -    local t_out, t_in = {}, t_in or {}
> +local function parameters_parse(param, options)
> +    local t_out, t_in = {}, param or {}

Here you introduce the second name for one thing. It does not improve
the code readability...

>  
>      -- 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)

I don't see any reason to make the live interval of those very local
values longer. The code will be harder to verify.

I never see any positive impact from redefinitions detection in
luacheck, but those examples show that it may push us to introduce
different terms for one thing and to reuse one variable for logically
different values. It would be too pathetic to say that it is harmful,
but it certainly not good. (NB: Also said about this in [1].)

[1]: https://lists.tarantool.org/pipermail/tarantool-patches/2020-June/017304.html

> -local function ibuf_tostring(ibuf)
> +local function ibuf_tostring()
>      return '<ibuf>'
>  end

The function contract assumes that it receives one argument. Whether
luacheck happy about this or not, we should not confuse a reader and
write the function like it does not receive any value.

I propose to use '-- luacheck: no unused args' for those cases, see [2].

[2]: https://lists.tarantool.org/pipermail/tarantool-patches/2020-June/017307.html

WBR, Alexander Turenko.


More information about the Tarantool-patches mailing list