summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/hackfmt.vim18
-rw-r--r--doc/ale-php.txt11
-rw-r--r--doc/ale.txt3
-rw-r--r--test/fixers/test_hackfmt_fixer_callback.vader37
-rw-r--r--test/hack_files/testfile.php0
7 files changed, 74 insertions, 2 deletions
diff --git a/README.md b/README.md
index 7d154ce1..adf49655 100644
--- a/README.md
+++ b/README.md
@@ -120,7 +120,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 |
| Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic) |
-| PHP | [hack](http://hacklang.org/), [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 | [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) |
| Pod | [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) |
| Pug | [pug-lint](https://github.com/pugjs/pug-lint) |
| Puppet | [puppet](https://puppet.com), [puppet-lint](https://puppet-lint.com) |
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index bbdcc430..5aa78ac5 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -117,6 +117,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['rust'],
\ 'description': 'Fix Rust files with Rustfmt.',
\ },
+\ 'hackfmt': {
+\ 'function': 'ale#fixers#hackfmt#Fix',
+\ 'suggested_filetypes': ['php'],
+\ 'description': 'Fix Hack files with hackfmt.',
+\ },
\ 'hfmt': {
\ 'function': 'ale#fixers#hfmt#Fix',
\ 'suggested_filetypes': ['haskell'],
diff --git a/autoload/ale/fixers/hackfmt.vim b/autoload/ale/fixers/hackfmt.vim
new file mode 100644
index 00000000..b5bf0dc5
--- /dev/null
+++ b/autoload/ale/fixers/hackfmt.vim
@@ -0,0 +1,18 @@
+" 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', '')
+
+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')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ' -i'
+ \ . (empty(l:options) ? '' : ' ' . l:options)
+ \ . ' %t',
+ \ 'read_temporary_file': 1,
+ \}
+endfunction
diff --git a/doc/ale-php.txt b/doc/ale-php.txt
index 8756d60e..f09c95fd 100644
--- a/doc/ale-php.txt
+++ b/doc/ale-php.txt
@@ -9,6 +9,17 @@ 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*
g:ale_php_langserver_executable *g:ale_php_langserver_executable*
diff --git a/doc/ale.txt b/doc/ale.txt
index fb5a6348..c90ab1d7 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -125,6 +125,7 @@ CONTENTS *ale-contents*
perlcritic..........................|ale-perl-perlcritic|
php...................................|ale-php-options|
hack................................|ale-php-hack|
+ hackfmt.............................|ale-php-hackfmt|
langserver..........................|ale-php-langserver|
phan................................|ale-php-phan|
phpcbf..............................|ale-php-phpcbf|
@@ -301,7 +302,7 @@ Notes:
* Objective-C++: `clang`
* OCaml: `merlin` (see |ale-ocaml-merlin|)
* Perl: `perl -c`, `perl-critic`
-* PHP: `hack`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`
+* PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`
* Pod: `proselint`, `write-good`
* Pug: `pug-lint`
* Puppet: `puppet`, `puppet-lint`
diff --git a/test/fixers/test_hackfmt_fixer_callback.vader b/test/fixers/test_hackfmt_fixer_callback.vader
new file mode 100644
index 00000000..ed78fc85
--- /dev/null
+++ b/test/fixers/test_hackfmt_fixer_callback.vader
@@ -0,0 +1,37 @@
+Before:
+ Save g:ale_php_hackfmt_executable
+ Save g:ale_php_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 = ''
+
+ call ale#test#SetDirectory('/testplugin/test/fixers')
+
+After:
+ Restore
+
+ call ale#test#RestoreDirectory()
+
+Execute(The hackfmt callback should return the correct default values):
+ call ale#test#SetFilename('../hack_files/testfile.php')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' -i %t',
+ \ },
+ \ 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')
+
+ AssertEqual
+ \ {
+ \ 'read_temporary_file': 1,
+ \ 'command': ale#Escape('xxxinvalid')
+ \ . ' -i --some-option %t',
+ \ },
+ \ ale#fixers#hackfmt#Fix(bufnr(''))
diff --git a/test/hack_files/testfile.php b/test/hack_files/testfile.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/hack_files/testfile.php