From 7af33637e874efea63a0bc27769aa4728962c652 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ananace\" Olofsson" Date: Fri, 26 Oct 2018 18:34:32 +0200 Subject: Add the dockerfile_lint linter for Dockerfiles (#1971) * Add the dockerfile_lint linter for Dockerfiles --- ale_linters/dockerfile/dockerfile_lint.vim | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 ale_linters/dockerfile/dockerfile_lint.vim (limited to 'ale_linters') diff --git a/ale_linters/dockerfile/dockerfile_lint.vim b/ale_linters/dockerfile/dockerfile_lint.vim new file mode 100644 index 00000000..a5a846f2 --- /dev/null +++ b/ale_linters/dockerfile/dockerfile_lint.vim @@ -0,0 +1,61 @@ +" Author: Alexander Olofsson + +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'] + + if get(l:object, 'description', 'None') isnot# 'None' + let l:message = l:message . '. ' . l:object['description'] + endif + + call add(l:messages, { + \ 'lnum': l:line, + \ 'text': l:message, + \ 'type': ale_linters#dockerfile#dockerfile_lint#GetType(l:type), + \}) + 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_callback': ale#VarFunc('dockerfile_dockerfile_lint_executable'), +\ 'command_callback': 'ale_linters#dockerfile#dockerfile_lint#GetCommand', +\ 'callback': 'ale_linters#dockerfile#dockerfile_lint#Handle', +\}) -- cgit v1.2.3