2018-10-26 16:34:32 +00:00
|
|
|
" Author: Alexander Olofsson <alexander.olofsson@liu.se>
|
|
|
|
|
|
|
|
call ale#Set('dockerfile_dockerfile_lint_executable', 'dockerfile_lint')
|
|
|
|
call ale#Set('dockerfile_dockerfile_lint_options', '')
|
|
|
|
|
|
|
|
function! ale_linters#dockerfile#dockerfile_lint#GetType(type) abort
|
|
|
|
if a:type is? 'error'
|
|
|
|
return 'E'
|
|
|
|
elseif a:type is? 'warn'
|
|
|
|
return 'W'
|
|
|
|
endif
|
|
|
|
|
|
|
|
return 'I'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#dockerfile#dockerfile_lint#Handle(buffer, lines) abort
|
|
|
|
try
|
|
|
|
let l:data = json_decode(join(a:lines, ''))
|
|
|
|
catch
|
|
|
|
return []
|
|
|
|
endtry
|
|
|
|
|
|
|
|
if empty(l:data)
|
|
|
|
" Should never happen, but it's better to be on the safe side
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:messages = []
|
|
|
|
|
|
|
|
for l:type in ['error', 'warn', 'info']
|
|
|
|
for l:object in l:data[l:type]['data']
|
|
|
|
let l:line = get(l:object, 'line', -1)
|
|
|
|
let l:message = l:object['message']
|
|
|
|
|
2020-05-06 10:07:08 +00:00
|
|
|
let l:link = get(l:object, 'reference_url', '')
|
|
|
|
if type(l:link) == type([])
|
|
|
|
" Somehow, reference_url is returned as two-part list.
|
|
|
|
" Anchor markers in that list are sometimes duplicated.
|
|
|
|
" See https://github.com/projectatomic/dockerfile_lint/issues/134
|
|
|
|
let l:link = join(l:link, '')
|
|
|
|
let l:link = substitute(l:link, '##', '#', '')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let l:detail = l:message
|
2018-10-26 16:34:32 +00:00
|
|
|
if get(l:object, 'description', 'None') isnot# 'None'
|
2020-05-06 10:07:08 +00:00
|
|
|
let l:detail .= "\n\n" . l:object['description']
|
2018-10-26 16:34:32 +00:00
|
|
|
endif
|
2020-05-06 10:07:08 +00:00
|
|
|
let l:detail .= "\n\n" . l:link
|
2018-10-26 16:34:32 +00:00
|
|
|
|
|
|
|
call add(l:messages, {
|
|
|
|
\ 'lnum': l:line,
|
|
|
|
\ 'text': l:message,
|
|
|
|
\ 'type': ale_linters#dockerfile#dockerfile_lint#GetType(l:type),
|
2020-05-06 10:07:08 +00:00
|
|
|
\ 'detail': l:detail,
|
2018-10-26 16:34:32 +00:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:messages
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#dockerfile#dockerfile_lint#GetCommand(buffer) abort
|
|
|
|
return '%e' . ale#Pad(ale#Var(a:buffer, 'dockerfile_dockerfile_lint_options'))
|
|
|
|
\ . ' -p -j -f'
|
|
|
|
\ . ' %t'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('dockerfile', {
|
|
|
|
\ 'name': 'dockerfile_lint',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'dockerfile_dockerfile_lint_executable')},
|
|
|
|
\ 'command': function('ale_linters#dockerfile#dockerfile_lint#GetCommand'),
|
2018-10-26 16:34:32 +00:00
|
|
|
\ 'callback': 'ale_linters#dockerfile#dockerfile_lint#Handle',
|
|
|
|
\})
|