summaryrefslogtreecommitdiff
path: root/autoload/ale/fixers/xmllint.vim
blob: 9e478feb3bdaa421fc97db173708fc4ac28d3d06 (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
" Author: Cyril Roelandt <tipecaml@gmail.com>, jiz4oh <me@jiz4oh.com>
" Description: Integration of xmllint with ALE.

call ale#Set('xml_xmllint_executable', 'xmllint')
call ale#Set('xml_xmllint_options', '')
call ale#Set('xml_xmllint_indentsize', 2)

function! ale#fixers#xmllint#Fix(buffer) abort
    let l:executable = ale#Escape(ale#Var(a:buffer, 'xml_xmllint_executable'))
    let l:filename = bufname(a:buffer)

    if empty(l:filename)
        let l:filename = '%t'
    else
        let l:filename = ale#Escape(l:filename)
    endif

    let l:command = l:executable . ' --format ' . l:filename

    let l:indent = ale#Var(a:buffer, 'xml_xmllint_indentsize')

    if l:indent isnot# ''
        let l:env = ale#Env('XMLLINT_INDENT', repeat(' ', l:indent))
        let l:command = l:env . l:command
    endif

    let l:options = ale#Var(a:buffer, 'xml_xmllint_options')

    if l:options isnot# ''
        let l:command .= ' ' . l:options
    endif

    return {
    \   'command': l:command
    \}
endfunction