Skip to content

Commit

Permalink
Add systemdlint support
Browse files Browse the repository at this point in the history
Signed-off-by: Antonin Godard <[email protected]>
  • Loading branch information
antznin authored and mfussenegger committed Feb 20, 2024
1 parent cab1de0 commit 0e2858f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Other dedicated linters that are built-in are:
| [statix check][33] | `statix` |
| [stylelint][29] | `stylelint` |
| [Solhint][solhint] | `solhint` |
| [systemdlint][systemdlint] | `systemdlint` |
| [typos][typos] | `typos` |
| [Nagelfar][nagelfar] | `nagelfar` |
| [Vala][vala-lint] | `vala_lint` |
Expand Down Expand Up @@ -493,3 +494,4 @@ busted tests/
[opa_check]: https://www.openpolicyagent.org/
[regal]: https://github.com/StyraInc/regal
[vala-lint]: https://github.com/vala-lang/vala-lint
[systemdlint]: https://github.com/priv-kweihmann/systemdlint
22 changes: 22 additions & 0 deletions lua/lint/linters/systemdlint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- path/to/file:line:severity:code:message
local pattern = '([^:]+):(%d+):(%a+):(.+):(.+)'
local groups = { 'file', 'lnum', 'severity', 'code', 'message' }
local severity_map = {
['error'] = vim.diagnostic.severity.ERROR,
['warning'] = vim.diagnostic.severity.WARN,
['info'] = vim.diagnostic.severity.INFO,
}

return {
cmd = 'systemdlint',
stdin = false,
args = {
'--messageformat={path}:{line}:{severity}:{id}:{msg}',
},
ignore_exitcode = true,
stream = 'stderr',
parser = require('lint.parser').from_pattern(
pattern, groups, severity_map,
{ ['source'] = 'systemdlint' }
),
}
53 changes: 53 additions & 0 deletions tests/systemdlint_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('linter.systemdlint', function()
it('can parse the output', function()
local parser = require('lint.linters.systemdlint').parser
local bufnr = vim.uri_to_bufnr('file:///foo.service')
local result = parser([[
/foo.service:1:error:ExecNotFound:Command referenced not found
/foo.service:2:info:NoFailureCheck:Return-code check is disabled. Errors are not reported
/foo.service:3:warning:ReferencedUnitNotFound:The Unit 'bar.service' referenced was not found in filesystem
]], bufnr)

assert.are.same(3, #result)

local expected_error = {
code = 'ExecNotFound',
source = 'systemdlint',
message = 'Command referenced not found',
lnum = 0,
col = 0,
end_lnum = 0,
end_col = 0,
severity = vim.diagnostic.severity.ERROR,
user_data = { lsp = { code = 'ExecNotFound' } },
}
assert.are.same(expected_error, result[1])

local expected_info = {
code = 'NoFailureCheck',
source = 'systemdlint',
message = 'Return-code check is disabled. Errors are not reported',
lnum = 1,
col = 0,
end_lnum = 1,
end_col = 0,
severity = vim.diagnostic.severity.INFO,
user_data = { lsp = { code = 'NoFailureCheck' } },
}
assert.are.same(expected_info, result[2])

local expected_warning = {
code = 'ReferencedUnitNotFound',
source = 'systemdlint',
message = 'The Unit \'bar.service\' referenced was not found in filesystem',
lnum = 2,
col = 0,
end_lnum = 2,
end_col = 0,
severity = vim.diagnostic.severity.WARN,
user_data = { lsp = { code = 'ReferencedUnitNotFound' } },
}
assert.are.same(expected_warning, result[3])

end)
end)

0 comments on commit 0e2858f

Please sign in to comment.