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
This commit is contained in:
Michał Padula 2022-05-16 17:00:34 +02:00 committed by GitHub
parent 429f5a1447
commit e343148e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -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

View File

@ -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',
\ ' }',
\ ' }',
\ ' }',
\ ' ]',
\ '}'
\ ])