summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorhaginaga <haginaga@unetworks.jp>2018-05-08 14:19:47 +0900
committerhaginaga <haginaga@unetworks.jp>2018-05-08 14:19:47 +0900
commit8cee39c614ec741f8f58cb3d8375b8431f990c2a (patch)
treed5a284b4fb70e0e6fb66ca7a3ebd1cf53ca73c41 /ale_linters
parent726a768464d3e42869088599cf1bd049f7a751df (diff)
downloadale-8cee39c614ec741f8f58cb3d8375b8431f990c2a.zip
(close w0rp/ale#1561) Add support phan_client for php
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/php/phan.vim61
1 files changed, 47 insertions, 14 deletions
diff --git a/ale_linters/php/phan.vim b/ale_linters/php/phan.vim
index f3b3d48f..de1335fe 100644
--- a/ale_linters/php/phan.vim
+++ b/ale_linters/php/phan.vim
@@ -1,28 +1,61 @@
-" Author: diegoholiveira <https://github.com/diegoholiveira>
+" Author: diegoholiveira <https://github.com/diegoholiveira>, haginaga
" Description: static analyzer for PHP
" Define the minimum severity
let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)
+let g:ale_php_phan_executable = get(g:, 'ale_php_phan_executable', 'phan')
+let g:ale_php_phan_use_client = get(g:, 'ale_php_phan_use_client', 0)
+
+function! ale_linters#php#phan#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'php_phan_executable')
+endfunction
+
function! ale_linters#php#phan#GetCommand(buffer) abort
- return 'phan -y '
- \ . ale#Var(a:buffer, 'php_phan_minimum_severity')
- \ . ' %s'
+ let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
+ if l:use_client == 1
+ let l:args = '-l '
+ \ . ' %s'
+ else
+ let l:args = '-y '
+ \ . ale#Var(a:buffer, 'php_phan_minimum_severity')
+ \ . ' %s'
+ endif
+
+ let l:executable = ale_linters#php#phan#GetExecutable(a:buffer)
+
+ return ale#Escape(l:executable) . ' ' . l:args
endfunction
function! ale_linters#php#phan#Handle(buffer, lines) abort
+ let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
+
" Matches against lines like the following:
- "
- " /path/to/some-filename.php:18 ERRORTYPE message
- let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
- let l:output = []
+ if l:use_client == 1
+ " Phan error: ERRORTYPE: message in /path/to/some-filename.php on line nnn
+ let l:pattern = '^Phan error: \(\w\+\): \(.\+\) in \(.\+\) on line \(\d\+\)$'
+ else
+ " /path/to/some-filename.php:18 ERRORTYPE message
+ let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
+ endif
+ let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
- call add(l:output, {
- \ 'lnum': l:match[1] + 0,
- \ 'text': l:match[3],
- \ 'type': 'W',
- \})
+ if l:use_client == 1
+ let l:dict = {
+ \ 'lnum': l:match[4] + 0,
+ \ 'text': l:match[2],
+ \ 'type': 'W',
+ \}
+ else
+ let l:dict = {
+ \ 'lnum': l:match[1] + 0,
+ \ 'text': l:match[3],
+ \ 'type': 'W',
+ \}
+ endif
+
+ call add(l:output, l:dict)
endfor
return l:output
@@ -30,7 +63,7 @@ endfunction
call ale#linter#Define('php', {
\ 'name': 'phan',
-\ 'executable': 'phan',
+\ 'executable_callback': 'ale_linters#php#phan#GetExecutable',
\ 'command_callback': 'ale_linters#php#phan#GetCommand',
\ 'callback': 'ale_linters#php#phan#Handle',
\})