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