Skip to content

Commit

Permalink
fixup! Add linter for rpmspec
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Sep 19, 2023
1 parent 9d249b1 commit 346e530
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 8 additions & 5 deletions lua/lint/linters/rpmspec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ local parsers = {
[[(%w+): line (%d+): (.*)]],
{ 'severity', 'lnum', 'message' },
nil,
{ ['severity'] = vim.diagnostic.severity.ERROR, ['source'] = 'rpmspec' }
{
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' }
{
severity = vim.diagnostic.severity.WARN,
source = 'rpmspec'
}
),
}

Expand All @@ -27,13 +33,10 @@ return {
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,
}
20 changes: 8 additions & 12 deletions tests/rpmspec_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@ 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,
end_lnum = 0,
lnum = 0,
message = 'Macro expanded in comment',
severity = 2,
severity = vim.diagnostic.severity.WARN,
source = 'rpmspec',
}

assert.are.same(expected_warning_1, result[1])

local expected_error_1 = {
col = 0,
end_col = 0,
end_lnum = 2,
lnum = 2,
end_lnum = 1,
lnum = 1,
message = 'Unknown tag: %if',
severity = 1,
severity = vim.diagnostic.severity.ERROR,
source = 'rpmspec',
}

assert.are.same(expected_error_1, result[2])
assert.are.same(expected_error_1, result[1])
assert.are.same(expected_warning_1, result[2])
end)
end)

0 comments on commit 346e530

Please sign in to comment.