I broke up with neovim....vim is my best friend now
This commit is contained in:
41
dot_vim/plugged/ale/ale_linters/terraform/checkov.vim
Normal file
41
dot_vim/plugged/ale/ale_linters/terraform/checkov.vim
Normal file
@@ -0,0 +1,41 @@
|
||||
" Author: Thyme-87 <thyme-87@posteo.me>
|
||||
" Description: use checkov for providing warnings via ale
|
||||
|
||||
call ale#Set('terraform_checkov_executable', 'checkov')
|
||||
call ale#Set('terraform_checkov_options', '')
|
||||
|
||||
function! ale_linters#terraform#checkov#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'terraform_checkov_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#checkov#GetCommand(buffer) abort
|
||||
return '%e ' . '-f %t -o json --quiet ' . ale#Var(a:buffer, 'terraform_checkov_options')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#checkov#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
|
||||
let l:results = get(get(ale#util#FuzzyJSONDecode(a:lines, {}), 'results', []), 'failed_checks', [])
|
||||
|
||||
for l:violation in l:results
|
||||
call add(l:output, {
|
||||
\ 'filename': l:violation['file_path'],
|
||||
\ 'lnum': l:violation['file_line_range'][0],
|
||||
\ 'end_lnum': l:violation['file_line_range'][1],
|
||||
\ 'text': l:violation['check_name'] . ' [' . l:violation['check_id'] . ']',
|
||||
\ 'detail': l:violation['check_id'] . ': ' . l:violation['check_name'] . "\n" .
|
||||
\ 'For more information, see: '. l:violation['guideline'],
|
||||
\ 'type': 'W',
|
||||
\ })
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'checkov',
|
||||
\ 'output_stream': 'stdout',
|
||||
\ 'executable': function('ale_linters#terraform#checkov#GetExecutable'),
|
||||
\ 'command': function('ale_linters#terraform#checkov#GetCommand'),
|
||||
\ 'callback': 'ale_linters#terraform#checkov#Handle',
|
||||
\})
|
||||
69
dot_vim/plugged/ale/ale_linters/terraform/terraform.vim
Normal file
69
dot_vim/plugged/ale/ale_linters/terraform/terraform.vim
Normal file
@@ -0,0 +1,69 @@
|
||||
" Author: Keith Maxwell <keith.maxwell@gmail.com>
|
||||
" Description: terraform fmt to check for errors
|
||||
|
||||
call ale#Set('terraform_terraform_executable', 'terraform')
|
||||
|
||||
function! ale_linters#terraform#terraform#GetExecutable(buffer) abort
|
||||
return ale#Var(a:buffer, 'terraform_terraform_executable')
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetCommand(buffer) abort
|
||||
return ale#Escape(ale_linters#terraform#terraform#GetExecutable(a:buffer))
|
||||
\ . ' validate -no-color -json '
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetType(severity) abort
|
||||
if a:severity is? 'warning'
|
||||
return 'W'
|
||||
endif
|
||||
|
||||
return 'E'
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform#GetDetail(error) abort
|
||||
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
|
||||
let l:output = []
|
||||
|
||||
let l:errors = ale#util#FuzzyJSONDecode(a:lines, {'diagnostics': []})
|
||||
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||
let l:file = expand('#' . a:buffer . ':p')
|
||||
|
||||
for l:error in l:errors['diagnostics']
|
||||
if has_key(l:error, 'range')
|
||||
call add(l:output, {
|
||||
\ 'filename': ale#path#GetAbsPath(l:dir, l:error['range']['filename']),
|
||||
\ 'lnum': l:error['range']['start']['line'],
|
||||
\ 'col': l:error['range']['start']['column'],
|
||||
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
||||
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
||||
\})
|
||||
else
|
||||
call add(l:output, {
|
||||
\ 'filename': l:file,
|
||||
\ 'lnum': 0,
|
||||
\ 'col': 0,
|
||||
\ 'text': ale_linters#terraform#terraform#GetDetail(l:error),
|
||||
\ 'type': ale_linters#terraform#terraform#GetType(l:error['severity']),
|
||||
\})
|
||||
endif
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'terraform',
|
||||
\ 'output_stream': 'stdout',
|
||||
\ 'executable': function('ale_linters#terraform#terraform#GetExecutable'),
|
||||
\ 'command': function('ale_linters#terraform#terraform#GetCommand'),
|
||||
\ 'callback': 'ale_linters#terraform#terraform#Handle',
|
||||
\})
|
||||
38
dot_vim/plugged/ale/ale_linters/terraform/terraform_ls.vim
Normal file
38
dot_vim/plugged/ale/ale_linters/terraform/terraform_ls.vim
Normal file
@@ -0,0 +1,38 @@
|
||||
" Author: Horacio Sanson <hsanson@gmail.com>
|
||||
" Description: terraform-ls integration for ALE (cf. https://github.com/hashicorp/terraform-ls)
|
||||
|
||||
call ale#Set('terraform_terraform_executable', 'terraform')
|
||||
call ale#Set('terraform_ls_executable', 'terraform-ls')
|
||||
call ale#Set('terraform_ls_options', '')
|
||||
|
||||
function! ale_linters#terraform#terraform_ls#GetTerraformExecutable(buffer) abort
|
||||
let l:terraform_executable = ale#Var(a:buffer, 'terraform_terraform_executable')
|
||||
|
||||
if(ale#path#IsAbsolute(l:terraform_executable))
|
||||
return '-tf-exec ' . l:terraform_executable
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform_ls#GetCommand(buffer) abort
|
||||
return '%e'
|
||||
\ . ale#Pad('serve')
|
||||
\ . ale#Pad(ale_linters#terraform#terraform_ls#GetTerraformExecutable(a:buffer))
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'terraform_ls_options'))
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform_ls#GetProjectRoot(buffer) abort
|
||||
let l:tf_dir = ale#path#FindNearestDirectory(a:buffer, '.terraform')
|
||||
|
||||
return !empty(l:tf_dir) ? fnamemodify(l:tf_dir, ':h:h') : ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'terraform_ls',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'terraform_ls_executable')},
|
||||
\ 'command': function('ale_linters#terraform#terraform_ls#GetCommand'),
|
||||
\ 'project_root': function('ale_linters#terraform#terraform_ls#GetProjectRoot'),
|
||||
\ 'language': 'terraform',
|
||||
\})
|
||||
25
dot_vim/plugged/ale/ale_linters/terraform/terraform_lsp.vim
Normal file
25
dot_vim/plugged/ale/ale_linters/terraform/terraform_lsp.vim
Normal file
@@ -0,0 +1,25 @@
|
||||
" Author: OJFord <dev@ojford.com>
|
||||
" Description: terraform-lsp integration for ALE (cf. https://github.com/juliosueiras/terraform-lsp)
|
||||
|
||||
call ale#Set('terraform_langserver_executable', 'terraform-lsp')
|
||||
call ale#Set('terraform_langserver_options', '')
|
||||
|
||||
function! ale_linters#terraform#terraform_lsp#GetCommand(buffer) abort
|
||||
return '%e'
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'terraform_langserver_options'))
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#terraform_lsp#GetProjectRoot(buffer) abort
|
||||
let l:tf_dir = ale#path#FindNearestDirectory(a:buffer, '.terraform')
|
||||
|
||||
return !empty(l:tf_dir) ? fnamemodify(l:tf_dir, ':h:h') : ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'terraform_lsp',
|
||||
\ 'lsp': 'stdio',
|
||||
\ 'executable': {b -> ale#Var(b, 'terraform_langserver_executable')},
|
||||
\ 'command': function('ale_linters#terraform#terraform_lsp#GetCommand'),
|
||||
\ 'project_root': function('ale_linters#terraform#terraform_lsp#GetProjectRoot'),
|
||||
\ 'language': 'terraform',
|
||||
\})
|
||||
105
dot_vim/plugged/ale/ale_linters/terraform/tflint.vim
Normal file
105
dot_vim/plugged/ale/ale_linters/terraform/tflint.vim
Normal file
@@ -0,0 +1,105 @@
|
||||
" Author: Nat Williams <nat.williams@gmail.com>
|
||||
" Description: tflint for Terraform files
|
||||
"
|
||||
" See: https://www.terraform.io/
|
||||
" https://github.com/wata727/tflint
|
||||
|
||||
call ale#Set('terraform_tflint_options', '')
|
||||
call ale#Set('terraform_tflint_executable', 'tflint')
|
||||
|
||||
function! ale_linters#terraform#tflint#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
let l:pattern = '\v^(.*):(\d+),(\d+)-(\d+)?,?(\d+): (.{-1,}); (.+)$'
|
||||
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
||||
|
||||
" This is a rough test for tflint's output format
|
||||
" On versions prior to 0.11 it outputs all errors as a single level list
|
||||
if type(l:json) is v:t_list
|
||||
for l:error in l:json
|
||||
if l:error.type is# 'ERROR'
|
||||
let l:type = 'E'
|
||||
elseif l:error.type is# 'NOTICE'
|
||||
let l:type = 'I'
|
||||
else
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:error.line,
|
||||
\ 'text': l:error.message,
|
||||
\ 'type': l:type,
|
||||
\ 'code': l:error.detector,
|
||||
\})
|
||||
endfor
|
||||
else
|
||||
for l:error in get(l:json, 'errors', [])
|
||||
for l:match in ale#util#GetMatches(l:error.message, [l:pattern])
|
||||
if l:match[4] is# ''
|
||||
let l:match[4] = l:match[2]
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'filename': l:match[1],
|
||||
\ 'lnum': str2nr(l:match[2]),
|
||||
\ 'col': str2nr(l:match[3]),
|
||||
\ 'end_lnum': str2nr(l:match[4]),
|
||||
\ 'end_col': str2nr(l:match[5]),
|
||||
\ 'text': l:match[7],
|
||||
\ 'code': l:match[6],
|
||||
\ 'type': 'E',
|
||||
\})
|
||||
endfor
|
||||
endfor
|
||||
|
||||
for l:error in get(l:json, 'issues', [])
|
||||
if l:error.rule.severity is# 'ERROR'
|
||||
let l:type = 'E'
|
||||
elseif l:error.rule.severity is# 'NOTICE'
|
||||
let l:type = 'I'
|
||||
else
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'filename': l:error.range.filename,
|
||||
\ 'lnum': l:error.range.start.line,
|
||||
\ 'col': l:error.range.start.column,
|
||||
\ 'end_lnum': l:error.range.end.line,
|
||||
\ 'end_col': l:error.range.end.column,
|
||||
\ 'text': l:error.message,
|
||||
\ 'code': l:error.rule.name,
|
||||
\ 'type': l:type,
|
||||
\})
|
||||
endfor
|
||||
endif
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
function! ale_linters#terraform#tflint#GetCommand(buffer) abort
|
||||
let l:cmd = '%e'
|
||||
|
||||
let l:config_file = ale#path#FindNearestFile(a:buffer, '.tflint.hcl')
|
||||
|
||||
if !empty(l:config_file)
|
||||
let l:cmd .= ' --config ' . ale#Escape(l:config_file)
|
||||
endif
|
||||
|
||||
let l:opts = ale#Var(a:buffer, 'terraform_tflint_options')
|
||||
|
||||
if !empty(l:opts)
|
||||
let l:cmd .= ' ' . l:opts
|
||||
endif
|
||||
|
||||
let l:cmd .= ' -f json'
|
||||
|
||||
return l:cmd
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'tflint',
|
||||
\ 'executable': {b -> ale#Var(b, 'terraform_tflint_executable')},
|
||||
\ 'cwd': '%s:h',
|
||||
\ 'command': function('ale_linters#terraform#tflint#GetCommand'),
|
||||
\ 'callback': 'ale_linters#terraform#tflint#Handle',
|
||||
\})
|
||||
87
dot_vim/plugged/ale/ale_linters/terraform/tfsec.vim
Normal file
87
dot_vim/plugged/ale/ale_linters/terraform/tfsec.vim
Normal file
@@ -0,0 +1,87 @@
|
||||
" Description: tfsec for Terraform files
|
||||
"
|
||||
" See: https://www.terraform.io/
|
||||
" https://github.com/aquasecurity/tfsec
|
||||
|
||||
call ale#Set('terraform_tfsec_options', '')
|
||||
call ale#Set('terraform_tfsec_executable', 'tfsec')
|
||||
|
||||
let s:separator = has('win32') ? '\' : '/'
|
||||
|
||||
function! ale_linters#terraform#tfsec#Handle(buffer, lines) abort
|
||||
let l:output = []
|
||||
let l:json = ale#util#FuzzyJSONDecode(a:lines, {})
|
||||
|
||||
" if there's no warning, 'result' is `null`.
|
||||
if empty(get(l:json, 'results'))
|
||||
return l:output
|
||||
endif
|
||||
|
||||
for l:result in get(l:json, 'results', [])
|
||||
if l:result.severity is# 'LOW'
|
||||
let l:type = 'I'
|
||||
elseif l:result.severity is# 'CRITICAL'
|
||||
let l:type = 'E'
|
||||
else
|
||||
let l:type = 'W'
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'filename': l:result.location.filename,
|
||||
\ 'lnum': l:result.location.start_line,
|
||||
\ 'end_lnum': l:result.location.end_line,
|
||||
\ 'text': l:result.description,
|
||||
\ 'code': l:result.long_id,
|
||||
\ 'type': l:type,
|
||||
\})
|
||||
endfor
|
||||
|
||||
return l:output
|
||||
endfunction
|
||||
|
||||
" Construct command arguments to tfsec with `terraform_tfsec_options`.
|
||||
function! ale_linters#terraform#tfsec#GetCommand(buffer) abort
|
||||
let l:cmd = '%e'
|
||||
|
||||
let l:config = ale_linters#terraform#tfsec#FindConfig(a:buffer)
|
||||
|
||||
if !empty(l:config)
|
||||
let l:cmd .= ' --config-file ' . l:config
|
||||
endif
|
||||
|
||||
let l:opts = ale#Var(a:buffer, 'terraform_tfsec_options')
|
||||
|
||||
if !empty(l:opts)
|
||||
let l:cmd .= ' ' . l:opts
|
||||
endif
|
||||
|
||||
let l:cmd .= ' --format json'
|
||||
|
||||
return l:cmd
|
||||
endfunction
|
||||
|
||||
" Find the nearest configuration file of tfsec.
|
||||
function! ale_linters#terraform#tfsec#FindConfig(buffer) abort
|
||||
let l:config_dir = ale#path#FindNearestDirectory(a:buffer, '.tfsec')
|
||||
|
||||
if !empty(l:config_dir)
|
||||
" https://aquasecurity.github.io/tfsec/v1.28.0/guides/configuration/config/
|
||||
for l:basename in ['config.yml', 'config.json']
|
||||
let l:config = ale#path#Simplify(join([l:config_dir, l:basename], s:separator))
|
||||
|
||||
if filereadable(l:config)
|
||||
return ale#Escape(l:config)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
call ale#linter#Define('terraform', {
|
||||
\ 'name': 'tfsec',
|
||||
\ 'executable': {b -> ale#Var(b, 'terraform_tfsec_executable')},
|
||||
\ 'cwd': '%s:h',
|
||||
\ 'command': function('ale_linters#terraform#tfsec#GetCommand'),
|
||||
\ 'callback': 'ale_linters#terraform#tfsec#Handle',
|
||||
\})
|
||||
Reference in New Issue
Block a user