summaryrefslogtreecommitdiff
path: root/ale_linters/cloudformation/cfn_python_lint.vim
blob: 25e86ca3bb1df64712c55e0fbd75e2ec1cb08b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
" Author: Yasuhiro Kiyota <yasuhiroki.duck@gmail.com>
" Description: Support cfn-python-lint for AWS Cloudformation template file

function! ale_linters#cloudformation#cfn_python_lint#Handle(buffer, lines) abort
    " Matches patterns line the following:
    "
    " sample.template.yaml:96:7:96:15: [E3012] Property Resources/Sample/Properties/FromPort should be of type Integer
    let l:pattern = '\v^(.*):(\d+):(\d+):(\d+):(\d+): \[([[:alnum:]]+)\] (.*)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:code = l:match[6]

        if ale#path#IsBufferPath(a:buffer, l:match[1])
            call add(l:output, {
            \   'lnum': l:match[2] + 0,
            \   'col': l:match[3] + 0,
            \   'end_lnum': l:match[4] + 0,
            \   'end_col': l:match[5] + 0,
            \   'text': l:match[7],
            \   'code': l:code,
            \   'type': l:code[:0] is# 'E' ? 'E' : 'W',
            \})
        endif
    endfor

    return l:output
endfunction

call ale#linter#Define('cloudformation', {
\   'name': 'cloudformation',
\   'executable': 'cfn-lint',
\   'command': 'cfn-lint --template %t --format parseable',
\   'callback': 'ale_linters#cloudformation#cfn_python_lint#Handle',
\})