]> git.madduck.net Git - etc/vim.git/blob - ale_linters/spec/rpmlint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / ale_linters / spec / rpmlint.vim
1 " Author: Jason Tibbitts <tibbs@math.uh.edu>
2 " Description: Adds support for checking RPM spec files with rpmlint
3
4 " rpmlint will produce varions types of output:
5 "
6 " Lines like the following are output when the file is simply not able to be
7 " parsed by rpmspec -P:
8 "   apcupsd.spec: E: specfile-error warning: bogus date in %changelog: Mon Oct 1 2005 - Foo
9 "   apcupsd.spec: E: specfile-error error: %changelog not in descending chronological order
10 " They do not contain a line number, and there's not a whole lot that can be
11 " done to locate them besides grep for them.  rpmlint is just passing the
12 " output from rpm along with the filename, an error indicator, and an error
13 " type.
14 "
15 " Lines like the following:
16 "   cyrus-imapd.spec:23: W: macro-in-comment %version
17 "   cyrus-imapd.spec:18: E: hardcoded-library-path in %_prefix/lib/%name
18 " indicate warnings and errors, respectively.  No column numbers are provided
19 "
20 " Lines like:
21 "   apcupsd.spec: I: checking
22 "   apcupsd.spec: I: checking-url https://downloads.sourceforge.net/apcupsd/apcupsd-3.14.14.tar.gz (timeout 10 seconds)
23 " are merely informational and are only output when -v is passed.  But they
24 " may be useful in a log to know why things are taking so long.
25 "
26 " And this is always output at the end and should just be ignored:
27 "   0 packages and 1 specfiles checked; 4 errors, 0 warnings.
28
29 call ale#Set('spec_rpmlint_executable', 'rpmlint')
30 call ale#Set('spec_rpmlint_options', '')
31
32 function! ale_linters#spec#rpmlint#GetCommand(buffer, version) abort
33     if ale#semver#GTE(a:version, [2, 0, 0])
34         " The -o/--option flag was removed in version 2.0.0
35         let l:version_dependent_args = ''
36     else
37         let l:version_dependent_args = ' -o "NetworkEnabled False"'
38     endif
39
40     return '%e'
41     \   . ale#Pad(ale#Var(a:buffer, 'spec_rpmlint_options'))
42     \   . ' -v'
43     \   . l:version_dependent_args
44     \   . ' %t'
45 endfunction
46
47 function! ale_linters#spec#rpmlint#Handle(buffer, lines) abort
48     " let l:pat_inform = '^.\+: I: \(.+\)'
49     let l:pat_errwarn = '^.\+:\(\d\+\): \([EW]\): \(.\+\)'
50     let l:pat_baderr = '^.\+: E: \(.\+\)'
51     let l:output = []
52
53     for l:line in a:lines
54         let l:match_errwarn = matchlist(l:line, l:pat_errwarn)
55         let l:match_baderr = matchlist(l:line, l:pat_baderr)
56
57         if len(l:match_errwarn) > 0
58             let l:text = l:match_errwarn[3]
59             let l:type = l:match_errwarn[2]
60             let l:lnum = l:match_errwarn[1] + 0
61         elseif len(l:match_baderr) > 0
62             let l:text = l:match_baderr[1]
63             let l:type = 'E'
64             let l:lnum = 1
65         else
66             continue
67         endif
68
69         call add(l:output, {
70         \   'bufnr': a:buffer,
71         \   'lnum': l:lnum,
72         \   'text': l:text,
73         \   'type': l:type,
74         \})
75     endfor
76
77     return l:output
78 endfunction
79
80 call ale#linter#Define('spec', {
81 \   'name': 'rpmlint',
82 \   'executable': {b -> ale#Var(b, 'spec_rpmlint_executable')},
83 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
84 \       buffer,
85 \       ale#Var(buffer, 'spec_rpmlint_executable'),
86 \       '%e --version',
87 \       function('ale_linters#spec#rpmlint#GetCommand'),
88 \   )},
89 \   'callback': 'ale_linters#spec#rpmlint#Handle',
90 \})