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#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 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',
|
2017-11-21 13:38:27 +00:00
|
|
|
\ 'executable_callback': 'ale_linters#chef#foodcritic#GetExecutable',
|
2017-04-05 17:21:47 +00:00
|
|
|
\ 'command_callback': '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
|
|
|
\})
|