diff --git a/README.md b/README.md index 7d154ce..adf4965 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 bbdcc43..5aa78ac 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 0000000..b5bf0dc --- /dev/null +++ b/autoload/ale/fixers/hackfmt.vim @@ -0,0 +1,18 @@ +" Author: Sam Howie +" 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 8756d60..f09c95f 100644 --- a/doc/ale-php.txt +++ b/doc/ale-php.txt @@ -8,6 +8,17 @@ 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 fb5a634..c90ab1d 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 0000000..ed78fc8 --- /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 0000000..e69de29