-
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12517fb
commit 2afc57b
Showing
2 changed files
with
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- This is a linter for https://rpm.org/ | ||
local parsers = { | ||
-- errors | ||
require('lint.parser').from_pattern( | ||
[[(%w+): line (%d+): (.*)]], | ||
{ 'severity', 'lnum', 'message' }, | ||
nil, | ||
{ ['severity'] = vim.diagnostic.severity.ERROR, ['source'] = 'rpmspec' } | ||
), | ||
|
||
-- warnings | ||
require('lint.parser').from_pattern( | ||
[[(%w+): (.*) on line (%d+):]], | ||
{ 'severity', 'message', 'lnum' }, | ||
nil, | ||
{ ['severity'] = vim.diagnostic.severity.WARNING, ['source'] = 'rpmspec' } | ||
), | ||
} | ||
|
||
-- Usage: rpmspec -P <file> | ||
return { | ||
cmd = 'rpmspec', | ||
stdin = false, | ||
append_fname = true, | ||
args = { '-P' }, | ||
stream = 'stderr', | ||
ignore_exitcode = true, | ||
parser = function(output, bufnr) | ||
local diagnostics = {} | ||
|
||
for _, parser in ipairs(parsers) do | ||
local result = parser(output, bufnr) | ||
|
||
vim.list_extend(diagnostics, result) | ||
end | ||
|
||
return diagnostics | ||
end, | ||
} |
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,37 @@ | ||
describe('linter.rpmspec', function() | ||
it('can parse the output', function() | ||
local parser = require('lint.linters.rpmspec').parser | ||
local bufnr = vim.uri_to_bufnr('file:///foo.spec') | ||
local output = [[ | ||
warning: Macro expanded in comment on line 1: %{?fedora} | ||
error: line 2: Unknown tag: %if | ||
]] | ||
local result = parser(output, bufnr) | ||
|
||
assert.are.same(2, #result) | ||
|
||
local expected_warning_1 = { | ||
col = 0, | ||
end_col = 0, | ||
end_lnum = 1, | ||
lnum = 1, | ||
message = 'Macro expanded in comment', | ||
severity = 2, | ||
source = 'rpmspec', | ||
} | ||
|
||
assert.are.same(expected_warning_1, result[1]) | ||
|
||
local expected_error_1 = { | ||
col = 0, | ||
end_col = 0, | ||
end_lnum = 2, | ||
lnum = 2, | ||
message = 'Unknown tag: %if', | ||
severity = 1, | ||
source = 'rpmspec', | ||
} | ||
|
||
assert.are.same(expected_error_1, result[2]) | ||
end) | ||
end) |