]> git.madduck.net Git - etc/vim.git/blob - ale_linters/php/phan.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 / php / phan.vim
1 " Author: diegoholiveira <https://github.com/diegoholiveira>, haginaga <https://github.com/haginaga>
2 " Description: static analyzer for PHP
3
4 " Define the minimum severity
5 let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)
6
7 let g:ale_php_phan_executable = get(g:, 'ale_php_phan_executable', 'phan')
8 let g:ale_php_phan_use_client = get(g:, 'ale_php_phan_use_client', 0)
9
10 function! ale_linters#php#phan#GetExecutable(buffer) abort
11     let l:executable = ale#Var(a:buffer, 'php_phan_executable')
12
13     if ale#Var(a:buffer, 'php_phan_use_client') == 1 && l:executable is# 'phan'
14         let l:executable = 'phan_client'
15     endif
16
17     return l:executable
18 endfunction
19
20 function! ale_linters#php#phan#GetCommand(buffer) abort
21     if ale#Var(a:buffer, 'php_phan_use_client') == 1
22         let l:args = '-l '
23         \   . ' %s'
24     else
25         let l:args = '-y '
26         \   . ale#Var(a:buffer, 'php_phan_minimum_severity')
27         \   . ' %s'
28     endif
29
30     let l:executable = ale_linters#php#phan#GetExecutable(a:buffer)
31
32     return ale#Escape(l:executable) . ' ' . l:args
33 endfunction
34
35 function! ale_linters#php#phan#Handle(buffer, lines) abort
36     " Matches against lines like the following:
37     if ale#Var(a:buffer, 'php_phan_use_client') == 1
38         " Phan error: ERRORTYPE: message in /path/to/some-filename.php on line nnn
39         let l:pattern = '^Phan error: \(\w\+\): \(.\+\) in \(.\+\) on line \(\d\+\)$'
40     else
41         " /path/to/some-filename.php:18 ERRORTYPE message
42         let l:pattern = '^\(.*\):\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
43     endif
44
45     let l:output = []
46
47     for l:match in ale#util#GetMatches(a:lines, l:pattern)
48         if ale#Var(a:buffer, 'php_phan_use_client') == 1
49             let l:dict = {
50             \   'lnum': l:match[4] + 0,
51             \   'text': l:match[2],
52             \   'filename': l:match[3],
53             \   'type': 'W',
54             \}
55         else
56             let l:dict = {
57             \   'lnum': l:match[2] + 0,
58             \   'text': l:match[4],
59             \   'type': 'W',
60             \   'filename': l:match[1],
61             \}
62         endif
63
64         call add(l:output, l:dict)
65     endfor
66
67     return l:output
68 endfunction
69
70 call ale#linter#Define('php', {
71 \   'name': 'phan',
72 \   'executable': function('ale_linters#php#phan#GetExecutable'),
73 \   'command': function('ale_linters#php#phan#GetCommand'),
74 \   'callback': 'ale_linters#php#phan#Handle',
75 \})