summaryrefslogtreecommitdiff
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
parentc248885e5790ce81018ddc8f8afbc3c173051059 (diff)
downloadale-b172cd8b17a8d9f0573e75211963e59b37ad5c34.zip
Add phan as a linter for php files (#1026)
Add phan for checking PHP code
-rw-r--r--README.md2
-rw-r--r--ale_linters/php/phan.vim36
-rw-r--r--doc/ale-php.txt15
-rw-r--r--doc/ale.txt3
-rw-r--r--test/handler/test_php_phan_handler.vader24
5 files changed, 78 insertions, 2 deletions
diff --git a/README.md b/README.md
index 813b429f..742712af 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 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',
+\})
diff --git a/doc/ale-php.txt b/doc/ale-php.txt
index bae6d7d0..8756d60e 100644
--- a/doc/ale-php.txt
+++ b/doc/ale-php.txt
@@ -35,6 +35,21 @@ g:ale_php_langserver_use_global *g:ale_php_langserver_use_global*
===============================================================================
+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*
g:ale_php_phpcbf_executable *g:ale_php_phpcbf_executable*
diff --git a/doc/ale.txt b/doc/ale.txt
index 47b95438..2972381a 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 00000000..68ed6d06
--- /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()