summaryrefslogtreecommitdiff
path: root/autoload/ale/handlers/vale.vim
blob: 2da72fc712327f3715c3ce7b214221fa477c381e (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
36
37
38
39
" Author: Johannes Wienke <languitar@semipol.de>
" Description: output handler for the vale JSON format

function! ale#handlers#vale#GetType(severity) abort
    if a:severity is? 'warning'
        return 'W'
    elseif a:severity is? 'suggestion'
        return 'I'
    endif

    return 'E'
endfunction

function! ale#handlers#vale#Handle(buffer, lines) abort
    try
        let l:errors = json_decode(join(a:lines, ''))
    catch
        return []
    endtry

    if empty(l:errors)
        return []
    endif

    let l:output = []

    for l:error in l:errors[keys(l:errors)[0]]
        call add(l:output, {
        \   'lnum': l:error['Line'],
        \   'col': l:error['Span'][0],
        \   'end_col': l:error['Span'][1],
        \   'code': l:error['Check'],
        \   'text': l:error['Message'],
        \   'type': ale#handlers#vale#GetType(l:error['Severity']),
        \})
    endfor

    return l:output
endfunction