From 5a0c3fd01e79feb1b35e554c38045ae0a88c429f Mon Sep 17 00:00:00 2001 From: Zefei Xuan Date: Wed, 4 Jan 2017 09:07:21 -0800 Subject: [PATCH] Added hack linter for php (#239) * added hack linter * updated docs for hack (hh_client) * naming --- README.md | 2 +- ale_linters/php/hack.vim | 37 +++++++++++++++++++++++++++++++++++++ doc/ale.txt | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ale_linters/php/hack.vim diff --git a/README.md b/README.md index 07866013..200cc5d9 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ name. That seems to be the fairest way to arrange this table. | MATLAB | [mlint](https://www.mathworks.com/help/matlab/ref/mlint.html) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-integration-ocaml-merlin` for configuration instructions | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) | -| PHP | [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) | +| PHP | [hack](http://hacklang.org/), [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) | | Pug | [pug-lint](https://github.com/pugjs/pug-lint) | | Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) | | Python | [flake8](http://flake8.pycqa.org/en/latest/), [pylint](https://www.pylint.org/) | diff --git a/ale_linters/php/hack.vim b/ale_linters/php/hack.vim new file mode 100644 index 00000000..bacd835d --- /dev/null +++ b/ale_linters/php/hack.vim @@ -0,0 +1,37 @@ +" Author: Zefei Xuan +" Description: Hack type checking (http://hacklang.org/) + +function! ale_linters#php#hack#Handle(buffer, lines) + let l:pattern = '^\(.*\):\(\d\+\):\(\d\+\),\(\d\+\): \(.\+])\)$' + let l:output = [] + + for l:line in a:lines + let l:match = matchlist(l:line, l:pattern) + + if len(l:match) == 0 + continue + endif + + if a:buffer != bufnr(l:match[1]) + continue + endif + + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': l:match[2] + 0, + \ 'vcol': 0, + \ 'col': l:match[3] + 0, + \ 'text': l:match[5], + \ 'type': 'E', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('php', { +\ 'name': 'hack', +\ 'executable': 'hh_client', +\ 'command': 'hh_client --retries 0 --retry-if-init false', +\ 'callback': 'ale_linters#php#hack#Handle', +\}) diff --git a/doc/ale.txt b/doc/ale.txt index 8144267e..6d43ec65 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -84,7 +84,7 @@ The following languages and tools are supported. * MATLAB: 'mlint' * OCaml: 'merlin' (see |ale-linter-integration-ocaml-merlin|) * Perl: 'perl' (-c flag), 'perlcritic' -* PHP: 'php' (-l flag), 'phpcs' +* PHP: 'hack', 'php' (-l flag), 'phpcs' * Pug: 'pug-lint' * Puppet: 'puppet', 'puppet-lint' * Python: 'flake8', 'pylint'