diff --git a/README.md b/README.md index 5a416ac..5fc0f5f 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ formatting. | Objective-C | [clang](http://clang.llvm.org/) | | 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) | +| 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/) | | 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) | diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index d12cf0d..7e45e6a 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -185,6 +185,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['json'], \ 'description': 'Fix JSON files with jq.', \ }, +\ 'perltidy': { +\ 'function': 'ale#fixers#perltidy#Fix', +\ 'suggested_filetypes': ['perl'], +\ 'description': 'Fix Perl files with perltidy.', +\ }, \} " Reset the function registry to the default entries. diff --git a/autoload/ale/fixers/perltidy.vim b/autoload/ale/fixers/perltidy.vim new file mode 100644 index 0000000..a55a572 --- /dev/null +++ b/autoload/ale/fixers/perltidy.vim @@ -0,0 +1,18 @@ +" Author: kfly8 +" Description: Integration of perltidy with ALE. + +call ale#Set('perl_perltidy_executable', 'perltidy') +call ale#Set('perl_perltidy_options', '') + +function! ale#fixers#perltidy#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'perl_perltidy_executable') + let l:options = ale#Var(a:buffer, 'perl_perltidy_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' -b' + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' %t', + \ 'read_temporary_file': 1, + \} +endfunction diff --git a/doc/ale-perl.txt b/doc/ale-perl.txt index 0a4adff..761c273 100644 --- a/doc/ale-perl.txt +++ b/doc/ale-perl.txt @@ -76,7 +76,16 @@ g:ale_perl_perlcritic_showrules *g:ale_perl_perlcritic_showrules* Controls whether perlcritic rule names are shown after the error message. Defaults to off to reduce length of message. +=============================================================================== +perltidy *ale-perl-perltidy* +g:ale_perl_perltidy_options *g:ale_perl_perltidy_options* + *b:ale_perl_perltidy_options* + Type: |String| + Default: `''` + + This variable can be changed to alter the command-line arguments to + the perltidy invocation. =============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale.txt b/doc/ale.txt index 929fcf5..1f988e7 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -156,6 +156,7 @@ CONTENTS *ale-contents* perl..................................|ale-perl-options| perl................................|ale-perl-perl| perlcritic..........................|ale-perl-perlcritic| + perltidy............................|ale-perl-perltidy| php...................................|ale-php-options| hack................................|ale-php-hack| hackfmt.............................|ale-php-hackfmt| @@ -364,7 +365,7 @@ Notes: * Objective-C: `clang` * Objective-C++: `clang` * OCaml: `merlin` (see |ale-ocaml-merlin|), `ols` -* Perl: `perl -c`, `perl-critic` +* Perl: `perl -c`, `perl-critic`, `perltidy` * PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good` diff --git a/test/fixers/test_perltidy_fixer_callback.vader b/test/fixers/test_perltidy_fixer_callback.vader new file mode 100644 index 0000000..c7430bf --- /dev/null +++ b/test/fixers/test_perltidy_fixer_callback.vader @@ -0,0 +1,40 @@ +Before: + Save g:ale_perl_perltidy_executable + Save g:ale_perl_perltidy_options + + " Use an invalid global executable, so we don't match it. + let g:ale_perl_perltidy_executable = 'xxxinvalid' + let g:ale_perl_perltidy_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The perltidy callback should return the correct default values): + call ale#test#SetFilename('../pl_files/testfile.pl') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' -b' + \ . ' %t', + \ }, + \ ale#fixers#perltidy#Fix(bufnr('')) + +Execute(The perltidy callback should include custom perltidy options): + let g:ale_perl_perltidy_options = "-r '(a) -> a'" + call ale#test#SetFilename('../pl_files/testfile.pl') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' -b' + \ . ' ' . g:ale_perl_perltidy_options + \ . ' %t', + \ }, + \ ale#fixers#perltidy#Fix(bufnr(''))