Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions lua/guard-collection/linter/cpplint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local lint = require('guard.lint')

return {
fn = function(_, fname)
local co = assert(coroutine.running())
vim.system({ 'cpplint', '--filter=-legal/copyright', fname }, {}, function(result)
coroutine.resume(co, result.stderr or '')
end)
return coroutine.yield()
end,
parse = function(result, bufnr)
local diags = {}
for line in result:gmatch('[^\n]+') do
local lnum, msg, cat, sev = line:match('^[^:]+:(%d+):%s*(.-)%s+%[([^%]]+)%]%s+%[(%d+)%]$')
if lnum then
local severity = tonumber(sev) >= 3 and vim.diagnostic.severity.ERROR
or vim.diagnostic.severity.WARN
table.insert(
diags,
lint.diag_fmt(
bufnr,
tonumber(lnum) - 1,
0,
('[%s] %s'):format(cat, msg),
severity,
'cpplint'
)
)
end
end
return diags
end,
}
1 change: 1 addition & 0 deletions lua/guard-collection/linter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ return {
checkmake = require('guard-collection.linter.checkmake'),
['clang-tidy'] = require('guard-collection.linter.clang-tidy'),
codespell = require('guard-collection.linter.codespell'),
cpplint = require('guard-collection.linter.cpplint'),
detekt = require('guard-collection.linter.detekt'),
eslint = require('guard-collection.linter.eslint'),
eslint_d = require('guard-collection.linter.eslint_d'),
Expand Down
36 changes: 36 additions & 0 deletions test/linter/cpplint_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe('cpplint', function()
it('can lint', function()
local helper = require('test.linter.helper')
local ns = helper.namespace
local ft = require('guard.filetype')
ft('cpp'):lint('cpplint')

local buf, diagnostics = helper.test_with('cpp', {
[[int main(){int x=1;}]],
})
assert.are.same({
{
bufnr = buf,
col = 0,
end_col = 0,
end_lnum = 0,
lnum = 0,
message = '[whitespace/operators] Missing spaces around =',
namespace = ns,
severity = 1,
source = 'cpplint',
},
{
bufnr = buf,
col = 0,
end_col = 0,
end_lnum = 0,
lnum = 0,
message = '[whitespace/braces] Missing space before {',
namespace = ns,
severity = 1,
source = 'cpplint',
},
}, diagnostics)
end)
end)
Loading