2018-03-31 10:55:20 -04:00
|
|
|
" 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.
|
|
|
|
|
|
|
|
call ale#Set('chef_foodcritic_executable', 'foodcritic')
|
|
|
|
call ale#Set('chef_foodcritic_options', '')
|
|
|
|
|
|
|
|
function! ale_linters#chef#foodcritic#GetCommand(buffer) abort
|
|
|
|
let l:options = ale#Var(a:buffer, 'chef_foodcritic_options')
|
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
return '%e' . ale#Pad(escape(l:options, '~')) . ' %s'
|
2018-03-31 10:55:20 -04:00
|
|
|
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 = '\v([^:]+): (.+): ([a-zA-Z]?:?[^:]+):(\d+)$'
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'code': l:match[1],
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'filename': l:match[3],
|
|
|
|
\ 'lnum': l:match[4] + 0,
|
|
|
|
\ 'type': 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('chef', {
|
|
|
|
\ 'name': 'foodcritic',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'chef_foodcritic_executable')},
|
|
|
|
\ 'command': function('ale_linters#chef#foodcritic#GetCommand'),
|
2018-03-31 10:55:20 -04:00
|
|
|
\ 'callback': 'ale_linters#chef#foodcritic#Handle',
|
|
|
|
\ 'lint_file': 1,
|
|
|
|
\})
|