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`
This commit is contained in:
Fred Emmott 2018-07-27 13:50:59 -07:00
parent 5f024eda09
commit 238201805d
No known key found for this signature in database
GPG Key ID: 06C22A9D789FCA28
10 changed files with 126 additions and 61 deletions

View File

@ -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) |

27
ale_linters/hack/hack.vim Normal file
View File

@ -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',
\})

View File

@ -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',
\})

View File

@ -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',
\})

View File

@ -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)

42
doc/ale-hack.txt Normal file
View File

@ -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:

View File

@ -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*

View File

@ -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`

View File

@ -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
\ {

View File

@ -0,0 +1,4 @@
<?hh // strict
async function foo(): Awaitable<void> {
}