Add hackfmt fixer

This commit is contained in:
Sam Howie 2017-10-26 16:11:02 -07:00 committed by Sam Howie
parent 73b8181ce6
commit 36898436b5
7 changed files with 74 additions and 2 deletions

View File

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

View File

@ -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'],

View File

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

View File

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

View File

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

View File

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

View File