Fix 2726 - fix terraform linter.

Instead of using `terraform fmt` for linting use `terraform validate`
with json output.
This commit is contained in:
Horacio Sanson
2021-01-30 17:11:12 +09:00
parent 7c44f4e403
commit d511d5af11
3 changed files with 76 additions and 33 deletions

View File

@@ -1,34 +1,61 @@
Before:
" Load the file which defines the linter.
runtime ale_linters/terraform/terraform.vim
call ale#test#SetDirectory('/testplugin/test/terraform_files')
call ale#test#SetFilename('providers.tf')
After:
" Unload all linters again.
call ale#linter#Reset()
call ale#test#RestoreDirectory()
Execute(The output should be correct):
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'col': 20,
\ 'type': 'E',
\ 'text': 'illegal char',
\ 'lnum': 17,
\ 'col': 13,
\ 'filename': '/testplugin/test/terraform_files/providers.tf',
\ 'type': 'W',
\ 'text': 'Terraform 0.13 and earlier allowed provider version',
\ },
\ {
\ 'lnum': 2,
\ 'col': 14,
\ 'lnum': 0,
\ 'col': 0,
\ 'filename': '/testplugin/test/terraform_files/providers.tf',
\ 'type': 'E',
\ 'text': 'literal not terminated',
\ },
\ {
\ 'lnum': 1,
\ 'type': 'E',
\ 'text': 'object expected closing RBRACE got: EOF',
\ },
\ 'text': 'Plugin reinitialization required. Please run "terraform"',
\ }
\ ],
\ ale_linters#terraform#terraform#Handle(bufnr(''), [
\ 'Error running fmt: In <standard input>: At 1:20: illegal char',
\ 'Error running fmt: In <standard input>: At 2:14: literal not terminated',
\ 'Error running fmt: In <standard input>: object expected closing RBRACE got: EOF',
\ '{',
\ '"valid": false,',
\ '"error_count": 1,',
\ '"warning_count": 1,',
\ '"diagnostics": [',
\ ' {',
\ ' "severity": "warning",',
\ ' "summary": "Version constraints inside provider configuration blocks are deprecated",',
\ ' "detail": "Terraform 0.13 and earlier allowed provider version",',
\ ' "range": {',
\ ' "filename": "providers.tf",',
\ ' "start": {',
\ ' "line": 17,',
\ ' "column": 13,',
\ ' "byte": 669',
\ ' },',
\ ' "end": {',
\ ' "line": 17,',
\ ' "column": 24,',
\ ' "byte": 680',
\ ' }',
\ ' }',
\ ' },',
\ ' {',
\ ' "severity": "error",',
\ ' "summary": "Could not load plugin",',
\ ' "detail": "Plugin reinitialization required. Please run \"terraform\""',
\ ' }',
\ ' ]',
\ '}',
\ ])