summaryrefslogtreecommitdiff
path: root/ale_linters/qml/qmlfmt.vim
blob: 85b131fdf89ed5191930f10ac4a47caae58a4130 (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
40
" Author: pylipp (www.github.com/pylipp)
" Description: qmlfmt for QML files

let g:ale_qml_qmlfmt_executable = get(g:, 'ale_qml_qmlfmt_executable', 'qmlfmt')

function! ale_linters#qml#qmlfmt#GetExecutable(buffer) abort
    return ale#Var(a:buffer, 'qml_qmlfmt_executable')
endfunction

function! ale_linters#qml#qmlfmt#GetCommand(buffer) abort
    return ale#Escape(ale_linters#qml#qmlfmt#GetExecutable(a:buffer))
    \   . ' -e'
endfunction

" Find lines like
" Error:11:1: Expected token `}'
function! ale_linters#qml#qmlfmt#Handle(buffer, lines) abort
    let l:pattern = '\v^(Error|Warning):(\d+):(\d+): (.+)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:item = {
        \   'lnum': l:match[2] + 0,
        \   'col': l:match[3] + 0,
        \   'text': l:match[4],
        \   'type': l:match[1] is# 'Warning' ? 'W' : 'E',
        \}
        call add(l:output, l:item)
    endfor

    return l:output
endfunction

call ale#linter#Define('qml', {
\   'name': 'qmlfmt',
\   'output_stream': 'stderr',
\   'executable_callback': 'ale_linters#qml#qmlfmt#GetExecutable',
\   'command_callback': 'ale_linters#qml#qmlfmt#GetCommand',
\   'callback': 'ale_linters#qml#qmlfmt#Handle',
\})