summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-08-02 21:58:57 +0100
committerGitHub <noreply@github.com>2018-08-02 21:58:57 +0100
commit9ef266d050d698c3ed3be3456ce6a5da5755d5ef (patch)
tree6e3d82e5df785173b6f067ddfd4b32a75fb9cef6
parent94270402cb5c28017061c383c40dff89008d0125 (diff)
parenta728f074f727ad9aac0d6947f7b81d26078c0fb6 (diff)
downloadale-9ef266d050d698c3ed3be3456ce6a5da5755d5ef.zip
Merge pull request #1770 from fredemmott/hack
Split Hack out from PHP, modernize
-rw-r--r--README.md3
-rw-r--r--ale_linters/hack/hack.vim22
-rw-r--r--ale_linters/hack/hhast.vim35
-rw-r--r--ale_linters/php/hack.vim28
-rw-r--r--autoload/ale/fix/registry.vim2
-rw-r--r--autoload/ale/fixers/hackfmt.vim8
-rw-r--r--autoload/ale/linter.vim2
-rw-r--r--doc/ale-hack.txt51
-rw-r--r--doc/ale-php.txt18
-rw-r--r--doc/ale.txt10
-rw-r--r--test/fixers/test_hackfmt_fixer_callback.vader14
-rw-r--r--test/hack_files/testfile.php0
12 files changed, 131 insertions, 62 deletions
diff --git a/README.md b/README.md
index 209370f0..210c4bfa 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) (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) |
diff --git a/ale_linters/hack/hack.vim b/ale_linters/hack/hack.vim
new file mode 100644
index 00000000..aea428cc
--- /dev/null
+++ b/ale_linters/hack/hack.vim
@@ -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',
+\})
diff --git a/ale_linters/hack/hhast.vim b/ale_linters/hack/hhast.vim
new file mode 100644
index 00000000..5070dc4e
--- /dev/null
+++ b/ale_linters/hack/hhast.vim
@@ -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',
+\})
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/fix/registry.vim b/autoload/ale/fix/registry.vim
index dc34e4c5..e60d67b6 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -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': {
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/autoload/ale/linter.vim b/autoload/ale/linter.vim
index 683d506a..ab86d77e 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -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'],
diff --git a/doc/ale-hack.txt b/doc/ale-hack.txt
new file mode 100644
index 00000000..4776b8cf
--- /dev/null
+++ b/doc/ale-hack.txt
@@ -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:
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 5006e472..db060a2b 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|
@@ -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'],
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
deleted file mode 100644
index e69de29b..00000000
--- a/test/hack_files/testfile.php
+++ /dev/null