Merge pull request #1517 from kfly8/perltidy-fixer

Added perltidy fixer
This commit is contained in:
w0rp 2018-04-22 18:02:19 +01:00 committed by GitHub
commit 5a365e7926
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 75 additions and 2 deletions

View file

@ -132,7 +132,7 @@ formatting.
| Objective-C | [clang](http://clang.llvm.org/) | | Objective-C | [clang](http://clang.llvm.org/) |
| 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) | | 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/) | | 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) | | 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) | | Pod | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) |

View file

@ -185,6 +185,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['json'], \ 'suggested_filetypes': ['json'],
\ 'description': 'Fix JSON files with jq.', \ '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. " Reset the function registry to the default entries.

View file

@ -0,0 +1,18 @@
" Author: kfly8 <kentafly88@gmail.com>
" 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

View file

@ -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. Controls whether perlcritic rule names are shown after the error message.
Defaults to off to reduce length of 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: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -156,6 +156,7 @@ CONTENTS *ale-contents*
perl..................................|ale-perl-options| perl..................................|ale-perl-options|
perl................................|ale-perl-perl| perl................................|ale-perl-perl|
perlcritic..........................|ale-perl-perlcritic| perlcritic..........................|ale-perl-perlcritic|
perltidy............................|ale-perl-perltidy|
php...................................|ale-php-options| php...................................|ale-php-options|
hack................................|ale-php-hack| hack................................|ale-php-hack|
hackfmt.............................|ale-php-hackfmt| hackfmt.............................|ale-php-hackfmt|
@ -364,7 +365,7 @@ Notes:
* Objective-C: `clang` * Objective-C: `clang`
* Objective-C++: `clang` * Objective-C++: `clang`
* OCaml: `merlin` (see |ale-ocaml-merlin|), `ols` * 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` * PHP: `hack`, `hackfmt`, `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`
* PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good`
* Pod: `alex`!!, `proselint`, `write-good` * Pod: `alex`!!, `proselint`, `write-good`

View file

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