Skip to content

Commit

Permalink
Add linter for rpmspec
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptomilk committed Sep 17, 2023
1 parent 12517fb commit 2afc57b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lua/lint/linters/rpmspec.lua
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,
}
37 changes: 37 additions & 0 deletions tests/rpmspec_spec.lua
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)

0 comments on commit 2afc57b

Please sign in to comment.