From 7d174b00561f2cb6a6ad71b839b1b6fc6bd88e3b Mon Sep 17 00:00:00 2001 From: Ardis Date: Sun, 16 Jul 2017 16:04:25 +0200 Subject: Added phpstan linter for php. (#772) * Added phpstan linter for php. --- ale_linters/php/phpstan.vim | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ale_linters/php/phpstan.vim (limited to 'ale_linters/php') diff --git a/ale_linters/php/phpstan.vim b/ale_linters/php/phpstan.vim new file mode 100644 index 00000000..69173ef4 --- /dev/null +++ b/ale_linters/php/phpstan.vim @@ -0,0 +1,40 @@ +" Author: medains , ardis +" Description: phpstan for PHP files + +" Set to change the ruleset +let g:ale_php_phpstan_executable = get(g:, 'ale_php_phpstan_executable', 'phpstan') +let g:ale_php_phpstan_level = get(g:, 'ale_php_phpstan_level', '4') + +function! ale_linters#php#phpstan#GetCommand(buffer) abort + return ale#Var(a:buffer, 'php_phpstan_executable') + \ . ' analyze -l' + \ . ale#Var(a:buffer, 'php_phpstan_level') + \ . ' --errorFormat raw' + \ . ' %s' +endfunction + +function! ale_linters#php#phpstan#Handle(buffer, lines) abort + " Matches against lines like the following: + " + " filename.php:15:message + " C:\folder\filename.php:15:message + let l:pattern = '^\([a-zA-Z]:\)\?[^:]\+:\(\d\+\):\(.*\)$' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:pattern) + call add(l:output, { + \ 'lnum': l:match[2] + 0, + \ 'text': l:match[3], + \ 'type': 'W', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('php', { +\ 'name': 'phpstan', +\ 'executable': 'phpstan', +\ 'command_callback': 'ale_linters#php#phpstan#GetCommand', +\ 'callback': 'ale_linters#php#phpstan#Handle', +\}) -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0