Skip to content

Commit

Permalink
Add linter for rpmspec (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptomilk authored Sep 19, 2023
1 parent 3c936d9 commit 63fab8d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Other dedicated linters that are built-in are:
| [robocop][robocop] | `robocop` |
| [rstcheck][rstcheck] | `rstcheck` |
| [rstlint][rstlint] | `rstlint` |
| [RPM][rpm] | `rpmspec` |
| [Ruby][ruby] | `ruby` |
| [RuboCop][rubocop] | `rubocop` |
| [Ruff][ruff] | `ruff` |
Expand Down Expand Up @@ -389,3 +390,4 @@ busted tests/
[perlimports]: https://github.com/perl-ide/App-perlimports
[perlcritic]: https://github.com/Perl-Critic/Perl-Critic
[gdlint]: https://github.com/Scony/godot-gdscript-toolkit
[rpm]: https://rpm.org
42 changes: 42 additions & 0 deletions lua/lint/linters/rpmspec.lua
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,
}
33 changes: 33 additions & 0 deletions tests/rpmspec_spec.lua
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)

0 comments on commit 63fab8d

Please sign in to comment.