diff options
author | Chris Weyl <chris@weyl.io> | 2017-07-03 09:37:32 -0500 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2017-07-03 15:37:32 +0100 |
commit | 5a3cfbbdf50bc3e82e8ceca486a6bbda201f99d9 (patch) | |
tree | 8b082f2598a3f49ace0f3ba38eb4b34f342cffdc /ale_linters/dockerfile | |
parent | 51f256e897891617eb8539c31f0c48e037600de7 (diff) | |
download | ale-5a3cfbbdf50bc3e82e8ceca486a6bbda201f99d9.zip |
Allow `hadolint` linter to run via docker image (#720)
* Add documentation for hadolint (doc/ale-hadolint.txt)
* Allow `hadolint` linter to run via docker image
These changes enable the `hadolint` linter to run via the author's
docker image, if present. Three modes are supported:
* never use docker;
* always use docker; and
* use docker as a failback.
Diffstat (limited to 'ale_linters/dockerfile')
-rw-r--r-- | ale_linters/dockerfile/hadolint.vim | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/ale_linters/dockerfile/hadolint.vim b/ale_linters/dockerfile/hadolint.vim index 1ac94ce3..4063bf1b 100644 --- a/ale_linters/dockerfile/hadolint.vim +++ b/ale_linters/dockerfile/hadolint.vim @@ -1,5 +1,9 @@ " Author: hauleth - https://github.com/hauleth +" always, yes, never +call ale#Set('dockerfile_hadolint_use_docker', 'never') +call ale#Set('dockerfile_hadolint_docker_image', 'lukasmartinelli/hadolint') + function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort " Matches patterns line the following: " @@ -29,9 +33,45 @@ function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort 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 ==# 'never' + return 'hadolint' + elseif l:use_docker ==# '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) + if l:command ==# 'docker' + return 'docker run --rm -i ' . ale#Var(a:buffer, 'dockerfile_hadolint_docker_image') + endif + return 'hadolint -' +endfunction + + call ale#linter#Define('dockerfile', { \ 'name': 'hadolint', -\ 'executable': 'hadolint', -\ 'command': 'hadolint -', +\ 'executable_callback': 'ale_linters#dockerfile#hadolint#GetExecutable', +\ 'command_callback': 'ale_linters#dockerfile#hadolint#GetCommand', \ 'callback': 'ale_linters#dockerfile#hadolint#Handle', \}) |