From cb0f0e1d0b2b189fbfb32b8ccbbc5efbed2cd7f0 Mon Sep 17 00:00:00 2001 From: infokiller Date: Tue, 19 Oct 2021 09:30:19 +0300 Subject: [PATCH] fix(hadolint): set code field as well (#3943) --- ale_linters/dockerfile/hadolint.vim | 10 ++++++++-- test/handler/test_hadolint.vader | 3 +++ test/test_dockerfile_hadolint_linter.vader | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ale_linters/dockerfile/hadolint.vim b/ale_linters/dockerfile/hadolint.vim index 45b03aed..278e9466 100644 --- a/ale_linters/dockerfile/hadolint.vim +++ b/ale_linters/dockerfile/hadolint.vim @@ -55,13 +55,19 @@ function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort let l:detail = 'hadolint could not parse the file because of a syntax error.' endif - call add(l:output, { + 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 diff --git a/test/handler/test_hadolint.vader b/test/handler/test_hadolint.vader index a88454fa..f84c303d 100644 --- a/test/handler/test_hadolint.vader +++ b/test/handler/test_hadolint.vader @@ -16,6 +16,7 @@ Execute(The hadolint handler should handle a normal example): \ 'lnum': 1, \ 'col': 0, \ 'type': 'W', + \ 'code': 'DL3006', \ 'text': "DL3006: Always tag the version of an image explicitly", \ 'detail': "DL3006 ( https://github.com/hadolint/hadolint/wiki/DL3006 )\n\nAlways tag the version of an image explicitly", \ }, @@ -23,6 +24,7 @@ Execute(The hadolint handler should handle a normal example): \ 'lnum': 4, \ 'col': 0, \ 'type': 'W', + \ 'code': 'DL3033', \ 'text': "DL3033: Specify version with `yum install -y -`.", \ 'detail': "DL3033 ( https://github.com/hadolint/hadolint/wiki/DL3033 )\n\nSpecify version with `yum install -y -`.", \ }, @@ -30,6 +32,7 @@ Execute(The hadolint handler should handle a normal example): \ 'lnum': 12, \ 'col': 0, \ 'type': 'W', + \ 'code': 'SC2039', \ 'text': "SC2039: In POSIX sh, brace expansion is undefined.", \ 'detail': "SC2039 ( https://github.com/koalaman/shellcheck/wiki/SC2039 )\n\nIn POSIX sh, brace expansion is undefined.", \ }, diff --git a/test/test_dockerfile_hadolint_linter.vader b/test/test_dockerfile_hadolint_linter.vader index 072cc524..6e02b212 100644 --- a/test/test_dockerfile_hadolint_linter.vader +++ b/test/test_dockerfile_hadolint_linter.vader @@ -68,14 +68,14 @@ Execute(command is correct when not docker): Execute(test warnings from hadolint): AssertEqual - \ [{'lnum': 10, 'col': 0, 'type': 'W', 'text': 'DL3007: Using latest is prone to errors', 'detail': "DL3007 ( https://github.com/hadolint/hadolint/wiki/DL3007 )\n\nUsing latest is prone to errors"}], + \ [{'lnum': 10, 'col': 0, 'type': 'W', 'code': 'DL3007', 'text': 'DL3007: 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(''), [ \ '-:10 DL3007 warning: Using latest is prone to errors', \ ]) Execute(test warnings from shellcheck): AssertEqual - \ [{'lnum': 3, 'col': 0, 'type': 'W', 'text': 'SC2154: bar is referenced but not assigned.', 'detail': "SC2154 ( https://github.com/koalaman/shellcheck/wiki/SC2154 )\n\nbar is referenced but not assigned."}], + \ [{'lnum': 3, 'col': 0, 'type': 'W', 'code': 'SC2154', 'text': 'SC2154: 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(''), [ \ '-:3 SC2154 warning: bar is referenced but not assigned.', \ ])