(close w0rp/ale#1561) Add support phan_client for php
This commit is contained in:
parent
726a768464
commit
8cee39c614
@ -1,28 +1,61 @@
|
|||||||
" Author: diegoholiveira <https://github.com/diegoholiveira>
|
" Author: diegoholiveira <https://github.com/diegoholiveira>, haginaga
|
||||||
" Description: static analyzer for PHP
|
" Description: static analyzer for PHP
|
||||||
|
|
||||||
" Define the minimum severity
|
" Define the minimum severity
|
||||||
let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)
|
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
|
function! ale_linters#php#phan#GetCommand(buffer) abort
|
||||||
return 'phan -y '
|
let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
|
||||||
\ . ale#Var(a:buffer, 'php_phan_minimum_severity')
|
if l:use_client == 1
|
||||||
\ . ' %s'
|
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
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#php#phan#Handle(buffer, lines) abort
|
function! ale_linters#php#phan#Handle(buffer, lines) abort
|
||||||
" Matches against lines like the following:
|
let l:use_client = ale#Var(a:buffer, 'php_phan_use_client')
|
||||||
"
|
|
||||||
" /path/to/some-filename.php:18 ERRORTYPE message
|
|
||||||
let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
|
|
||||||
let l:output = []
|
|
||||||
|
|
||||||
|
" Matches against lines like the following:
|
||||||
|
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)
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
call add(l:output, {
|
if l:use_client == 1
|
||||||
\ 'lnum': l:match[1] + 0,
|
let l:dict = {
|
||||||
\ 'text': l:match[3],
|
\ 'lnum': l:match[4] + 0,
|
||||||
\ 'type': 'W',
|
\ '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
|
endfor
|
||||||
|
|
||||||
return l:output
|
return l:output
|
||||||
@ -30,7 +63,7 @@ endfunction
|
|||||||
|
|
||||||
call ale#linter#Define('php', {
|
call ale#linter#Define('php', {
|
||||||
\ 'name': 'phan',
|
\ 'name': 'phan',
|
||||||
\ 'executable': 'phan',
|
\ 'executable_callback': 'ale_linters#php#phan#GetExecutable',
|
||||||
\ 'command_callback': 'ale_linters#php#phan#GetCommand',
|
\ 'command_callback': 'ale_linters#php#phan#GetCommand',
|
||||||
\ 'callback': 'ale_linters#php#phan#Handle',
|
\ 'callback': 'ale_linters#php#phan#Handle',
|
||||||
\})
|
\})
|
||||||
|
@ -48,7 +48,7 @@ g:ale_php_langserver_use_global *g:ale_php_langserver_use_global*
|
|||||||
===============================================================================
|
===============================================================================
|
||||||
phan *ale-php-phan*
|
phan *ale-php-phan*
|
||||||
|
|
||||||
WARNING: please do not use this linter if you have an configuration file
|
WARNING: please use the phan_client linter if you have an configuration file
|
||||||
for your project because the phan will look into your entirely project and
|
for your project because the phan will look into your entirely project and
|
||||||
ale will display in the current buffer warnings that may belong to other file.
|
ale will display in the current buffer warnings that may belong to other file.
|
||||||
|
|
||||||
@ -57,8 +57,22 @@ g:ale_php_phan_minimum_severity *g:ale_php_phan_minimum_severity*
|
|||||||
Type: |Number|
|
Type: |Number|
|
||||||
Default: `0`
|
Default: `0`
|
||||||
|
|
||||||
This variable defines the minimum severity level
|
This variable defines the minimum severity level.
|
||||||
|
|
||||||
|
g:ale_php_phan_executable *g:ale_php_phan_executable*
|
||||||
|
*b:ale_php_phan_executable*
|
||||||
|
Type: |String|
|
||||||
|
Default: `'phan'`
|
||||||
|
|
||||||
|
This variable sets executable used for phan or phan_client.
|
||||||
|
|
||||||
|
g:ale_php_phan_use_client *g:ale_php_phan_use_client*
|
||||||
|
*b:ale_php_phan_use_client*
|
||||||
|
Type: |Number|
|
||||||
|
Default: `get(g:, 'ale_php_phan_use_client', 0)`
|
||||||
|
|
||||||
|
This variable can be set to 1 to use the phan_client with phan daemon mode
|
||||||
|
instead of the phan standalone.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
phpcbf *ale-php-phpcbf*
|
phpcbf *ale-php-phpcbf*
|
||||||
|
Loading…
Reference in New Issue
Block a user