summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-04-22 18:02:19 +0100
committerGitHub <noreply@github.com>2018-04-22 18:02:19 +0100
commit5a365e792693373413984a7eae2d64f7d92c1238 (patch)
tree78a1d829122f1dc5a812bc457a13fb2c9b94c30d
parent87ad4dfbe78665029521667afb2f159f3865523b (diff)
parent498be478be6b57cff90f4d2889e87bf0067d6dec (diff)
downloadale-5a365e792693373413984a7eae2d64f7d92c1238.zip
Merge pull request #1517 from kfly8/perltidy-fixer
Added perltidy fixer
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/perltidy.vim18
-rw-r--r--doc/ale-perl.txt9
-rw-r--r--doc/ale.txt3
-rw-r--r--test/fixers/test_perltidy_fixer_callback.vader40
6 files changed, 75 insertions, 2 deletions
diff --git a/README.md b/README.md
index 13631186..876ee4cd 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 d12cf0d4..7e45e6ad 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 00000000..a55a572b
--- /dev/null
+++ b/autoload/ale/fixers/perltidy.vim
@@ -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
diff --git a/doc/ale-perl.txt b/doc/ale-perl.txt
index 0a4adfff..761c2735 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 929fcf55..1f988e7d 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 00000000..c7430bfa
--- /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(''))