From e343148e80f53073e2d9b2d7a421adec5e06ee66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Padula?= Date: Mon, 16 May 2022 17:00:34 +0200 Subject: [PATCH] Fallback to summary field if detail exists but is empty in terraform linter (#4157) * Fallback to summary field if detail exists but is empty in terraform linter * Add test * Update terraform.vim * remove whitespaces --- ale_linters/terraform/terraform.vim | 8 ++++- test/handler/test_terraform_handler.vader | 39 +++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ale_linters/terraform/terraform.vim b/ale_linters/terraform/terraform.vim index cf134460..1beb8501 100644 --- a/ale_linters/terraform/terraform.vim +++ b/ale_linters/terraform/terraform.vim @@ -21,7 +21,13 @@ function! ale_linters#terraform#terraform#GetType(severity) abort endfunction function! ale_linters#terraform#terraform#GetDetail(error) abort - return get(a:error, 'detail', get(a:error, 'summary', '')) + let l:detail = get(a:error, 'detail', '') + + if strlen(l:detail) > 0 + return l:detail + else + return get(a:error, 'summary', '') + endif endfunction function! ale_linters#terraform#terraform#Handle(buffer, lines) abort diff --git a/test/handler/test_terraform_handler.vader b/test/handler/test_terraform_handler.vader index d054cb3b..4be89cb1 100644 --- a/test/handler/test_terraform_handler.vader +++ b/test/handler/test_terraform_handler.vader @@ -97,3 +97,42 @@ Execute(Should use summary if detail not available): \ ' ]', \ '}' \ ]) + +Execute(Should use summary if detail available but empty): + AssertEqual + \ [ + \ { + \ 'lnum': 91, + \ 'col': 41, + \ 'filename': ale#path#Simplify(g:dir . '/main.tf'), + \ 'type': 'E', + \ 'text': 'storage_os_disk: required field is not set', + \ } + \ ], + \ ale_linters#terraform#terraform#Handle(bufnr(''), [ + \ '{', + \ ' "valid": false,', + \ ' "error_count": 1,', + \ ' "warning_count": 0,', + \ ' "diagnostics": [', + \ ' {', + \ ' "severity": "error",', + \ ' "summary": "storage_os_disk: required field is not set",', + \ ' "detail": "",', + \ ' "range": {', + \ ' "filename": "main.tf",', + \ ' "start": {', + \ ' "line": 91,', + \ ' "column": 41,', + \ ' "byte": 2381', + \ ' },', + \ ' "end": {', + \ ' "line": 91,', + \ ' "column": 41,', + \ ' "byte": 2381', + \ ' }', + \ ' }', + \ ' }', + \ ' ]', + \ '}' + \ ])