summaryrefslogtreecommitdiff
path: root/ale_linters
diff options
context:
space:
mode:
authorDiego Oliveira <contato@diegoholiveira.com>2017-10-24 19:25:02 -0200
committerw0rp <w0rp@users.noreply.github.com>2017-10-24 22:25:02 +0100
commitb172cd8b17a8d9f0573e75211963e59b37ad5c34 (patch)
treec316cedc4171028ec03160e1c6299a2dce168670 /ale_linters
parentc248885e5790ce81018ddc8f8afbc3c173051059 (diff)
downloadale-b172cd8b17a8d9f0573e75211963e59b37ad5c34.zip
Add phan as a linter for php files (#1026)
Add phan for checking PHP code
Diffstat (limited to 'ale_linters')
-rw-r--r--ale_linters/php/phan.vim36
1 files changed, 36 insertions, 0 deletions
diff --git a/ale_linters/php/phan.vim b/ale_linters/php/phan.vim
new file mode 100644
index 00000000..f3b3d48f
--- /dev/null
+++ b/ale_linters/php/phan.vim
@@ -0,0 +1,36 @@
+" Author: diegoholiveira <https://github.com/diegoholiveira>
+" Description: static analyzer for PHP
+
+" Define the minimum severity
+let g:ale_php_phan_minimum_severity = get(g:, 'ale_php_phan_minimum_severity', 0)
+
+function! ale_linters#php#phan#GetCommand(buffer) abort
+ return 'phan -y '
+ \ . ale#Var(a:buffer, 'php_phan_minimum_severity')
+ \ . ' %s'
+endfunction
+
+function! ale_linters#php#phan#Handle(buffer, lines) abort
+ " Matches against lines like the following:
+ "
+ " /path/to/some-filename.php:18 ERRORTYPE message
+ let l:pattern = '^.*:\(\d\+\)\s\(\w\+\)\s\(.\+\)$'
+ 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',
+ \})
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('php', {
+\ 'name': 'phan',
+\ 'executable': 'phan',
+\ 'command_callback': 'ale_linters#php#phan#GetCommand',
+\ 'callback': 'ale_linters#php#phan#Handle',
+\})