mirror of
https://github.com/amix/vimrc
synced 2025-07-09 10:45:00 +08:00
gitignore sources_non_forked_cache
This commit is contained in:
@ -0,0 +1,76 @@
|
||||
" 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']
|
||||
|
||||
let l:link = get(l:object, 'reference_url', '')
|
||||
|
||||
if type(l:link) == v:t_list
|
||||
" 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
|
||||
|
||||
if get(l:object, 'description', 'None') isnot# 'None'
|
||||
let l:detail .= "\n\n" . l:object['description']
|
||||
endif
|
||||
|
||||
let l:detail .= "\n\n" . l:link
|
||||
|
||||
call add(l:messages, {
|
||||
\ 'lnum': l:line,
|
||||
\ 'text': l:message,
|
||||
\ 'type': ale_linters#dockerfile#dockerfile_lint#GetType(l:type),
|
||||
\ 'detail': l:detail,
|
||||
\})
|
||||
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',
|
||||
\ 'executable': {b -> ale#Var(b, 'dockerfile_dockerfile_lint_executable')},
|
||||
\ 'command': function('ale_linters#dockerfile#dockerfile_lint#GetCommand'),
|
||||
\ 'callback': 'ale_linters#dockerfile#dockerfile_lint#Handle',
|
||||
\})
|
123
sources_non_forked/ale/ale_linters/dockerfile/hadolint.vim
Normal file
123
sources_non_forked/ale/ale_linters/dockerfile/hadolint.vim
Normal file
@ -0,0 +1,123 @@
|
||||
" Author: hauleth - https://github.com/hauleth
|
||||
|
||||
" always, yes, never
|
||||
call ale#Set('dockerfile_hadolint_use_docker', 'never')
|
||||
call ale#Set('dockerfile_hadolint_docker_image', 'hadolint/hadolint')
|
||||
call ale#Set('dockerfile_hadolint_options', '')
|
||||
|
||||
function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort
|
||||
" Matches patterns line the following:
|
||||
"
|
||||
" -:19 DL3001 warning: Pipe chain should start with a raw value.
|
||||
" /dev/stdin:19:3 unexpected thing
|
||||
let l:pattern = '\v^%(/dev/stdin|-):(\d+):?(\d+)? ((DL|SC)(\d+) )?((.+)?: )?(.+)$'
|
||||
let l:output = []
|
||||
|
||||
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
||||
let l:lnum = 0
|
||||
let l:colnum = 0
|
||||
|
||||
if l:match[1] isnot# ''
|
||||
let l:lnum = l:match[1] + 0
|
||||
endif
|
||||
|
||||
if l:match[2] isnot# ''
|
||||
let l:colnum = l:match[2] + 0
|
||||
endif
|
||||
|
||||
" Shellcheck knows a 'style' severity - pin it to info level as well.
|
||||
if l:match[7] is# 'style'
|
||||
let l:type = 'I'
|
||||
elseif l:match[7] is# 'info'
|
||||
let l:type = 'I'
|
||||
elseif l:match[7] is# 'warning'
|
||||
let l:type = 'W'
|
||||
else
|
||||
let l:type = 'E'
|
||||
endif
|
||||
|
||||
let l:text = l:match[8]
|
||||
let l:detail = l:match[8]
|
||||
let l:domain = 'https://github.com/hadolint/hadolint/wiki/'
|
||||
let l:code = ''
|
||||
let l:link = ''
|
||||
|
||||
if l:match[4] is# 'SC'
|
||||
let l:domain = 'https://github.com/koalaman/shellcheck/wiki/'
|
||||
endif
|
||||
|
||||
if l:match[5] isnot# ''
|
||||
let l:code = l:match[4] . l:match[5]
|
||||
let l:link = ' ( ' . l:domain . l:code . ' )'
|
||||
let l:text = l:code . ': ' . l:detail
|
||||
let l:detail = l:code . l:link . "\n\n" . l:detail
|
||||
else
|
||||
let l:type = 'E'
|
||||
let l:detail = 'hadolint could not parse the file because of a syntax error.'
|
||||
endif
|
||||
|
||||
let l:line_output = {
|
||||
\ 'lnum': l:lnum,
|
||||
\ 'col': l:colnum,
|
||||
\ 'type': l:type,
|
||||
\ 'text': l:text,
|
||||
\ 'detail': l:detail
|
||||
\}
|
||||
|
||||
if l:code isnot# ''
|
||||
let l:line_output['code'] = l:code
|
||||
endif
|
||||
|
||||
call add(l:output, l:line_output)
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
" This is a little different than the typical 'executable' callback. We want
|
||||
" to afford the user the chance to say always use docker, never use docker,
|
||||
" and use docker if the hadolint executable is not present on the system.
|
||||
"
|
||||
" In the case of neither docker nor hadolint executables being present, it
|
||||
" really doesn't matter which we return -- either will have the effect of
|
||||
" 'nope, can't use this linter!'.
|
||||
|
||||
function! ale_linters#dockerfile#hadolint#GetExecutable(buffer) abort
|
||||
let l:use_docker = ale#Var(a:buffer, 'dockerfile_hadolint_use_docker')
|
||||
|
||||
" check for mandatory directives
|
||||
if l:use_docker is# 'never'
|
||||
return 'hadolint'
|
||||
elseif l:use_docker is# 'always'
|
||||
return 'docker'
|
||||
endif
|
||||
|
||||
" if we reach here, we want to use 'hadolint' if present...
|
||||
if executable('hadolint')
|
||||
return 'hadolint'
|
||||
endif
|
||||
|
||||
"... and 'docker' as a fallback.
|
||||
return 'docker'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#dockerfile#hadolint#GetCommand(buffer) abort
|
||||
let l:command = ale_linters#dockerfile#hadolint#GetExecutable(a:buffer)
|
||||
let l:opts = ale#Var(a:buffer, 'dockerfile_hadolint_options') . ' --no-color -'
|
||||
|
||||
if l:command is# 'docker'
|
||||
return printf('docker run --rm -i %s hadolint %s',
|
||||
\ ale#Var(a:buffer, 'dockerfile_hadolint_docker_image'),
|
||||
\ l:opts)
|
||||
endif
|
||||
|
||||
return 'hadolint ' . l:opts
|
||||
endfunction
|
||||
|
||||
|
||||
call ale#linter#Define('dockerfile', {
|
||||
\ 'name': 'hadolint',
|
||||
\ 'executable': function('ale_linters#dockerfile#hadolint#GetExecutable'),
|
||||
\ 'command': function('ale_linters#dockerfile#hadolint#GetCommand'),
|
||||
\ 'callback': 'ale_linters#dockerfile#hadolint#Handle',
|
||||
\})
|
Reference in New Issue
Block a user