diff options
author | w0rp <devw0rp@gmail.com> | 2017-11-21 13:38:27 +0000 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-11-21 13:38:33 +0000 |
commit | ac7f69063db30edfad14fac19b9d06be487885b1 (patch) | |
tree | a54c60e3c5bd05d10883d0e9a117e36a9f81801e /ale_linters/chef | |
parent | ce2986cfa502849e552b126e9df9d090275f98e2 (diff) | |
download | ale-ac7f69063db30edfad14fac19b9d06be487885b1.zip |
#1151 - Overhaul the foodcritic linter for checking files on disk
Diffstat (limited to 'ale_linters/chef')
-rw-r--r-- | ale_linters/chef/foodcritic.vim | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/ale_linters/chef/foodcritic.vim b/ale_linters/chef/foodcritic.vim index 079e3041..2c28246c 100644 --- a/ale_linters/chef/foodcritic.vim +++ b/ale_linters/chef/foodcritic.vim @@ -1,24 +1,37 @@ " Author: Edward Larkey <edwlarkey@mac.com> " Author: Jose Junior <jose.junior@gmail.com> +" Author: w0rp <devw0rp@gmail.com> " Description: This file adds the foodcritic linter for Chef files. -" Support options! -let g:ale_chef_foodcritic_options = get(g:, 'ale_chef_foodcritic_options', '') -let g:ale_chef_foodcritic_executable = get(g:, 'ale_chef_foodcritic_executable', 'foodcritic') +call ale#Set('chef_foodcritic_executable', 'foodcritic') +call ale#Set('chef_foodcritic_options', '') + +function! ale_linters#chef#foodcritic#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'chef_foodcritic_executable') +endfunction + +function! ale_linters#chef#foodcritic#GetCommand(buffer) abort + let l:executable = ale_linters#chef#foodcritic#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'chef_foodcritic_options') + + return ale#Escape(l:executable) + \ . (!empty(l:options) ? ' ' . escape(l:options, '~') : '') + \ . ' %s' +endfunction function! ale_linters#chef#foodcritic#Handle(buffer, lines) abort " Matches patterns line the following: " " FC002: Avoid string interpolation where not required: httpd.rb:13 - let l:pattern = '^\(.\+:\s.\+\):\s\(.\+\):\(\d\+\)$' + let l:pattern = '\v([^:]+): (.+): ([a-zA-Z]?:?[^:]+):(\d+)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) - let l:text = l:match[1] - call add(l:output, { - \ 'lnum': l:match[3] + 0, - \ 'text': l:text, + \ 'code': l:match[1], + \ 'text': l:match[2], + \ 'filename': l:match[3], + \ 'lnum': l:match[4] + 0, \ 'type': 'W', \}) endfor @@ -26,17 +39,10 @@ function! ale_linters#chef#foodcritic#Handle(buffer, lines) abort return l:output endfunction -function! ale_linters#chef#foodcritic#GetCommand(buffer) abort - return printf('%s %s %%t', - \ ale#Var(a:buffer, 'chef_foodcritic_executable'), - \ escape(ale#Var(a:buffer, 'chef_foodcritic_options'), '~') - \) -endfunction - - call ale#linter#Define('chef', { \ 'name': 'foodcritic', -\ 'executable': 'foodcritic', +\ 'executable_callback': 'ale_linters#chef#foodcritic#GetExecutable', \ 'command_callback': 'ale_linters#chef#foodcritic#GetCommand', \ 'callback': 'ale_linters#chef#foodcritic#Handle', +\ 'lint_file': 1, \}) |