Skip to content

Commit 563bb7a

Browse files
authored
feat(linter): add checkmake makefile linter (#63)
1 parent 411971c commit 563bb7a

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
local lint = require('guard.lint')
2+
3+
return {
4+
fn = function(_, fname)
5+
local co = assert(coroutine.running())
6+
vim.system({
7+
'checkmake',
8+
'--format={{.FileName}}:{{.LineNumber}}: [{{.Rule}}] {{.Violation}}\n',
9+
fname,
10+
}, {}, function(result)
11+
coroutine.resume(co, result.stdout or '')
12+
end)
13+
return coroutine.yield()
14+
end,
15+
parse = function(result, bufnr)
16+
local diags = {}
17+
for line in result:gmatch('[^\n]+') do
18+
local lnum, rule, msg = line:match(':(%d+): %[([^%]]+)%] (.+)$')
19+
if lnum then
20+
table.insert(
21+
diags,
22+
lint.diag_fmt(
23+
bufnr,
24+
tonumber(lnum),
25+
0,
26+
('[%s] %s'):format(rule, msg),
27+
vim.diagnostic.severity.WARN,
28+
'checkmake'
29+
)
30+
)
31+
end
32+
end
33+
return diags
34+
end,
35+
}

lua/guard-collection/linter/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
return {
2+
checkmake = require('guard-collection.linter.checkmake'),
23
['clang-tidy'] = require('guard-collection.linter.clang-tidy'),
34
codespell = require('guard-collection.linter.codespell'),
45
detekt = require('guard-collection.linter.detekt'),

test/linter/checkmake_spec.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
describe('checkmake', function()
2+
it('can lint', function()
3+
local helper = require('test.linter.helper')
4+
local ns = helper.namespace
5+
local ft = require('guard.filetype')
6+
ft('make'):lint('checkmake')
7+
8+
local buf, diagnostics = helper.test_with('make', {
9+
[[all:]],
10+
[[\techo hello]],
11+
})
12+
assert.are.same({
13+
{
14+
bufnr = buf,
15+
col = 0,
16+
end_col = 0,
17+
end_lnum = 0,
18+
lnum = 0,
19+
message = '[minphony] Missing required phony target "all"',
20+
namespace = ns,
21+
severity = 2,
22+
source = 'checkmake',
23+
},
24+
{
25+
bufnr = buf,
26+
col = 0,
27+
end_col = 0,
28+
end_lnum = 0,
29+
lnum = 0,
30+
message = '[minphony] Missing required phony target "clean"',
31+
namespace = ns,
32+
severity = 2,
33+
source = 'checkmake',
34+
},
35+
{
36+
bufnr = buf,
37+
col = 0,
38+
end_col = 0,
39+
end_lnum = 0,
40+
lnum = 0,
41+
message = '[minphony] Missing required phony target "test"',
42+
namespace = ns,
43+
severity = 2,
44+
source = 'checkmake',
45+
},
46+
}, diagnostics)
47+
end)
48+
end)

0 commit comments

Comments
 (0)