From 3f1cab3e7ee3d7e90062e32e7d8c9557077c08a8 Mon Sep 17 00:00:00 2001 From: Chris Weyl Date: Thu, 29 Jun 2017 07:08:51 -0500 Subject: Add profile, other options to the perlcritic linter (#675) * Add profile, other options to the perlcritic linter --- ale_linters/perl/perlcritic.vim | 51 +++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'ale_linters') 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 +" Author: Vincent Lequertier , Chris Weyl " 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', \}) -- cgit v1.2.3