Skip to content

Commit

Permalink
luacheck: change global vars to local in sql-tap
Browse files Browse the repository at this point in the history
Fixed luacheck warning 111 (setting non-standard global variable)
in test/sql-tap directory.
Enabled this directory for checking W111.

Changed almost all variables in test/sql-tap from globals
to locals. In any cases, where variables need to be global,
added inline comments for luacheck.

In .luacheckrc added all lua files, which where checked before
this commit, to `include_files` option and cleaned almost totally
option `exclude_files`.

It was bad idea to add deep directories to `exclude_files`, because
after that there is no way to enable files or child dirs of this
directories for processing by luacheck. In this case, it was impossible
to enable `test/sql-tap/` directory because whole `test/` was in
`exclude_files` and consequently ignored.

Fixes #5173
Part-of #5464
  • Loading branch information
artemreyt committed Nov 12, 2020
1 parent 94dc5bd commit d44244b
Show file tree
Hide file tree
Showing 259 changed files with 585 additions and 523 deletions.
50 changes: 42 additions & 8 deletions .luacheckrc
Expand Up @@ -22,19 +22,53 @@ ignore = {
}

include_files = {
"**/*.lua",
"extra/**/*.lua",
"extra/dist/tarantoolctl.in",
"src/**/*.lua",
"static-build/**/*.lua",
"test/sql-tap/**/*.lua"
}

exclude_files = {
"build/**/*.lua",
-- Third-party source code.
"src/box/lua/serpent.lua",
"test-run/**/*.lua",
"test/**/*.lua",
"third_party/**/*.lua",
".rocks/**/*.lua",
".git/**/*.lua",
}

--
-- gh-5464: Fix luacheck warnings in test/sql-tap
--
files["test/sql-tap/**/*.lua"] = {
ignore = {
-- Accessing an undefined global variable.
"113",
-- Unused local variable.
"211",
-- Unused argument.
"212",
-- Unused loop variable.
"213",
-- Local variable is set but never accessed.
"231",
-- "Value assigned to a local variable is unused."
"311",
-- Unreachable code.
"511",
-- Loop can be executed at most once.
"512",
-- An empty if branch.
"542",
-- A line consists of nothing but whitespace.
"611",
-- A line contains trailing whitespace.
"612",
-- Trailing whitespace in a string.
"613",
-- Trailing whitespace in a comment.
"614",
-- Inconsistent indentation (SPACE followed by TAB).
"621",
-- Line is too long.
"631"
}
}

