summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Weyl <chris@weyl.io>2017-06-29 07:08:51 -0500
committerw0rp <w0rp@users.noreply.github.com>2017-06-29 13:08:51 +0100
commit3f1cab3e7ee3d7e90062e32e7d8c9557077c08a8 (patch)
treea4871ee9fdd2ef91a2c825e26e12b12d25965f86
parent411c6b5e9f8ecf367aaf487adf4e380251c44fa1 (diff)
downloadale-3f1cab3e7ee3d7e90062e32e7d8c9557077c08a8.zip
Add profile, other options to the perlcritic linter (#675)
* Add profile, other options to the perlcritic linter
-rw-r--r--ale_linters/perl/perlcritic.vim51
-rw-r--r--doc/ale-perl.txt31
-rw-r--r--test/test_perlcritic_linter.vader62
-rw-r--r--test/test_perlcritic_showrules.vader16
4 files changed, 137 insertions, 23 deletions
diff --git a/ale_linters/perl/perlcritic.vim b/ale_linters/perl/perlcritic.vim
index 189a9ce3..a9e8f117 100644
--- a/ale_linters/perl/perlcritic.vim
+++ b/ale_linters/perl/perlcritic.vim
@@ -1,17 +1,54 @@
-" Author: Vincent Lequertier <https://github.com/SkySymbol>
+" Author: Vincent Lequertier <https://github.com/SkySymbol>, Chris Weyl <cweyl@alumni.drew.edu>
" Description: This file adds support for checking perl with perl critic
-if !exists('g:ale_perl_perlcritic_showrules')
- let g:ale_perl_perlcritic_showrules = 0
-endif
+let g:ale_perl_perlcritic_executable =
+\ get(g:, 'ale_perl_perlcritic_executable', 'perlcritic')
+
+let g:ale_perl_perlcritic_profile =
+\ get(g:, 'ale_perl_perlcritic_profile', '.perlcriticrc')
+
+let g:ale_perl_perlcritic_options =
+\ get(g:, 'ale_perl_perlcritic_options', '')
+
+let g:ale_perl_perlcritic_showrules =
+\ get(g:, 'ale_perl_perlcritic_showrules', 0)
+
+function! ale_linters#perl#perlcritic#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'perl_perlcritic_executable')
+endfunction
+
+function! ale_linters#perl#perlcritic#GetProfile(buffer) abort
+
+ " first see if we've been overridden
+ let l:profile = ale#Var(a:buffer, 'perl_perlcritic_profile')
+ if l:profile ==? ''
+ return ''
+ endif
+
+ " otherwise, iterate upwards to find it
+ return ale#path#FindNearestFile(a:buffer, l:profile)
+endfunction
function! ale_linters#perl#perlcritic#GetCommand(buffer) abort
let l:critic_verbosity = '%l:%c %m\n'
- if g:ale_perl_perlcritic_showrules
+ if ale#Var(a:buffer, 'perl_perlcritic_showrules')
let l:critic_verbosity = '%l:%c %m [%p]\n'
endif
- return "perlcritic --verbose '". l:critic_verbosity . "' --nocolor"
+ let l:profile = ale_linters#perl#perlcritic#GetProfile(a:buffer)
+ let l:options = ale#Var(a:buffer, 'perl_perlcritic_options')
+
+ let l:command = ale#Escape(ale_linters#perl#perlcritic#GetExecutable(a:buffer))
+ \ . " --verbose '". l:critic_verbosity . "' --nocolor"
+
+ if l:profile !=? ''
+ let l:command .= ' --profile ' . ale#Escape(l:profile)
+ endif
+ if l:options !=? ''
+ let l:command .= ' ' . l:options
+ endif
+
+ return l:command
endfunction
@@ -32,8 +69,8 @@ endfunction
call ale#linter#Define('perl', {
\ 'name': 'perlcritic',
-\ 'executable': 'perlcritic',
\ 'output_stream': 'stdout',
+\ 'executable_callback': 'ale_linters#perl#perlcritic#GetExecutable',
\ 'command_callback': 'ale_linters#perl#perlcritic#GetCommand',
\ 'callback': 'ale_linters#perl#perlcritic#Handle',
\})
diff --git a/doc/ale-perl.txt b/doc/ale-perl.txt
index 8349dff7..4425bda5 100644
--- a/doc/ale-perl.txt
+++ b/doc/ale-perl.txt
@@ -25,6 +25,37 @@ g:ale_perl_perl_options *g:ale_perl_perl_options*
-------------------------------------------------------------------------------
perlcritic *ale-perl-perlcritic*
+g:ale_perl_perlcritic_executable *g:ale_perl_perlcritic_executable*
+ *b:ale_perl_perlcritic_executable*
+ Type: |String|
+ Default: `'perlcritic'`
+
+ This variable can be changed to modify the perlcritic executable used for
+ linting perl.
+
+
+g:ale_perl_perlcritic_profile *g:ale_perl_perlcritic_profile*
+ *b:ale_perl_perlcritic_profile*
+ Type: |String|
+ Default: `'.perlcriticrc'`
+
+ This variable can be changed to modify the perlcritic profile used for
+ linting perl. The current directory is checked for the file, then the
+ parent directory, etc, until it finds one. If no matching file is found, no
+ profile is passed to perlcritic.
+
+ Set to an empty string to disable using a profile.
+
+
+g:ale_perl_perlcritic_options *g:ale_perl_perlcritic_options*
+ *b:ale_perl_perlcritic_options*
+ Type: |String|
+ Default: `''`
+
+ This variable can be changed to supply additional command-line arguments to
+ the perlcritic invocation.
+
+
g:ale_perl_perlcritic_showrules *g:ale_perl_perlcritic_showrules*
Type: |Number|
diff --git a/test/test_perlcritic_linter.vader b/test/test_perlcritic_linter.vader
new file mode 100644
index 00000000..8b7cf1a4
--- /dev/null
+++ b/test/test_perlcritic_linter.vader
@@ -0,0 +1,62 @@
+" NOTE: We use the 'b:' forms below to ensure that we're properly using
+" ale#Var()
+
+Given perl:
+ #!/usr/bin/env perl
+ use v5.10;
+ say 'Hi there!';
+
+
+Before:
+ Save g:ale_perl_perlcritic_profile
+ Save g:ale_perl_perlcritic_options
+ Save g:ale_perl_perlcritic_executable
+ Save g:ale_perl_perlcritic_showrules
+ silent! unlet g:ale_perl_perlcritic_options
+ silent! unlet g:ale_perl_perlcritic_executable
+ silent! unlet g:ale_perl_perlcritic_showrules
+ let g:ale_perl_perlcritic_profile = ''
+
+ " enable loading inside test container
+ silent! cd /testplugin
+ source ale_linters/perl/perlcritic.vim
+
+
+After:
+ Restore
+ silent! unlet b:ale_perl_perlcritic_profile
+ silent! unlet b:ale_perl_perlcritic_options
+ silent! unlet b:ale_perl_perlcritic_executable
+ silent! unlet b:ale_perl_perlcritic_showrules
+
+
+Execute(no g:ale_perl_perlcritic_showrules):
+ let b:ale_perl_perlcritic_showrules = 0
+
+ AssertEqual
+ \ "'perlcritic' --verbose '". '%l:%c %m\n' . "' --nocolor",
+ \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
+
+
+Execute(yes g:ale_perl_perlcritic_showrules):
+ let b:ale_perl_perlcritic_showrules = 1
+
+ AssertEqual
+ \ "'perlcritic' --verbose '". '%l:%c %m [%p]\n' . "' --nocolor",
+ \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
+
+
+Execute(set g:ale_perl_perlcritic_profile):
+ let b:ale_perl_perlcritic_profile = 'README.md'
+
+ Assert
+ \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
+ \ =~# "--profile '.*/README.md'"
+
+
+Execute(g:ale_perl_perlcritic_options):
+ let b:ale_perl_perlcritic_options = 'beep boop'
+
+ AssertEqual
+ \ "'perlcritic' --verbose '". '%l:%c %m\n' . "' --nocolor beep boop",
+ \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
diff --git a/test/test_perlcritic_showrules.vader b/test/test_perlcritic_showrules.vader
deleted file mode 100644
index 52089080..00000000
--- a/test/test_perlcritic_showrules.vader
+++ /dev/null
@@ -1,16 +0,0 @@
-Execute(no g:ale_perl_perlcritic_showrules):
- silent noautocmd new testfile.pl
-
- let g:ale_perl_perlcritic_showrules = 0
-
- AssertEqual
- \ "perlcritic --verbose '". '%l:%c %m\n' . "' --nocolor",
- \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
-
- let g:ale_perl_perlcritic_showrules = 1
-
- AssertEqual
- \ "perlcritic --verbose '". '%l:%c %m [%p]\n' . "' --nocolor",
- \ ale_linters#perl#perlcritic#GetCommand(bufnr(''))
-
- :q