Skip to content

Commit 50c36c2

Browse files
committed
feat(linter): add cpplint C++ linter
1 parent 411971c commit 50c36c2

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local lint = require('guard.lint')
2+
3+
return {
4+
cmd = 'cpplint',
5+
fname = true,
6+
stderr = true,
7+
ignore_exit_code = true,
8+
parse = function(result, bufnr)
9+
local diags = {}
10+
for line in result:gmatch('[^\n]+') do
11+
local lnum, msg, cat, sev = line:match('^[^:]+:(%d+):%s*(.-)%s+%[([^%]]+)%]%s+%[(%d+)%]$')
12+
if lnum then
13+
local severity = tonumber(sev) >= 3 and vim.diagnostic.severity.ERROR
14+
or vim.diagnostic.severity.WARN
15+
table.insert(
16+
diags,
17+
lint.diag_fmt(
18+
bufnr,
19+
tonumber(lnum) - 1,
20+
0,
21+
('[%s] %s'):format(cat, msg),
22+
severity,
23+
'cpplint'
24+
)
25+
)
26+
end
27+
end
28+
return diags
29+
end,
30+
}

lua/guard-collection/linter/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
return {
22
['clang-tidy'] = require('guard-collection.linter.clang-tidy'),
33
codespell = require('guard-collection.linter.codespell'),
4+
cpplint = require('guard-collection.linter.cpplint'),
45
detekt = require('guard-collection.linter.detekt'),
56
eslint = require('guard-collection.linter.eslint'),
67
eslint_d = require('guard-collection.linter.eslint_d'),

test/linter/cpplint_spec.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
describe('cpplint', 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('cpp'):lint('cpplint')
7+
8+
local buf, diagnostics = helper.test_with('cpp', {
9+
[[// Copyright 2026 Test]],
10+
[[int main(){int x=1;}]],
11+
})
12+
assert.are.same({
13+
{
14+
bufnr = buf,
15+
col = 0,
16+
end_col = 0,
17+
end_lnum = 1,
18+
lnum = 1,
19+
message = '[whitespace/operators] Missing spaces around =',
20+
namespace = ns,
21+
severity = 1,
22+
source = 'cpplint',
23+
},
24+
{
25+
bufnr = buf,
26+
col = 0,
27+
end_col = 0,
28+
end_lnum = 1,
29+
lnum = 1,
30+
message = '[whitespace/braces] Missing space before {',
31+
namespace = ns,
32+
severity = 1,
33+
source = 'cpplint',
34+
},
35+
}, diagnostics)
36+
end)
37+
end)

0 commit comments

Comments
 (0)