diff --git a/README.md b/README.md index 813b429..742712a 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ formatting. | Objective-C++ | [clang](http://clang.llvm.org/) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | -| PHP | [hack](http://hacklang.org/), [langserver](https://github.com/felixfbecker/php-language-server), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | +| PHP | [hack](http://hacklang.org/), [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer) | | Pod | [proselint](http://proselint.com/)| | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | diff --git a/ale_linters/php/phan.vim b/ale_linters/php/phan.vim new file mode 100644 index 0000000..f3b3d48 --- /dev/null +++ b/ale_linters/php/phan.vim @@ -0,0 +1,36 @@ +" Author: 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', +\}) diff --git a/doc/ale-php.txt b/doc/ale-php.txt index bae6d7d..8756d60 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -34,6 +34,21 @@ g:ale_php_langserver_use_global *g:ale_php_langserver_use_global* See: |ale-integrations-local-executables| +=============================================================================== +phan *ale-php-phan* + +WARNING: please do not use this linter if you have an configuration file +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. + +g:ale_php_phan_minimum_severity *g:ale_php_phan_minimum_severity* + *b:ale_php_phan_minimum_severity* + Type: |Number| + Default: `0` + + This variable defines the minimum severity level + + =============================================================================== phpcbf *ale-php-phpcbf* diff --git a/doc/ale.txt b/doc/ale.txt index 47b9543..2972381 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -115,6 +115,7 @@ CONTENTS *ale-contents* php...................................|ale-php-options| hack................................|ale-php-hack| langserver..........................|ale-php-langserver| + phan................................|ale-php-phan| phpcbf..............................|ale-php-phpcbf| phpcs...............................|ale-php-phpcs| phpmd...............................|ale-php-phpmd| @@ -273,7 +274,7 @@ Notes: * Objective-C++: `clang` * OCaml: `merlin` (see |ale-ocaml-merlin|) * Perl: `perl -c`, `perl-critic` -* PHP: `hack`, `langserver`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` +* PHP: `hack`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf` * Pod: `proselint` * Pug: `pug-lint` * Puppet: `puppet`, `puppet-lint` diff --git a/test/handler/test_php_phan_handler.vader b/test/handler/test_php_phan_handler.vader new file mode 100644 index 0000000..68ed6d0 --- /dev/null +++ b/test/handler/test_php_phan_handler.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/php/phan.vim + +Execute(The php static analyzer handler should parse errors from phan): + AssertEqual + \ [ + \ { + \ 'lnum': 25, + \ 'type': 'W', + \ 'text': 'Return type of getValidator is undeclared type \Respect\Validation\Validator', + \ }, + \ { + \ 'lnum': 66, + \ 'type': 'W', + \ 'text': 'Call to method string from undeclared class \Respect\Validation\Validator', + \ }, + \ ], + \ ale_linters#php#phan#Handle(347, [ + \ "example.php:25 PhanUndeclaredTypeReturnType Return type of getValidator is undeclared type \\Respect\\Validation\\Validator", + \ "example.php:66 PhanUndeclaredClassMethod Call to method string from undeclared class \\Respect\\Validation\\Validator", + \ ]) + +After: + call ale#linter#Reset()