]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/perl/perlcritic.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:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / perl / perlcritic.vim
1 " Author: Vincent Lequertier <https://github.com/SkySymbol>, Chris Weyl <cweyl@alumni.drew.edu>
2 " Description: This file adds support for checking perl with perl critic
3
4 call ale#Set('perl_perlcritic_executable', 'perlcritic')
5 call ale#Set('perl_perlcritic_profile', '.perlcriticrc')
6 call ale#Set('perl_perlcritic_options', '')
7 call ale#Set('perl_perlcritic_showrules', 0)
8
9 function! ale_linters#perl#perlcritic#GetProfile(buffer) abort
10     " first see if we've been overridden
11     let l:profile = ale#Var(a:buffer, 'perl_perlcritic_profile')
12
13     if l:profile is? ''
14         return ''
15     endif
16
17     " otherwise, iterate upwards to find it
18     return ale#path#FindNearestFile(a:buffer, l:profile)
19 endfunction
20
21 function! ale_linters#perl#perlcritic#GetCommand(buffer) abort
22     let l:critic_verbosity = '%l:%c %m\n'
23
24     if ale#Var(a:buffer, 'perl_perlcritic_showrules')
25         let l:critic_verbosity = '%l:%c %m [%p]\n'
26     endif
27
28     let l:profile = ale_linters#perl#perlcritic#GetProfile(a:buffer)
29     let l:options = ale#Var(a:buffer, 'perl_perlcritic_options')
30
31     return '%e'
32     \   . ' --verbose ' . ale#Escape(l:critic_verbosity)
33     \   . ' --nocolor'
34     \   . (!empty(l:profile) ? ' --profile ' . ale#Escape(l:profile) : '')
35     \   . ale#Pad(l:options)
36 endfunction
37
38
39 function! ale_linters#perl#perlcritic#Handle(buffer, lines) abort
40     let l:pattern = '\(\d\+\):\(\d\+\) \(.\+\)'
41     let l:output = []
42
43     for l:match in ale#util#GetMatches(a:lines, l:pattern)
44         call add(l:output, {
45         \   'lnum': l:match[1],
46         \   'col': l:match[2],
47         \   'text': l:match[3],
48         \   'type': 'W'
49         \})
50     endfor
51
52     return l:output
53 endfunction
54
55 call ale#linter#Define('perl', {
56 \   'name': 'perlcritic',
57 \   'output_stream': 'stdout',
58 \   'executable': {b -> ale#Var(b, 'perl_perlcritic_executable')},
59 \   'command': function('ale_linters#perl#perlcritic#GetCommand'),
60 \   'callback': 'ale_linters#perl#perlcritic#Handle',
61 \})