Skip to content

Commit

Permalink
Add rpmlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mulling authored and mfussenegger committed Dec 19, 2024
1 parent 0efe84e commit 3683676
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ Other dedicated linters that are built-in are:
| [Revive][14] | `revive` |
| [rflint][rflint] | `rflint` |
| [robocop][robocop] | `robocop` |
| [rpmlint][rpmlint] | `rpmlint` |
| [RPM][rpm] | `rpmspec` |
| [rstcheck][rstcheck] | `rstcheck` |
| [rstlint][rstlint] | `rstlint` |
Expand Down Expand Up @@ -538,6 +539,7 @@ busted tests/
[perlcritic]: https://github.com/Perl-Critic/Perl-Critic
[ponyc]: https://github.com/ponylang/ponyc
[gdlint]: https://github.com/Scony/godot-gdscript-toolkit
[rpmlint]: https://github.com/rpm-software-management/rpmlint
[rpm]: https://rpm.org
[ec]: https://github.com/editorconfig-checker/editorconfig-checker
[dmypy]: https://mypy.readthedocs.io/en/stable/mypy_daemon.html
Expand Down
54 changes: 54 additions & 0 deletions lua/lint/linters/rpmlint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local severity = {
['W'] = vim.diagnostic.severity.WARN,
['E'] = vim.diagnostic.severity.ERROR,
}

local parsers = {
require('lint.parser').from_pattern(
'warning: line (%d+): (.*)',
{ 'lnum', 'message' },
nil,
{
severity = vim.diagnostic.severity.WARN,
source = 'rpmlint'
}
),

require('lint.parser').from_pattern(
'.*:(%d+): ([W|E]): (.*)',
{ 'lnum', 'severity', 'message' },
severity,
{
severity = vim.diagnostic.severity.WARN,
source = 'rpmlint'
}
),

require('lint.parser').from_pattern(
'.*: E: .*: line (%d+): (.*)',
{ 'lnum', 'message' },
nil,
{
severity = vim.diagnostic.severity.ERROR,
source = 'rpmlint'
}
),

}

return {
cmd = 'rpmlint',
stdin = false,
append_fname = true,
args = {},
stream = 'both',
ignore_exitcode = true,
parser = function(output, bufnr, cwd)
local diagnostics = {}
for _, parser in ipairs(parsers) do
local result = parser(output, bufnr, cwd)
vim.list_extend(diagnostics, result)
end
return diagnostics
end,
}
59 changes: 59 additions & 0 deletions spec/rpmlint_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
describe('linter.rpmlint', function()
it('can parse the output', function()
local parser = require('lint.linters.rpmlint').parser
local bufnr = vim.uri_to_bufnr('file:///foo.spec')
local output = [[
warning: line 162: It's not recommended to have unversioned Obsoletes
foo.spec:17: W: %autopatch-not-in-prep
foo.spec: E: specfile-error error: line 31: Unknown tag: %escription
foo.spec:9: E: buildprereq-use Something
]]
local result = parser(output, bufnr)
assert.are.same(4, #result)

local expected_warning_1 = {
col = 0,
end_col = 0,
end_lnum = 161,
lnum = 161,
message = "It's not recommended to have unversioned Obsoletes",
severity = vim.diagnostic.severity.WARN,
source = 'rpmlint',
}

local expected_warning_2 = {
col = 0,
end_col = 0,
end_lnum = 16,
lnum = 16,
message = '%autopatch-not-in-prep',
severity = vim.diagnostic.severity.WARN,
source = 'rpmlint',
}

local expected_error_1 = {
col = 0,
end_col = 0,
end_lnum = 30,
lnum = 30,
message = 'Unknown tag: %escription',
severity = vim.diagnostic.severity.ERROR,
source = 'rpmlint',
}

local expected_error_2 = {
col = 0,
end_col = 0,
end_lnum = 8,
lnum = 8,
message = 'buildprereq-use Something',
severity = vim.diagnostic.severity.ERROR,
source = 'rpmlint',
}

assert.are.same(expected_warning_1, result[1])
assert.are.same(expected_warning_2, result[2])
assert.are.same(expected_error_1, result[4])
assert.are.same(expected_error_2, result[3])
end)
end)

0 comments on commit 3683676

Please sign in to comment.