-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
3c936d9
commit 63fab8d
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,42 @@ | ||
-- 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.WARN, | ||
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,33 @@ | ||
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 = 0, | ||
lnum = 0, | ||
message = 'Macro expanded in comment', | ||
severity = vim.diagnostic.severity.WARN, | ||
source = 'rpmspec', | ||
} | ||
local expected_error_1 = { | ||
col = 0, | ||
end_col = 0, | ||
end_lnum = 1, | ||
lnum = 1, | ||
message = 'Unknown tag: %if', | ||
severity = vim.diagnostic.severity.ERROR, | ||
source = 'rpmspec', | ||
} | ||
assert.are.same(expected_error_1, result[1]) | ||
assert.are.same(expected_warning_1, result[2]) | ||
end) | ||
end) |