files["src/lua/help.lua"] = {
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/aggnested.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(7)

--!./tcltestrunner.lua
Expand Down
3 changes: 2 additions & 1 deletion test/sql-tap/alias.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(9)

--!./tcltestrunner.lua
Expand All @@ -24,6 +24,7 @@ test:plan(9)
-- A procedure to return a sequence of increasing integers.
--

-- luacheck: globals counter
counter = 0

-- Function is declared as deterministic deliberately.
Expand Down
14 changes: 7 additions & 7 deletions test/sql-tap/alter.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(50)

test:do_execsql_test(
Expand Down Expand Up @@ -90,11 +90,11 @@ test:do_catchsql_test(
test:do_test(
"alter-2.3.prepare",
function()
format = {}
local format = {}
format[1] = { name = 'id', type = 'integer'}
format[2] = { name = 'f2', type = 'number'}
s = box.schema.create_space('t', {format = format})
i = s:create_index('i', {parts= {1, 'integer'}})
local s = box.schema.create_space('t', {format = format})
local i = s:create_index('i', {parts= {1, 'integer'}})

s:replace{1, 4}
s:replace{2, 2}
Expand Down Expand Up @@ -520,10 +520,10 @@ test:do_catchsql_test(
test:do_test(
"alter-8.1.0",
function()
format = {}
local format = {}
format[1] = { name = 'id', type = 'scalar'}
format[2] = { name = 'f2', type = 'scalar'}
s = box.schema.create_space('T', {format = format})
local s = box.schema.create_space('T', {format = format})
end,
{})

Expand Down Expand Up @@ -560,7 +560,7 @@ test:do_catchsql_test(
test:do_test(
"alter-8.3.2",
function()
i = box.space.T.index[1]
local i = box.space.T.index[1]
return i.id
end, 1)

Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/alter2.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(26)

-- This suite is aimed to test ALTER TABLE ADD CONSTRAINT statement.
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze1.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(38)

--!./tcltestrunner.lua
Expand Down Expand Up @@ -384,7 +384,7 @@ test:do_execsql_test(
-- </analyze-5.0>
})

stat = "_sql_stat4"
local stat = "_sql_stat4"

test:do_execsql_test(
"analyze-5.1",
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze3.test.lua
@@ -1,8 +1,8 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(37)

testprefix = "analyze3"
local testprefix = "analyze3"

--!./tcltestrunner.lua
-- 2009 August 06
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/analyze4.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(4)

--!./tcltestrunner.lua
Expand Down
16 changes: 10 additions & 6 deletions test/sql-tap/analyze5.test.lua
@@ -1,8 +1,8 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(88)

json = require("json")
local json = require("json")

--!./tcltestrunner.lua
-- 2011 January 19
Expand All @@ -21,13 +21,13 @@ json = require("json")
-- with many repeated values and only a few distinct values.
--

testprefix = "analyze5"
local testprefix = "analyze5"
local function eqp(sql)
return test:execsql("EXPLAIN QUERY PLAN"..sql)
end

local function alpha(blob)
ret = ""
local ret = ""
for _, c in ipairs(X(37, "X!cmd", [=[["split",["blob"],""]]=])) do
if X(39, "X!cmd", [=[["string","is","alpha",["c"]]]=])
then
Expand Down Expand Up @@ -64,13 +64,14 @@ test:do_test(
-- test:execsql("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, t INT ,u INT ,v TEXT COLLATE nocase,w INT ,x INT ,y INT ,z INT )")
test:execsql("CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, t TEXT ,u TEXT ,v TEXT ,w TEXT ,x TEXT ,y TEXT ,z NUMBER)")
for i=0,999 do -- _ in X(0, "X!for", [=[["set i 0","$i < 1000","incr i"]]=]) do
local y
if ((i >= 25) and (i <= 50)) then
y = 1
else
y = 0
end

z = 0
local z = 0
if i >= 400 then
z = 1
end
Expand All @@ -81,6 +82,7 @@ test:do_test(
z = z + 1
end

local x, w, t, u
x = z
w = z
t = (z + 0.5)
Expand All @@ -99,7 +101,7 @@ test:do_test(
-- if X(65, "X!cmd", [=[["expr","$i%2"]]=]) then
-- v = u
-- end
v = 'NULL'
local v = 'NULL'
test:execsql("INSERT INTO t1 (t,u,v,w,x,y,z) VALUES('"..t.."','"..u.."','"..v.."','"..w.."','"..x.."','"..y.."','"..z.."')")
end
test:execsql([[
Expand Down Expand Up @@ -252,6 +254,7 @@ for i, v in pairs({
test:do_test(
"analyze5-1."..i.."b",
function()
local w2, a1, a2, res
w2 = v[1]:gsub('y', '+y'):gsub('z', '+z')
a1 = test:execsql("SELECT id FROM t1 NOT INDEXED WHERE "..w2.." ORDER BY +id")
a2 = test:execsql("SELECT id FROM t1 WHERE "..v[1].." ORDER BY +id")
Expand Down Expand Up @@ -298,6 +301,7 @@ for i, v in pairs({
test:do_test(
"analyze5-1."..i.."b",
function()
local a1, a2, res
a1 = test:execsql("SELECT id FROM t1 NOT INDEXED WHERE "..v.." ORDER BY +id")
a2 = test:execsql("SELECT id FROM t1 WHERE "..v.." ORDER BY +id")
if (test.is_deeply_regex(a1, a1))
Expand Down
4 changes: 2 additions & 2 deletions test/sql-tap/analyze6.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(13)

--!./tcltestrunner.lua
Expand All @@ -21,7 +21,7 @@ test:plan(13)
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]

testprefix = "analyze6"
local testprefix = "analyze6"

test:do_test(
"analyze6-1.0",
Expand Down
2 changes: 1 addition & 1 deletion test/sql-tap/analyze7.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(14)

--!./tcltestrunner.lua
Expand Down
5 changes: 3 additions & 2 deletions test/sql-tap/analyze8.test.lua
@@ -1,5 +1,5 @@
#!/usr/bin/env tarantool
test = require("sqltester")
local test = require("sqltester")
test:plan(15)

--!./tcltestrunner.lua
Expand All @@ -18,7 +18,7 @@ test:plan(15)
-- in this file is testing the capabilities of sql_stat3.
--

testprefix = "analyze8"
local testprefix = "analyze8"

-- Scenario:
--
Expand All @@ -39,6 +39,7 @@ test:do_test(
CREATE INDEX t1c ON t1(c);
]])
for i=0, 1000 do
local a, b, c
if (i % 2 == 0)
then
a = i
Expand Down

0 comments on commit d44244b

Please sign in to comment.