Merge pull request #1308 from lorenzo/patch-1

Improving hadolint checker
This commit is contained in:
w0rp 2018-01-30 16:04:44 +00:00 committed by GitHub
commit 52fe924a13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 11 deletions

View File

@ -93,7 +93,7 @@ formatting.
| D | [dmd](https://dlang.org/dmd-linux.html) | | D | [dmd](https://dlang.org/dmd-linux.html) |
| Dafny | [dafny](https://rise4fun.com/Dafny) !! | | Dafny | [dafny](https://rise4fun.com/Dafny) !! |
| Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server) | | Dart | [dartanalyzer](https://github.com/dart-lang/sdk/tree/master/pkg/analyzer_cli) !!, [language_server](https://github.com/natebosch/dart_language_server) |
| Dockerfile | [hadolint](https://github.com/lukasmartinelli/hadolint) | | Dockerfile | [hadolint](https://github.com/hadolint/hadolint) |
| Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma) !!| | Elixir | [credo](https://github.com/rrrene/credo), [dialyxir](https://github.com/jeremyjh/dialyxir), [dogma](https://github.com/lpil/dogma) !!|
| Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) | | Elm | [elm-format](https://github.com/avh4/elm-format), [elm-make](https://github.com/elm-lang/elm-make) |
| Erb | [erb](https://apidock.com/ruby/ERB), [erubi](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) | | Erb | [erb](https://apidock.com/ruby/ERB), [erubi](https://github.com/jeremyevans/erubi), [erubis](https://github.com/kwatch/erubis) |

View File

@ -2,31 +2,51 @@
" always, yes, never " always, yes, never
call ale#Set('dockerfile_hadolint_use_docker', 'never') call ale#Set('dockerfile_hadolint_use_docker', 'never')
call ale#Set('dockerfile_hadolint_docker_image', 'lukasmartinelli/hadolint') call ale#Set('dockerfile_hadolint_docker_image', 'hadolint/hadolint')
function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort
" Matches patterns line the following: " Matches patterns line the following:
" "
" stdin:19: F: Pipe chain should start with a raw value. " /dev/stdin:19 DL3001 Pipe chain should start with a raw value.
let l:pattern = '\v^/dev/stdin:?(\d+)? (\S+) (.+)$' " /dev/stdin:19:3 unexpected thing
let l:pattern = '\v^/dev/stdin:(\d+):?(\d+)? ((DL|SC)(\d+) )?(.+)$'
let l:output = [] let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern) for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:lnum = 0 let l:lnum = 0
let l:colnum = 0
if l:match[1] isnot# '' if l:match[1] isnot# ''
let l:lnum = l:match[1] + 0 let l:lnum = l:match[1] + 0
endif endif
if l:match[2] isnot# ''
let l:colnum = l:match[2] + 0
endif
let l:type = 'W' let l:type = 'W'
let l:text = l:match[3] let l:text = l:match[6]
let l:detail = l:match[6]
let l:domain = 'https://github.com/hadolint/hadolint/wiki/'
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:detail = l:code . l:link . "\n\n" . l:detail
else
let l:type = 'E'
endif
call add(l:output, { call add(l:output, {
\ 'lnum': l:lnum, \ 'lnum': l:lnum,
\ 'col': 0, \ 'col': l:colnum,
\ 'type': l:type, \ 'type': l:type,
\ 'text': l:text, \ 'text': l:text,
\ 'nr': l:match[2], \ 'detail': l:detail
\}) \})
endfor endfor

View File

@ -5,7 +5,7 @@ ALE Dockerfile Integration *ale-dockerfile-options*
=============================================================================== ===============================================================================
hadolint *ale-dockerfile-hadolint* hadolint *ale-dockerfile-hadolint*
hadolint can be found at: https://github.com/lukasmartinelli/hadolint hadolint can be found at: https://github.com/hadolint/hadolint
g:ale_dockerfile_hadolint_use_docker *g:ale_dockerfile_hadolint_use_docker* g:ale_dockerfile_hadolint_use_docker *g:ale_dockerfile_hadolint_use_docker*
@ -25,12 +25,12 @@ g:ale_dockerfile_hadolint_use_docker *g:ale_dockerfile_hadolint_use_docker*
g:ale_dockerfile_hadolint_image *g:ale_dockerfile_hadolint_image* g:ale_dockerfile_hadolint_image *g:ale_dockerfile_hadolint_image*
*b:ale_dockerfile_hadolint_image* *b:ale_dockerfile_hadolint_image*
Type: |String| Type: |String|
Default: `'lukasmartinelli/hadolint'` Default: `'hadolint/hadolint'`
This variable controls the docker image used to run hadolint. The default This variable controls the docker image used to run hadolint. The default
is hadolint's author's build, and can be found at: is hadolint's author's build, and can be found at:
https://hub.docker.com/r/lukasmartinelli/hadolint/ https://hub.docker.com/r/hadolint/hadolint/
=============================================================================== ===============================================================================

View File

@ -55,7 +55,7 @@ Execute(command is correct when using docker):
let b:ale_dockerfile_hadolint_use_docker = 'always' let b:ale_dockerfile_hadolint_use_docker = 'always'
AssertEqual AssertEqual
\ "docker run --rm -i lukasmartinelli/hadolint", \ "docker run --rm -i hadolint/hadolint",
\ ale_linters#dockerfile#hadolint#GetCommand(bufnr('')) \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))
@ -66,4 +66,25 @@ Execute(command is correct when not docker):
\ "hadolint -", \ "hadolint -",
\ ale_linters#dockerfile#hadolint#GetCommand(bufnr('')) \ ale_linters#dockerfile#hadolint#GetCommand(bufnr(''))
Execute(test warnings from hadolint):
AssertEqual
\ [{'lnum': 10, 'col': 0, 'type': 'W', 'text': 'Using latest is prone to errors', 'detail': "DL3007 ( https://github.com/hadolint/hadolint/wiki/DL3007 )\n\nUsing latest is prone to errors"}],
\ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
\ '/dev/stdin:10 DL3007 Using latest is prone to errors',
\ ])
Execute(test warnings from shellcheck):
AssertEqual
\ [{'lnum': 3, 'col': 0, 'type': 'W', 'text': 'bar is referenced but not assigned.', 'detail': "SC2154 ( https://github.com/koalaman/shellcheck/wiki/SC2154 )\n\nbar is referenced but not assigned."}],
\ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
\ '/dev/stdin:3 SC2154 bar is referenced but not assigned.',
\ ])
Execute(test errors from dockerfile parser):
AssertEqual
\ [{'lnum': 3, 'col': 4, 'type': 'E', 'text': 'unexpected "A" expecting at least one space after ''RUN''', 'detail': 'unexpected "A" expecting at least one space after ''RUN'''}],
\ ale_linters#dockerfile#hadolint#Handle(bufnr(''), [
\ "/dev/stdin:3:4 unexpected \"A\" expecting at least one space after 'RUN'",
\ ])
" fin... " fin...