summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZefei Xuan <zefei.xuan@gmail.com>2017-01-04 09:07:21 -0800
committerw0rp <w0rp@users.noreply.github.com>2017-01-04 17:07:21 +0000
commit5a0c3fd01e79feb1b35e554c38045ae0a88c429f (patch)
tree2e5df09b9a4a3ed8956190321886ace9101c399f
parented43b17201307bf1562624fbf6ddf93f4d0c93c3 (diff)
downloadale-5a0c3fd01e79feb1b35e554c38045ae0a88c429f.zip
Added hack linter for php (#239)
* added hack linter * updated docs for hack (hh_client) * naming
-rw-r--r--README.md2
-rw-r--r--ale_linters/php/hack.vim37
-rw-r--r--doc/ale.txt2
3 files changed, 39 insertions, 2 deletions
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 <https://github.com/zefei>
+" 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'