]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/perl/perl.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 '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / perl / perl.vim
1 " Author: Vincent Lequertier <https://github.com/SkySymbol>
2 " Description: This file adds support for checking perl syntax
3
4 call ale#Set('perl_perl_executable', 'perl')
5 call ale#Set('perl_perl_options', '-c -Mwarnings -Ilib')
6
7 function! ale_linters#perl#perl#GetCommand(buffer) abort
8     return '%e' . ale#Pad(ale#Var(a:buffer, 'perl_perl_options')) . ' %t'
9 endfunction
10
11 let s:begin_failed_skip_pattern = '\v' . join([
12 \   '^Compilation failed in require',
13 \   '^Can''t locate',
14 \], '|')
15
16 function! ale_linters#perl#perl#Handle(buffer, lines) abort
17     if empty(a:lines)
18         return []
19     endif
20
21     let l:pattern = '\(..\{-}\) at \(..\{-}\) line \(\d\+\)'
22     let l:output = []
23     let l:basename = expand('#' . a:buffer . ':t')
24
25     let l:type = 'E'
26
27     if a:lines[-1] =~# 'syntax OK'
28         let l:type = 'W'
29     endif
30
31     let l:seen = {}
32
33     for l:match in ale#util#GetMatches(a:lines, l:pattern)
34         let l:line = l:match[3]
35         let l:file = l:match[2]
36         let l:text = l:match[1]
37
38         if ale#path#IsBufferPath(a:buffer, l:file)
39         \ && !has_key(l:seen,l:line)
40         \ && (
41         \   l:text isnot# 'BEGIN failed--compilation aborted'
42         \   || empty(l:output)
43         \   || match(l:output[-1].text, s:begin_failed_skip_pattern) < 0
44         \ )
45             call add(l:output, {
46             \   'lnum': l:line,
47             \   'text': l:text,
48             \   'type': l:type,
49             \})
50
51             let l:seen[l:line] = 1
52         endif
53     endfor
54
55     return l:output
56 endfunction
57
58 call ale#linter#Define('perl', {
59 \   'name': 'perl',
60 \   'executable': {b -> ale#Var(b, 'perl_perl_executable')},
61 \   'output_stream': 'both',
62 \   'command': function('ale_linters#perl#perl#GetCommand'),
63 \   'callback': 'ale_linters#perl#perl#Handle',
64 \})