mirror of https://github.com/dense-analysis/ale
Perlcritic column number and rule names (#640)
* Add column number to perlcritic linting output This returns the column number of the perlcritic error so that ale can show the column in addition to the line where perlcritic found an error. * Add perlcritic configuration for rule names This adds a configuration setting so that the name of the perlcritic rule is shown [Rule::Name] after the error message. This is useful to lookup the rule failure. * Add a vader test for perlcritic#GetCommand
This commit is contained in:
parent
64ad51048d
commit
99263bdda4
|
@ -1,14 +1,29 @@
|
||||||
" Author: Vincent Lequertier <https://github.com/SkySymbol>
|
" Author: Vincent Lequertier <https://github.com/SkySymbol>
|
||||||
" Description: This file adds support for checking perl with perl critic
|
" 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
|
||||||
|
|
||||||
|
function! ale_linters#perl#perlcritic#GetCommand(buffer) abort
|
||||||
|
let l:critic_verbosity = '%l:%c %m\n'
|
||||||
|
if g:ale_perl_perlcritic_showrules
|
||||||
|
let l:critic_verbosity = '%l:%c %m [%p]\n'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return "perlcritic --verbose '". l:critic_verbosity . "' --nocolor"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
function! ale_linters#perl#perlcritic#Handle(buffer, lines) abort
|
function! ale_linters#perl#perlcritic#Handle(buffer, lines) abort
|
||||||
let l:pattern = '\(.\+\) at \(.\+\) line \(\d\+\)'
|
let l:pattern = '\(\d\+\):\(\d\+\) \(.\+\)'
|
||||||
let l:output = []
|
let l:output = []
|
||||||
|
|
||||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||||
call add(l:output, {
|
call add(l:output, {
|
||||||
\ 'text': l:match[1],
|
\ 'lnum': l:match[1],
|
||||||
\ 'lnum': l:match[3],
|
\ 'col': l:match[2],
|
||||||
|
\ 'text': l:match[3],
|
||||||
\})
|
\})
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
@ -19,6 +34,6 @@ call ale#linter#Define('perl', {
|
||||||
\ 'name': 'perlcritic',
|
\ 'name': 'perlcritic',
|
||||||
\ 'executable': 'perlcritic',
|
\ 'executable': 'perlcritic',
|
||||||
\ 'output_stream': 'stdout',
|
\ 'output_stream': 'stdout',
|
||||||
\ 'command': 'perlcritic --verbose 3 --nocolor',
|
\ 'command_callback': 'ale_linters#perl#perlcritic#GetCommand',
|
||||||
\ 'callback': 'ale_linters#perl#perlcritic#Handle',
|
\ 'callback': 'ale_linters#perl#perlcritic#Handle',
|
||||||
\})
|
\})
|
||||||
|
|
|
@ -22,5 +22,17 @@ g:ale_perl_perl_options *g:ale_perl_perl_options*
|
||||||
invocation.
|
invocation.
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
perlcritic *ale-perl-perlcritic*
|
||||||
|
|
||||||
|
g:ale_perl_perlcritic_showrules *g:ale_perl_perlcritic_showrules*
|
||||||
|
|
||||||
|
Type: |Number|
|
||||||
|
Default: 0
|
||||||
|
|
||||||
|
Controls whether perlcritic rule names are shown after the error message.
|
||||||
|
Defaults to off to reduce length of message.
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||||
|
|
|
@ -63,6 +63,7 @@ CONTENTS *ale-contents*
|
||||||
merlin..............................|ale-ocaml-merlin|
|
merlin..............................|ale-ocaml-merlin|
|
||||||
perl..................................|ale-perl-options|
|
perl..................................|ale-perl-options|
|
||||||
perl................................|ale-perl-perl|
|
perl................................|ale-perl-perl|
|
||||||
|
perlcritic..........................|ale-perl-perlcritic|
|
||||||
php...................................|ale-php-options|
|
php...................................|ale-php-options|
|
||||||
phpcs...............................|ale-php-phpcs|
|
phpcs...............................|ale-php-phpcs|
|
||||||
phpmd...............................|ale-php-phpmd|
|
phpmd...............................|ale-php-phpmd|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
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
|
Loading…
Reference in New Issue