2016-10-30 14:23:32 -04:00
|
|
|
" Author: Edward Larkey <edwlarkey@mac.com>
|
2017-04-05 13:21:47 -04:00
|
|
|
" Author: Jose Junior <jose.junior@gmail.com>
|
2017-11-21 08:38:27 -05:00
|
|
|
" Author: w0rp <devw0rp@gmail.com>
|
2016-10-30 14:23:32 -04:00
|
|
|
" Description: This file adds the foodcritic linter for Chef files.
|
|
|
|
|
2017-11-21 08:38:27 -05:00
|
|
|
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
|
2017-04-05 13:21:47 -04:00
|
|
|
|
2017-01-22 09:54:57 -05:00
|
|
|
function! ale_linters#chef#foodcritic#Handle(buffer, lines) abort
|
2016-10-30 14:23:32 -04:00
|
|
|
" Matches patterns line the following:
|
|
|
|
"
|
|
|
|
" FC002: Avoid string interpolation where not required: httpd.rb:13
|
2017-11-21 08:38:27 -05:00
|
|
|
let l:pattern = '\v([^:]+): (.+): ([a-zA-Z]?:?[^:]+):(\d+)$'
|
2016-10-30 14:23:32 -04:00
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 19:35:53 -04:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2016-10-30 14:23:32 -04:00
|
|
|
call add(l:output, {
|
2017-11-21 08:38:27 -05:00
|
|
|
\ 'code': l:match[1],
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'filename': l:match[3],
|
|
|
|
\ 'lnum': l:match[4] + 0,
|
2016-10-30 14:23:32 -04:00
|
|
|
\ 'type': 'W',
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('chef', {
|
|
|
|
\ 'name': 'foodcritic',
|
2017-11-21 08:38:27 -05:00
|
|
|
\ 'executable_callback': 'ale_linters#chef#foodcritic#GetExecutable',
|
2017-04-05 13:21:47 -04:00
|
|
|
\ 'command_callback': 'ale_linters#chef#foodcritic#GetCommand',
|
2016-10-30 14:23:32 -04:00
|
|
|
\ 'callback': 'ale_linters#chef#foodcritic#Handle',
|
2017-11-21 08:38:27 -05:00
|
|
|
\ 'lint_file': 1,
|
2016-10-30 14:23:32 -04:00
|
|
|
\})
|