Skip to content

Commit ee1176b

Browse files
authored
feat(linter): add zsh syntax checker (#62)
* feat(linter): add zsh syntax checker * fix(ci): add luarocks bin to PATH * fix: revert ci change
1 parent a55f21b commit ee1176b

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

lua/guard-collection/linter/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ return {
2323
mypy = require('guard-collection.linter.mypy').mypy,
2424
mypyc = require('guard-collection.linter.mypy').mypyc,
2525
dmypy = require('guard-collection.linter.mypy').dmypy,
26+
zsh = require('guard-collection.linter.zsh'),
2627
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local lint = require('guard.lint')
2+
3+
return {
4+
fn = function(_, fname)
5+
local co = assert(coroutine.running())
6+
vim.system({ 'zsh', '-n', fname }, {}, function(result)
7+
coroutine.resume(co, result.stderr or '')
8+
end)
9+
return coroutine.yield()
10+
end,
11+
parse = function(result, bufnr)
12+
local diags = {}
13+
for line in result:gmatch('[^\n]+') do
14+
local lnum, msg = line:match(':(%d+): (.+)$')
15+
if lnum then
16+
table.insert(
17+
diags,
18+
lint.diag_fmt(bufnr, tonumber(lnum) - 1, 0, msg, vim.diagnostic.severity.ERROR, 'zsh')
19+
)
20+
end
21+
end
22+
return diags
23+
end,
24+
}

test/linter/zsh_spec.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe('zsh', 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('zsh'):lint('zsh')
7+
8+
local buf, diagnostics = helper.test_with('zsh', {
9+
'if true; then',
10+
})
11+
assert.are.same({
12+
{
13+
bufnr = buf,
14+
col = 0,
15+
end_col = 0,
16+
end_lnum = 1,
17+
lnum = 1,
18+
message = "parse error near `\\n'",
19+
namespace = ns,
20+
severity = 1,
21+
source = 'zsh',
22+
},
23+
}, diagnostics)
24+
end)
25+
end)

0 commit comments

Comments
 (0)