[Tarantool-patches] [PATCH v8 04/14] test: fix luacheck warnings W211 in test/sql-tap

Sergey Bronnikov sergeyb at tarantool.org
Tue Mar 2 11:05:45 MSK 2021


Hi!

On 02.03.2021 00:27, Vladislav Shpilevoy wrote:
>> --- a/test/sql-tap/select9.test.lua
>> +++ b/test/sql-tap/select9.test.lua
>> @@ -274,8 +274,6 @@ test:do_execsql_test(
>>           -- </select9-2.0>
>>       })
>>
>> -local _ = test:execsql([[SELECT * from "_space" where "name"='T1']])["id"]
>> -local _ = 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"]]]=])
>>
>>>        })
>>>    -local _ = test:execsql([[SELECT * from "_space" where "name"='T1']])["id"]
>>> -local _ = 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"]]=])
>>> ====================
>>>
>>> However even if we would would to keep them you wouldn't need `local _ = `.
>>> You can call functions without saving their result into a variable.
>> luacheck reports an error when result of function is not assigned to variable.
>>
>> With patch:
>>
>> --- a/test/sql-tap/select9.test.lua
>> +++ b/test/sql-tap/select9.test.lua
>> @@ -274,8 +274,7 @@ test:do_execsql_test(
>>           -- </select9-2.0>
>>       })
>>
>> -local _ = test:execsql([[SELECT * from "_space" where "name"='T1']])["id"]
>> -local _ = test:execsql([[SELECT * from "_space" where "name"='T2']])["id"]
>> +test:execsql([[SELECT * from "_space" where "name"='T1']])["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"]]]=])
>>
>> it reports:
>>
>> Checking test/sql-tap/select9.test.lua            1 error
>>
>>      test/sql-tap/select9.test.lua:289:1: (E011) expected '=' near 'iOuterLoop'
>>
>> Total: 0 warnings / 1 error in 264 files
>>
>>
>> iOuterLoop is a variable on a next uncommented line. Seems Lua requires that function's result must be assigned to variable.
> That is hardly possible. We have Lua calls not saved into anything.
> For instance, grep fiber.name(...) calls.
>
> I suspect it is because you left ["id"] thing after the call. Because
> result of [] indeed makes no sense without being used.

Looks so.

$ cat sample.lua
function aaa()
     return {}
end

aaa()
aaa()['id']

local b = 'dd'

$ luacheck --codes sample.lua
Checking sample.lua                               1 error

     sample.lua:8:1: (E011) expected '=' near 'local'

Total: 0 warnings / 1 error in 1 file



More information about the Tarantool-patches mailing list