1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
local config = require 'config'
local util = require 'utility'
-- disable all default groups to make isolated tests
config.set(nil, 'Lua.diagnostics.groupFileStatus',
{
['ambiguity'] = 'None',
['await'] = 'None',
['codestyle'] = 'None',
['conventions'] = 'None',
['duplicate'] = 'None',
['global'] = 'None',
['luadoc'] = 'None',
['redefined'] = 'None',
['strict'] = 'None',
['strong'] = 'None',
['type-check'] = 'None',
['unbalanced'] = 'None',
['unused'] = 'None'
})
-- enable single diagnostic that is to be tested
config.set(nil, 'Lua.diagnostics.neededFileStatus',
{
['global-element'] = 'Any!' -- override groupFileStatus
})
-- check that local elements are not warned about
TEST [[
local x = 123
x = 321
<!Y!> = "global"
<!z!> = "global"
]]
TEST [[
local function test1()
print()
end
function <!Test2!>()
print()
end
]]
TEST [[
local function closure1()
local elem1 = 1
<!elem2!> = 2
end
function <!Closure2!>()
local elem1 = 1
<!elem2!> = 2
end
]]
-- add elements to exemption list
config.set(nil, 'Lua.diagnostics.globals',
{
'GLOBAL1',
'GLOBAL2',
'GLOBAL_CLOSURE'
})
TEST [[
GLOBAL1 = "allowed"
<!global2!> = "not allowed"
<!GLOBAL3!> = "not allowed"
]]
TEST [[
function GLOBAL1()
print()
end
]]
TEST [[
local function closure1()
local elem1 = 1
GLOBAL1 = 2
end
function GLOBAL_CLOSURE()
local elem1 = 1
GLOBAL2 = 2
<!elem2!> = 2
end
]]
-- reset configurations
config.set(nil, 'Lua.diagnostics.groupFileStatus',
{})
config.set(nil, 'Lua.diagnostics.neededFileStatus',
{})
config.set(nil, 'Lua.diagnostics.globals',
{})
|