Skip to content

Commit 95fb27d

Browse files
authored
init: luacheck (#441)
1 parent 16f80b2 commit 95fb27d

File tree

19 files changed

+112
-147
lines changed

19 files changed

+112
-147
lines changed

.github/workflows/default.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,18 @@ jobs:
4949
version: latest
5050
# CLI arguments
5151
args: --color always --check .
52+
53+
luacheck:
54+
name: Luacheck
55+
runs-on: ubuntu-22.04
56+
steps:
57+
- uses: actions/checkout@v3
58+
59+
- name: Prepare
60+
run: |
61+
sudo apt-get update
62+
sudo apt-get install -y luarocks
63+
sudo luarocks install luacheck
64+
65+
- name: Lint
66+
run: sudo make lint

.luacheckrc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
-- Rerun tests only if their modification time changed.
2+
cache = true
3+
4+
std = luajit
5+
codes = true
6+
7+
self = false
8+
9+
-- Glorious list of warnings: https://luacheck.readthedocs.io/en/stable/warnings.html
10+
ignore = {
11+
"212", -- Unused argument, In the case of callback function, _arg_name is easier to understand than _, so this option is set to off.
12+
"122", -- Indirectly setting a readonly global
13+
}
14+
15+
globals = {
16+
"_",
17+
"_PlenaryLeafTable",
18+
"_PlenaryBustedOldAssert",
19+
"_AssociatedBufs",
20+
}
21+
22+
-- Global objects defined by the C code
23+
read_globals = {
24+
"vim",
25+
}
26+
27+
exclude_files = {
28+
"lua/plenary/profile/lua_profiler.lua",
29+
"lua/plenary/profile/memory_profiler.lua",
30+
"lua/plenary/vararg/rotate.lua",
31+
"lua/plenary/async_lib/*.lua",
32+
}
33+
34+
files = {
35+
["lua/plenary/busted.lua"] = {
36+
globals = {
37+
"describe",
38+
"it",
39+
"pending",
40+
"before_each",
41+
"after_each",
42+
"clear",
43+
"assert",
44+
"print",
45+
},
46+
},
47+
["lua/plenary/async/init.lua"] = {
48+
globals = {
49+
"a",
50+
},
51+
},
52+
["lua/plenary/async/tests.lua"] = {
53+
globals = {
54+
"describe",
55+
"it",
56+
"before_each",
57+
"after_each",
58+
},
59+
},
60+
}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
.PHONY: test generate_filetypes lint luarocks_upload test_luarocks_install
12
test:
23
nvim --headless --noplugin -u scripts/minimal.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim'}"
34

45
generate_filetypes:
56
nvim --headless -c 'luafile scripts/update_filetypes_from_github.lua' -c 'qa!'
67

8+
lint:
9+
luacheck lua/plenary
10+
711
luarocks_upload:
812
bash ./scripts/luarocks-upload.sh
913

lua/plenary/async/control.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function Condvar:notify_all()
3333
end
3434

3535
for i = 1, len do
36-
-- table.remove will ensure that indexes are correct and make "ipairs" safe, which is not the case for "self.handles[i] = nil"
36+
-- table.remove will ensure that indexes are correct and make "ipairs" safe,
37+
-- which is not the case for "self.handles[i] = nil"
3738
table.remove(self.handles, i)
3839
end
3940
end
@@ -93,8 +94,7 @@ Semaphore.acquire = a.wrap(function(self, callback)
9394

9495
if self.permits > 0 and #self.handles > 0 then
9596
self.permits = self.permits - 1
96-
local callback = table.remove(self.handles)
97-
callback(self_permit)
97+
table.remove(self.handles)(self_permit)
9898
end
9999
end
100100

lua/plenary/async/init.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ local exports = setmetatable(require "plenary.async.async", {
2828

2929
exports.tests.add_globals = function()
3030
a = exports
31-
async = exports.async
32-
await = exports.await
33-
await_all = exports.await_all
3431

3532
-- must prefix with a or stack overflow, plenary.test harness already added it
3633
a.describe = exports.tests.describe
@@ -44,9 +41,6 @@ exports.tests.add_to_env = function()
4441
local env = getfenv(2)
4542

4643
env.a = exports
47-
env.async = exports.async
48-
env.await = exports.await
49-
env.await_all = exports.await_all
5044

5145
-- must prefix with a or stack overflow, plenary.test harness already added it
5246
env.a.describe = exports.tests.describe

lua/plenary/async/structs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local M = {}
22

3-
Deque = {}
3+
local Deque = {}
44
Deque.__index = Deque
55

66
---@class Deque

lua/plenary/async/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ M.block_on = function(async_function, timeout)
2424

2525
local stat, ret
2626

27-
a.run(async_function, function(_stat, ...)
28-
stat = _stat
27+
a.run(async_function, function(stat_, ...)
28+
stat = stat_
2929
ret = { ... }
3030
end)
3131

lua/plenary/benchmark/init.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local B = {}
21
local stat = require "plenary.benchmark.stat"
32

43
local get_stats = function(results)

lua/plenary/bit.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ function M.extract(n, field, width) -- Lua5.2 inspired
213213
width = width or 1
214214
return band(rshift(n, field), 2^width-1)
215215
end
216-
local extract = M.extract
217216

218217
function M.replace(n, v, field, width) -- Lua5.2 inspired
219218
width = width or 1
@@ -222,7 +221,6 @@ function M.replace(n, v, field, width) -- Lua5.2 inspired
222221
local mask = bnot(lshift(mask1, field))
223222
return band(n, mask) + lshift(v, field)
224223
end
225-
local replace = M.replace
226224

227225
function M.bswap(x) -- BitOp style
228226
local a = band(x, 0xff); x = rshift(x, 8)

lua/plenary/busted.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mod.it = function(desc, func)
183183
-- TODO: We should figure out how to determine whether
184184
-- and assert failed or whether it was an error...
185185

186-
local to_insert, printed
186+
local to_insert
187187
if not ok then
188188
to_insert = results.fail
189189
test_result.msg = msg

0 commit comments

Comments
 (0)