Skip to content

Commit 507b1b7

Browse files
liguriopatapenka-alexey
authored andcommitted
emmyrc: fix unused
The patch enables rule `unused` and fixes a warnings produced by this rule by adding an underscore to the prefix of variables that are not used.
1 parent a5ad131 commit 507b1b7

3 files changed

Lines changed: 44 additions & 45 deletions

File tree

.emmyrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"disable": [
1515
"need-check-nil",
1616
"redefined-local",
17-
"unresolved-require",
18-
"unused"
17+
"unresolved-require"
1918
],
2019
"globals": [
2120
"box"

test/perftest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ for _, case in pairs(cases) do
134134
local name = ('test_%s_%s'):format(json.encode(case.check), case.argtype):gsub('%.', '_')
135135

136136
g[name] = function(_)
137-
local fn = function(arg) -- luacheck: no unused args
137+
local fn = function(_arg)
138138
checks(case.check)
139139
end
140140

test/test.lua

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,59 +19,59 @@ end
1919
local testdata = {}
2020

2121
local _l_number_optstring = 2 + debug.getinfo(1).currentline
22-
function testdata.fn_number_optstring(arg1, arg2) -- luacheck: no unused args
22+
function testdata.fn_number_optstring(_arg1, _arg2)
2323
checks('number', '?string')
2424
end
2525

2626
local _l_number_or_string = 2 + debug.getinfo(1).currentline
27-
function testdata.fn_number_or_string(arg1) -- luacheck: no unused args
27+
function testdata.fn_number_or_string(_arg1)
2828
checks('number|string')
2929
end
3030

3131
local _l_positive_number = 2 + debug.getinfo(1).currentline
32-
function testdata.fn_positive_number(arg1) -- luacheck: no unused args
32+
function testdata.fn_positive_number(_arg1)
3333
checks('positive_number')
3434
end
3535

36-
function testdata.fn_anytype(arg1) -- luacheck: no unused args
36+
function testdata.fn_anytype(_arg1)
3737
checks('?')
3838
end
3939

4040
local _l_nil_or_number_or_string = 2 + debug.getinfo(1).currentline
41-
function testdata.fn_nil_or_number_or_string(arg1) -- luacheck: no unused args
41+
function testdata.fn_nil_or_number_or_string(_arg1)
4242
checks('nil|number|string')
4343
end
4444

4545
local _l_optnumber_or_optstring = 2 + debug.getinfo(1).currentline
46-
function testdata.fn_optnumber_or_optstring(arg1) -- luacheck: no unused args
46+
function testdata.fn_optnumber_or_optstring(_arg1)
4747
checks('?number|?string')
4848
end
4949

5050
local _l_varargs = 2 + debug.getinfo(1).currentline
51-
function testdata.fn_varargs(arg1, ...) -- luacheck: no unused args
51+
function testdata.fn_varargs(_arg1, ...) -- luacheck: ignore 212
5252
checks('string')
5353
end
5454

5555
local _l_options = 2 + debug.getinfo(1).currentline
56-
function testdata.fn_options(options) -- luacheck: no unused args
56+
function testdata.fn_options(_options)
5757
checks({
5858
mystring = '?string',
5959
mynumber = '?number',
6060
})
6161
end
6262

6363
local _l_array = 2 + debug.getinfo(1).currentline
64-
function testdata.fn_array(array) -- luacheck: no unused args
64+
function testdata.fn_array(_array)
6565
checks({'number', 'number'})
6666
end
6767

6868
local _l_table = 2 + debug.getinfo(1).currentline
69-
function testdata.fn_table(table) -- luacheck: no unused args
69+
function testdata.fn_table(_table)
7070
checks({mykey = 'number'})
7171
end
7272

7373
local _l_inception = 2 + debug.getinfo(1).currentline
74-
function testdata.fn_inception(options) -- luacheck: no unused args
74+
function testdata.fn_inception(_options)
7575
checks({
7676
we = {
7777
need = {
@@ -90,27 +90,27 @@ local function deepchecks()
9090
end
9191

9292
local _l_deepcheck = 2 + debug.getinfo(1).currentline
93-
function testdata.fn_deepcheck(arg1) -- luacheck: no unused args
93+
function testdata.fn_deepcheck(_arg1)
9494
deepchecks()
9595
end
9696

9797
local _l_excess_checks = 2 + debug.getinfo(1).currentline
98-
function testdata.fn_excess_checks(arg1) -- luacheck: no unused args
98+
function testdata.fn_excess_checks(_arg1)
9999
checks('?number', '?string')
100100
end
101101

102102
local _l_missing_checks = 2 + debug.getinfo(1).currentline
103-
function testdata.fn_missing_checks(arg1, arg2) -- luacheck: no unused args
103+
function testdata.fn_missing_checks(_arg1, _arg2)
104104
checks('?number')
105105
end
106106

107107
local _l_bad_check_type_1 = 2 + debug.getinfo(1).currentline
108-
function testdata.bad_check_type_1(arg1, arg2) -- luacheck: no unused args
108+
function testdata.bad_check_type_1(_arg1, _arg2)
109109
checks("?string", 5)
110110
end
111111

112112
local _l_bad_check_type_2 = 2 + debug.getinfo(1).currentline
113-
function testdata.bad_check_type_2(arg1, arg2) -- luacheck: no unused args
113+
function testdata.bad_check_type_2(_arg1, _arg2)
114114
checks({param = 5})
115115
end
116116

@@ -294,12 +294,12 @@ local err_cases = {
294294
{
295295
code = 'fn_options({mynumber = "bad"})',
296296
line = _l_options,
297-
error = 'bad argument options.mynumber to fn_options (?number expected, got string)',
297+
error = 'bad argument _options.mynumber to fn_options (?number expected, got string)',
298298
},
299299
{
300300
code = 'fn_options({badfield = "bad"})',
301301
line = _l_options,
302-
error = 'unexpected argument options.badfield to fn_options',
302+
error = 'unexpected argument _options.badfield to fn_options',
303303
},
304304

305305
-- fn_array
@@ -311,40 +311,40 @@ local err_cases = {
311311
{
312312
code = 'fn_array()',
313313
line = _l_array,
314-
error = 'bad argument array[1] to fn_array (number expected, got nil)',
314+
error = 'bad argument _array[1] to fn_array (number expected, got nil)',
315315
},
316316
{
317317
code = 'fn_array(nil)',
318318
line = _l_array,
319-
error = 'bad argument array[1] to fn_array (number expected, got nil)',
319+
error = 'bad argument _array[1] to fn_array (number expected, got nil)',
320320
},
321321
{
322322
code = 'fn_array(box.NULL)',
323323
line = _l_array,
324-
error = 'bad argument array[1] to fn_array (number expected, got nil)',
324+
error = 'bad argument _array[1] to fn_array (number expected, got nil)',
325325
},
326326
{
327327
code = 'fn_array({})',
328328
line = _l_array,
329-
error = 'bad argument array[1] to fn_array (number expected, got nil)',
329+
error = 'bad argument _array[1] to fn_array (number expected, got nil)',
330330
},
331331
{
332332
code = 'fn_array({"str1"})',
333333
line = _l_array,
334-
error = 'bad argument array[1] to fn_array (number expected, got string)',
334+
error = 'bad argument _array[1] to fn_array (number expected, got string)',
335335
},
336336
{
337337
code = 'fn_array({1})',
338338
line = _l_array,
339-
error = 'bad argument array[2] to fn_array (number expected, got nil)',
339+
error = 'bad argument _array[2] to fn_array (number expected, got nil)',
340340
},
341341
{
342342
code = 'fn_array({1, 2})',
343343
},
344344
{
345345
code = 'fn_array({1, 2, 3})',
346346
line = _l_array,
347-
error = 'unexpected argument array[3] to fn_array',
347+
error = 'unexpected argument _array[3] to fn_array',
348348
},
349349

350350
-- fn_table
@@ -356,25 +356,25 @@ local err_cases = {
356356
{
357357
code = 'fn_table()',
358358
line = _l_table,
359-
error = 'bad argument table.mykey to fn_table (number expected, got nil)',
359+
error = 'bad argument _table.mykey to fn_table (number expected, got nil)',
360360
},
361361
{
362362
code = 'fn_table({})',
363363
line = _l_table,
364-
error = 'bad argument table.mykey to fn_table (number expected, got nil)',
364+
error = 'bad argument _table.mykey to fn_table (number expected, got nil)',
365365
},
366366
{
367367
code = 'fn_table({mykey = "str"})',
368368
line = _l_table,
369-
error = 'bad argument table.mykey to fn_table (number expected, got string)',
369+
error = 'bad argument _table.mykey to fn_table (number expected, got string)',
370370
},
371371
{
372372
code = 'fn_table({mykey = 0})',
373373
},
374374
{
375375
code = 'fn_table({mykey = 0, excess = 1})',
376376
line = _l_table,
377-
error = 'unexpected argument table.excess to fn_table',
377+
error = 'unexpected argument _table.excess to fn_table',
378378
},
379379

380380
-- fn_inception
@@ -387,7 +387,7 @@ local err_cases = {
387387
{
388388
code = 'fn_inception({we = false})',
389389
line = _l_inception,
390-
error = 'bad argument options.we to fn_inception (?table expected, got boolean)',
390+
error = 'bad argument _options.we to fn_inception (?table expected, got boolean)',
391391
},
392392
{
393393
code = 'fn_inception({we = {}})',
@@ -407,7 +407,7 @@ local err_cases = {
407407
{
408408
code = 'fn_inception({we = {need = {to = {go = {deeper = {}}}}}})',
409409
line = _l_inception,
410-
error = 'bad argument options.we.need.to.go.deeper to fn_inception (?number expected, got table)',
410+
error = 'bad argument _options.we.need.to.go.deeper to fn_inception (?number expected, got table)',
411411
},
412412

413413
-- fn_deepcheck
@@ -429,7 +429,7 @@ local err_cases = {
429429
{
430430
code = 'fn_missing_checks()',
431431
line = _l_missing_checks,
432-
error = 'checks: argument "arg2" is not checked',
432+
error = 'checks: argument "_arg2" is not checked',
433433
},
434434
{
435435
code = 'bad_check_type_1()',
@@ -583,34 +583,34 @@ for _, case in pairs(options_v2_cases) do
583583
end
584584

585585
------------------------------------------------------------------------------
586-
function testdata.fn_int64(arg) -- luacheck: no unused args
586+
function testdata.fn_int64(_arg)
587587
checks('int64')
588588
end
589589

590-
function testdata.fn_uint64(arg) -- luacheck: no unused args
590+
function testdata.fn_uint64(_arg)
591591
checks('uint64')
592592
end
593593

594594
local uuid = require('uuid')
595595
testdata.myid = uuid()
596596

597-
function testdata.fn_uuid(arg) -- luacheck: no unused args
597+
function testdata.fn_uuid(_arg)
598598
checks('uuid')
599599
end
600600

601-
function testdata.fn_uuid_str(arg) -- luacheck: no unused args
601+
function testdata.fn_uuid_str(_arg)
602602
checks('uuid_str')
603603
end
604604

605-
function testdata.fn_uuid_bin(arg) -- luacheck: no unused args
605+
function testdata.fn_uuid_bin(_arg)
606606
checks('uuid_bin')
607607
end
608608

609-
function testdata.fn_tuple(arg) -- luacheck: no unused args
609+
function testdata.fn_tuple(_arg)
610610
checks('tuple')
611611
end
612612

613-
function testdata.fn_decimal(arg) -- luacheck: no unused args
613+
function testdata.fn_decimal(_arg)
614614
checks('decimal')
615615
end
616616

@@ -619,13 +619,13 @@ if has_decimal then
619619
testdata.decimal = decimal
620620
end
621621

622-
function testdata.fn_error(arg) -- luacheck: no unused args
622+
function testdata.fn_error(_arg)
623623
checks('error')
624624
end
625625

626626
local has_error = (box.error ~= nil) and (box.error.new ~= nil)
627627

628-
function testdata.fn_datetime(arg) -- luacheck: no unused args
628+
function testdata.fn_datetime(_arg)
629629
checks('datetime')
630630
end
631631

@@ -634,7 +634,7 @@ if has_datetime then
634634
testdata.datetime = datetime
635635
end
636636

637-
function testdata.fn_interval(arg) -- luacheck: no unused args
637+
function testdata.fn_interval(_arg)
638638
checks('interval')
639639
end
640640

0 commit comments

Comments
 (0)