-
-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Antonin Godard <[email protected]>
- Loading branch information
1 parent
cab1de0
commit 0e2858f
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | ||
), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |