Merge pull request #1770 from fredemmott/hack

Split Hack out from PHP, modernize
This commit is contained in:
w0rp 2018-08-02 21:58:57 +01:00 committed by GitHub
commit 9ef266d050
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 131 additions and 62 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) (disabled by default; see `:help ale-integration-hack`) |
| 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), [hie](https://github.com/haskell/haskell-ide-engine) |
@ -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) |

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

@ -0,0 +1,22 @@
" Author: Fred Emmott <fe@fb.com>
" Description: Hack support via `hack lsp`
call ale#Set('hack_hack_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_hack_executable')
endfunction
call ale#linter#Define('hack', {
\ 'name': 'hack',
\ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#hack#hack#GetExecutable',
\ 'command': '%e lsp --from vim-ale',
\ 'project_root_callback': 'ale_linters#hack#hack#GetProjectRoot',
\})

View File

@ -0,0 +1,35 @@
" 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
" Find the hack root, then figure out if it's also an HHAST root.
" Don't try to use lint configurations from vendor/foo/bar/hhast-lint.json
let l:hhconfig = ale#path#FindNearestFile(a:buffer, '.hhconfig')
if empty(l:hhconfig)
return ''
endif
let l:root = fnamemodify(l:hhconfig, ':h')
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
call ale#linter#Define('hack', {
\ 'name': 'hhast',
\ 'lsp': 'stdio',
\ 'executable_callback': 'ale_linters#hack#hhast#GetExecutable',
\ 'command': '%e --mode lsp --from vim-ale',
\ '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

@ -157,7 +157,7 @@ let s:default_registry = {
\ },
\ 'hackfmt': {
\ 'function': 'ale#fixers#hackfmt#Fix',
\ 'suggested_filetypes': ['php'],
\ 'suggested_filetypes': ['hack'],
\ 'description': 'Fix Hack files with hackfmt.',
\ },
\ 'hfmt': {

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)

View File

@ -26,11 +26,13 @@ let s:default_ale_linter_aliases = {
"
" Only cargo is enabled for Rust by default.
" rpmlint is disabled by default because it can result in code execution.
" hhast is disabled by default because it executes code in the project root.
"
" NOTE: Update the g:ale_linters documentation when modifying this.
let s:default_ale_linters = {
\ 'csh': ['shell'],
\ 'go': ['gofmt', 'golint', 'go vet'],
\ 'hack': ['hack'],
\ 'help': [],
\ 'perl': ['perlcritic'],
\ 'python': ['flake8', 'mypy', 'pylint'],

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

@ -0,0 +1,51 @@
===============================================================================
ALE Hack Integration *ale-hack-options*
*ale-integration-hack*
HHAST is disabled by default, as it executes code in the project root.
Currently linters must be enabled globally. HHAST can be enabled with:
>
let g:ale_linters = {'hack': ['hack', 'hhast']}
<
===============================================================================
hack *ale-hack-hack*
g:ale_hack_hack_executable *g:ale_hack_hack_executable*
*b:ale_hack_hack_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|
@ -172,8 +176,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|
@ -368,6 +370,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`, `hie`
@ -394,7 +397,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`
@ -1212,6 +1215,7 @@ g:ale_linters *g:ale_linters*
{
\ 'csh': ['shell'],
\ 'go': ['gofmt', 'golint', 'go vet'],
\ 'hack': ['hack'],
\ 'help': [],
\ 'perl': ['perlcritic'],
\ 'python': ['flake8', 'mypy', 'pylint'],

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