summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Emmott <fe@fb.com>2018-07-27 13:50:59 -0700
committerFred Emmott <fe@fb.com>2018-08-02 11:28:56 -0700
commit238201805dd23ea422a107b3170de7892335137b (patch)
treee214989c1a7dd048a0d162dc27d70a92479a62db
parent5f024eda093dcce62159a6f262ffb084ccce4e51 (diff)
downloadale-238201805dd23ea422a107b3170de7892335137b.zip
Split Hack out from PHP, modernize
fixes #1738 - Replace previous `hh_client` usage with LSP client - Add `HHAST` linter - Split Hack from PHP: Hack is increasingly diverging from PHP: - Hack tools do not understand PHP - Most PHP tools do not handle Hack code well (including vim's syntax highightling files) - http://github.com/hhvm/vim-hack now sets filetype to `hack`
-rw-r--r--README.md3
-rw-r--r--ale_linters/hack/hack.vim27
-rw-r--r--ale_linters/hack/hhast.vim34
-rw-r--r--ale_linters/php/hack.vim28
-rw-r--r--autoload/ale/fixers/hackfmt.vim8
-rw-r--r--doc/ale-hack.txt42
-rw-r--r--doc/ale-php.txt18
-rw-r--r--doc/ale.txt9
-rw-r--r--test/fixers/test_hackfmt_fixer_callback.vader14
-rw-r--r--test/hack_files/testfile.php4
10 files changed, 126 insertions, 61 deletions
diff --git a/README.md b/README.md
index bc7b1ee6..07de881d 100644
--- a/README.md
+++ b/README.md
@@ -126,6 +126,7 @@ formatting.
| GLSL | [glslang](https://github.com/KhronosGroup/glslang), [glslls](https://github.com/svenstaro/glsl-language-server) |
| Go | [gofmt](https://golang.org/cmd/gofmt/), [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports), [go vet](https://golang.org/cmd/vet/) !!, [golint](https://godoc.org/github.com/golang/lint), [gotype](https://godoc.org/golang.org/x/tools/cmd/gotype) !!, [gometalinter](https://github.com/alecthomas/gometalinter) !!, [go build](https://golang.org/cmd/go/) !!, [gosimple](https://github.com/dominikh/go-tools/tree/master/cmd/gosimple) !!, [staticcheck](https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck) !! |
| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) |
+| Hack | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/hhvm/tree/master/hphp/hack/hackfmt), [hhast](https://github.com/hhvm/hhast) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) |
@@ -152,7 +153,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, [ols](https://github.com/freebroccolo/ocaml-language-server) |
| 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 | [hack](http://hacklang.org/), [hackfmt](https://github.com/facebook/flow/tree/master/hack/hackfmt), [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/) |
| 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/hack/hack.vim b/ale_linters/hack/hack.vim
new file mode 100644
index 00000000..0253767a
--- /dev/null
+++ b/ale_linters/hack/hack.vim
@@ -0,0 +1,27 @@
+" Author: Fred Emmott <fe@fb.com>
+" Description: Hack support via `hack lsp`
+
+call ale#Set('hack_hhclient_executable', 'hh_client')
+
+function! ale_linters#hack#hack#GetProjectRoot(buffer) abort
+ let l:hhconfig = ale#path#FindNearestFile(a:buffer, '.hhconfig')
+ return !empty(l:hhconfig) ? fnamemodify(l:hhconfig, ':h') : ''
+endfunction
+
+function! ale_linters#hack#hack#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'hack_hhclient_executable')
+endfunction
+
+
+function! ale_linters#hack#hack#GetCommand(buffer) abort
+ let l:executable = ale_linters#hack#hack#GetExecutable(a:buffer)
+ return ale#Escape(l:executable).' lsp --from vim-ale'
+endfunction
+
+call ale#linter#Define('hack', {
+\ 'name': 'hack',
+\ 'lsp': 'stdio',
+\ 'executable_callback': 'ale_linters#hack#hack#GetExecutable',
+\ 'command_callback': 'ale_linters#hack#hack#GetCommand',
+\ 'project_root_callback': 'ale_linters#hack#hack#GetProjectRoot',
+\})
diff --git a/ale_linters/hack/hhast.vim b/ale_linters/hack/hhast.vim
new file mode 100644
index 00000000..8ff5a962
--- /dev/null
+++ b/ale_linters/hack/hhast.vim
@@ -0,0 +1,34 @@
+" Author: Fred Emmott <fe@fb.com>
+" Description: Hack support via `hhast lsp`
+
+call ale#Set('hack_hhast_executable', 'vendor/bin/hhast-lint')
+
+function! ale_linters#hack#hhast#GetProjectRoot(buffer) abort
+ let l:root = ale_linters#hack#hack#GetProjectRoot(a:buffer)
+ if empty(l:root)
+ return ''
+ endif
+ let l:hhast_config = findfile('hhast-lint.json', l:root)
+ return !empty(l:hhast_config) ? l:root : ''
+endfunction
+
+function! ale_linters#hack#hhast#GetExecutable(buffer) abort
+ let l:root = ale_linters#hack#hhast#GetProjectRoot(a:buffer)
+ let l:relative = ale#Var(a:buffer, 'hack_hhast_executable')
+ let l:absolute = findfile(l:relative, l:root)
+ return !empty(l:absolute) ? l:absolute : ''
+endfunction
+
+
+function! ale_linters#hack#hhast#GetCommand(buffer) abort
+ let l:executable = ale_linters#hack#hhast#GetExecutable(a:buffer)
+ return ale#Escape(l:executable).' --mode lsp --from vim-ale'
+endfunction
+
+call ale#linter#Define('hack', {
+\ 'name': 'hhast',
+\ 'lsp': 'stdio',
+\ 'executable_callback': 'ale_linters#hack#hhast#GetExecutable',
+\ 'command_callback': 'ale_linters#hack#hhast#GetCommand',
+\ 'project_root_callback': 'ale_linters#hack#hhast#GetProjectRoot',
+\})
diff --git a/ale_linters/php/hack.vim b/ale_linters/php/hack.vim
deleted file mode 100644
index 77d3a588..00000000
--- a/ale_linters/php/hack.vim
+++ /dev/null
@@ -1,28 +0,0 @@
-" Author: Zefei Xuan <https://github.com/zefei>
-" Description: Hack type checking (http://hacklang.org/)
-
-function! ale_linters#php#hack#Handle(buffer, lines) abort
- let l:pattern = '^\(.*\):\(\d\+\):\(\d\+\),\(\d\+\): \(.\+])\)$'
- let l:output = []
-
- for l:match in ale#util#GetMatches(a:lines, l:pattern)
- if a:buffer != bufnr(l:match[1])
- continue
- endif
-
- call add(l:output, {
- \ 'lnum': l:match[2] + 0,
- \ 'col': l:match[3] + 0,
- \ 'text': l:match[5],
- \})
- 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/autoload/ale/fixers/hackfmt.vim b/autoload/ale/fixers/hackfmt.vim
index b5bf0dc5..bf2d4f71 100644
--- a/autoload/ale/fixers/hackfmt.vim
+++ b/autoload/ale/fixers/hackfmt.vim
@@ -1,12 +1,12 @@
" Author: Sam Howie <samhowie@gmail.com>
" Description: Integration of hackfmt with ALE.
-call ale#Set('php_hackfmt_executable', 'hackfmt')
-call ale#Set('php_hackfmt_options', '')
+call ale#Set('hack_hackfmt_executable', 'hackfmt')
+call ale#Set('hack_hackfmt_options', '')
function! ale#fixers#hackfmt#Fix(buffer) abort
- let l:executable = ale#Var(a:buffer, 'php_hackfmt_executable')
- let l:options = ale#Var(a:buffer, 'php_hackfmt_options')
+ let l:executable = ale#Var(a:buffer, 'hack_hackfmt_executable')
+ let l:options = ale#Var(a:buffer, 'hack_hackfmt_options')
return {
\ 'command': ale#Escape(l:executable)
diff --git a/doc/ale-hack.txt b/doc/ale-hack.txt
new file mode 100644
index 00000000..0fbe5c45
--- /dev/null
+++ b/doc/ale-hack.txt
@@ -0,0 +1,42 @@
+===============================================================================
+ALE Hack Integration *ale-hack-options*
+
+===============================================================================
+hack *ale-hack-hack*
+
+g:ale_hack_hhclient_executable *g:ale_hack_hhclient_executable*
+ *b:ale_hack_hhclient_executable*
+
+ Type: |String|
+ Default: `'hh_client'`
+
+ This variable can be set to use a specific executable to interact with the
+ Hack typechecker.
+
+
+===============================================================================
+hackfmt *ale-hack-hackfmt*
+
+g:ale_hack_hackfmt_options *g:ale_hack_hackfmt_options*
+ *b:ale_hack_hackfmt_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be set to pass additional options to the hackfmt fixer.
+
+
+===============================================================================
+hhast *ale-hack-hhast*
+
+g:ale_hack_hhast_executable *g:ale_hack_hhast_executable*
+ *b:ale_hack_hhast_executable*
+
+ Type: |String|
+ Default: `'vendor/bin/hhast-lint'`
+
+ This variable can be set to use a specific executable to interact with the
+ Hack typechecker.
+
+
+===============================================================================
+ vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
diff --git a/doc/ale-php.txt b/doc/ale-php.txt
index 33796f7c..ba53db89 100644
--- a/doc/ale-php.txt
+++ b/doc/ale-php.txt
@@ -1,24 +1,6 @@
===============================================================================
ALE PHP Integration *ale-php-options*
-
-===============================================================================
-hack *ale-php-hack*
-
-There are no options for this linter.
-
-
-===============================================================================
-hackfmt *ale-php-hackfmt*
-
-g:ale_php_hackfmt_options *g:ale_php_hackfmt_options*
- *b:ale_php_hackfmt_options*
- Type: |String|
- Default: `''`
-
- This variable can be set to pass additional options to the hackfmt fixer.
-
-
===============================================================================
langserver *ale-php-langserver*
diff --git a/doc/ale.txt b/doc/ale.txt
index d4b51850..b60c3da0 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -96,6 +96,10 @@ CONTENTS *ale-contents*
eslint..............................|ale-graphql-eslint|
gqlint..............................|ale-graphql-gqlint|
prettier............................|ale-graphql-prettier|
+ hack..................................|ale-hack-options|
+ hack................................|ale-hack-hack|
+ hackfmt.............................|ale-hack-hackfmt|
+ hhast...............................|ale-hack-hhast|
handlebars............................|ale-handlebars-options|
ember-template-lint.................|ale-handlebars-embertemplatelint|
haskell...............................|ale-haskell-options|
@@ -171,8 +175,6 @@ CONTENTS *ale-contents*
perlcritic..........................|ale-perl-perlcritic|
perltidy............................|ale-perl-perltidy|
php...................................|ale-php-options|
- hack................................|ale-php-hack|
- hackfmt.............................|ale-php-hackfmt|
langserver..........................|ale-php-langserver|
phan................................|ale-php-phan|
phpcbf..............................|ale-php-phpcbf|
@@ -367,6 +369,7 @@ Notes:
* GLSL: glslang, `glslls`
* Go: `gofmt`, `goimports`, `go vet`!!, `golint`, `gotype`!!, `gometalinter`!!, `go build`!!, `gosimple`!!, `staticcheck`!!
* GraphQL: `eslint`, `gqlint`, `prettier`
+* Hack: `hack`, `hackfmt`, `hhast`
* Haml: `haml-lint`
* Handlebars: `ember-template-lint`
* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`
@@ -393,7 +396,7 @@ Notes:
* Objective-C++: `clang`
* OCaml: `merlin` (see |ale-ocaml-merlin|), `ols`
* Perl: `perl -c`, `perl-critic`, `perltidy`
-* PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`
+* PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`
* PO: `alex`!!, `msgfmt`, `proselint`, `write-good`
* Pod: `alex`!!, `proselint`, `write-good`
* Pony: `ponyc`
diff --git a/test/fixers/test_hackfmt_fixer_callback.vader b/test/fixers/test_hackfmt_fixer_callback.vader
index ed78fc85..d294c15e 100644
--- a/test/fixers/test_hackfmt_fixer_callback.vader
+++ b/test/fixers/test_hackfmt_fixer_callback.vader
@@ -1,10 +1,10 @@
Before:
- Save g:ale_php_hackfmt_executable
- Save g:ale_php_hackfmt_options
+ Save g:ale_hack_hackfmt_executable
+ Save g:ale_hack_hackfmt_options
" Use an invalid global executable, so we don't match it.
- let g:ale_php_hackfmt_executable = 'xxxinvalid'
- let g:ale_php_hackfmt_options = ''
+ let g:ale_hack_hackfmt_executable = 'xxxinvalid'
+ let g:ale_hack_hackfmt_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
@@ -14,7 +14,7 @@ After:
call ale#test#RestoreDirectory()
Execute(The hackfmt callback should return the correct default values):
- call ale#test#SetFilename('../hack_files/testfile.php')
+ call ale#test#SetFilename('../hack_files/testfile.hack')
AssertEqual
\ {
@@ -25,8 +25,8 @@ Execute(The hackfmt callback should return the correct default values):
\ ale#fixers#hackfmt#Fix(bufnr(''))
Execute(The hackfmt callback should include custom hackfmt options):
- let g:ale_php_hackfmt_options = "--some-option"
- call ale#test#SetFilename('../hack_files/testfile.php')
+ let g:ale_hack_hackfmt_options = "--some-option"
+ call ale#test#SetFilename('../hack_files/testfile.hack')
AssertEqual
\ {
diff --git a/test/hack_files/testfile.php b/test/hack_files/testfile.php
index e69de29b..313995d1 100644
--- a/test/hack_files/testfile.php
+++ b/test/hack_files/testfile.php
@@ -0,0 +1,4 @@
+<?hh // strict
+
+async function foo(): Awaitable<void> {
+}