Skip to content

Commit 4b6803b

Browse files
feat(linter): add buf protobuf linter (#64)
Co-authored-by: xiaoshihou <xiaoshihou@tutamail.com>
1 parent 563bb7a commit 4b6803b

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
return {
2+
cmd = 'buf',
3+
args = { 'lint', '--error-format=json' },
4+
fname = true,
5+
parse = require('guard.lint').from_json({
6+
lines = true,
7+
attributes = {
8+
lnum = 'start_line',
9+
col = 'start_column',
10+
end_lnum = 'end_line',
11+
end_col = 'end_column',
12+
code = 'type',
13+
message = 'message',
14+
},
15+
source = 'buf',
16+
}),
17+
}

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+
buf = require('guard-collection.linter.buf'),
23
checkmake = require('guard-collection.linter.checkmake'),
34
['clang-tidy'] = require('guard-collection.linter.clang-tidy'),
45
codespell = require('guard-collection.linter.codespell'),

test/linter/buf_spec.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe('buf', 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('proto'):lint('buf')
7+
8+
local buf, diagnostics = helper.test_with('proto', {
9+
[[syntax = "proto3"; message Foo { string bar = 1 }]],
10+
})
11+
assert.are.same({
12+
{
13+
bufnr = buf,
14+
col = 48,
15+
end_col = 48,
16+
end_lnum = 0,
17+
lnum = 0,
18+
message = "syntax error: expecting ';'",
19+
namespace = ns,
20+
severity = 4,
21+
source = 'buf',
22+
},
23+
}, diagnostics)
24+
end)
25+
end)

0 commit comments

Comments
 (0)