diff options
author | Richard Marmorstein <twitchard@users.noreply.github.com> | 2018-09-27 11:48:47 -0400 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2018-09-27 16:48:47 +0100 |
commit | 947360f714cac48cff1b3e1949b1b66b48be671e (patch) | |
tree | 75df21f7327ba0a376727f28cb2f7444d3cde391 | |
parent | 58ceb21cbc10a05f376664da31c8d7621e6d3669 (diff) | |
download | ale-947360f714cac48cff1b3e1949b1b66b48be671e.zip |
Add psalm linter for PHP (#1893)
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | ale_linters/php/psalm.vim | 28 | ||||
-rw-r--r-- | doc/ale-php.txt | 10 | ||||
-rw-r--r-- | doc/ale.txt | 3 | ||||
-rw-r--r-- | test/command_callback/test_psalm_command_callbacks.vader | 12 | ||||
-rw-r--r-- | test/handler/test_php_psalm_handler.vader | 24 |
6 files changed, 77 insertions, 2 deletions
@@ -155,7 +155,7 @@ formatting. | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) | | Pawn | [uncrustify](https://github.com/uncrustify/uncrustify) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic), [perltidy](https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy) | -| PHP | [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), [php-cs-fixer](http://cs.sensiolabs.org/) | +| PHP | [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), [php-cs-fixer](http://cs.sensiolabs.org/), [psalm](https://getpsalm.org) !! | | PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | Pony | [ponyc](https://github.com/ponylang/ponyc) | diff --git a/ale_linters/php/psalm.vim b/ale_linters/php/psalm.vim new file mode 100644 index 00000000..cd20ab81 --- /dev/null +++ b/ale_linters/php/psalm.vim @@ -0,0 +1,28 @@ +" Author: richard marmorstein <https://github.com/twitchard> +" Description: plugin for Psalm, static analyzer for PHP + +call ale#Set('php_psalm_executable', 'psalm') + +function! ale_linters#php#psalm#Handle(buffer, lines) abort + " Matches patterns like the following: + let l:pattern = '^.*:\(\d\+\):\(\d\+\):\(\w\+\) - \(.*\)$' + 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[4], + \ 'type': l:match[3][:0] is# 'e' ? 'E' : 'W', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('php', { +\ 'name': 'psalm', +\ 'command': '%e --diff --output-format=emacs %s', +\ 'executable_callback': ale#VarFunc('php_psalm_executable'), +\ 'callback': 'ale_linters#php#psalm#Handle', +\ 'lint_file': 1, +\}) diff --git a/doc/ale-php.txt b/doc/ale-php.txt index f38c3f88..2eed838e 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -170,6 +170,16 @@ g:ale_php_phpstan_configuration *g:ale_php_phpstan_configuration* =============================================================================== +psalm *ale-php-psalm* + +g:ale_php_psalm_executable *g:ale_php_psalm_executable* + *b:ale_php_psalm_executable* + Type: |String| + Default: `'psalm'` + + This variable sets the executable used for psalm. + +=============================================================================== php-cs-fixer *ale-php-php-cs-fixer* g:ale_php_cs_fixer_executable *g:ale_php_cs_fixer_executable* diff --git a/doc/ale.txt b/doc/ale.txt index b166d9c5..1cf2945f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -206,6 +206,7 @@ CONTENTS *ale-contents* phpcs...............................|ale-php-phpcs| phpmd...............................|ale-php-phpmd| phpstan.............................|ale-php-phpstan| + psalm...............................|ale-php-psalm| php-cs-fixer........................|ale-php-php-cs-fixer| po....................................|ale-po-options| write-good..........................|ale-po-write-good| @@ -433,7 +434,7 @@ Notes: * OCaml: `merlin` (see |ale-ocaml-merlin|), `ols`, `ocamlformat` * Pawn: `uncrustify` * Perl: `perl -c`, `perl-critic`, `perltidy` -* PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer` +* PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`, `psalm`!! * PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` * Pony: `ponyc` diff --git a/test/command_callback/test_psalm_command_callbacks.vader b/test/command_callback/test_psalm_command_callbacks.vader new file mode 100644 index 00000000..4c31b7b4 --- /dev/null +++ b/test/command_callback/test_psalm_command_callbacks.vader @@ -0,0 +1,12 @@ +Before: + call ale#assert#SetUpLinterTest('php', 'psalm') + +After: + call ale#assert#TearDownLinterTest() + +Execute(Custom executables should be used for the executable and command): + let g:ale_php_psalm_executable = 'psalm_test' + + AssertLinter 'psalm_test', + \ ale#Escape('psalm_test') . ' --diff --output-format=emacs %s' + diff --git a/test/handler/test_php_psalm_handler.vader b/test/handler/test_php_psalm_handler.vader new file mode 100644 index 00000000..fd62a467 --- /dev/null +++ b/test/handler/test_php_psalm_handler.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/php/psalm.vim + +After: + call ale#linter#Reset() + +Execute(The php static analyzer handler should parse errors from psalm): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'type': 'W', + \ 'text': 'somewarning', + \ }, + \ { + \ 'lnum': 11, + \ 'type': 'E', + \ 'text': 'someerror', + \ }, + \ ], + \ ale_linters#php#psalm#Handle(347, [ + \ "/file:1:3:warning - somewarning", + \ "/file:11:33:error - someerror", + \ ]) |