]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/xml/xmllint.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit 'a39f715c13be3352193ffd9c5b7536b8786eff64' as '.vim/bundle/vim-lsp'
[etc/vim.git] / .vim / bundle / ale / ale_linters / xml / xmllint.vim
1 " Author: q12321q <q12321q@gmail.com>
2 " Description: This file adds support for checking XML code with xmllint.
3
4 " CLI options
5 let g:ale_xml_xmllint_executable = get(g:, 'ale_xml_xmllint_executable', 'xmllint')
6 let g:ale_xml_xmllint_options = get(g:, 'ale_xml_xmllint_options', '')
7
8 function! ale_linters#xml#xmllint#GetCommand(buffer) abort
9     return '%e'
10     \   . ale#Pad(ale#Var(a:buffer, 'xml_xmllint_options'))
11     \   . ' --noout -'
12 endfunction
13
14 function! ale_linters#xml#xmllint#Handle(buffer, lines) abort
15     " Matches patterns lines like the following:
16     " file/path:123: error level : error message
17     let l:pattern_message = '\v^([^:]+):(\d+):\s*(([^:]+)\s*:\s+.*)$'
18
19     " parse column token line like that:
20     " file/path:123: parser error : Opening and ending tag mismatch: foo line 1 and bar
21     " </bar>
22     "       ^
23     let l:pattern_column_token = '\v^\s*\^$'
24
25     let l:output = []
26
27     for l:line in a:lines
28         " Parse error/warning lines
29         let l:match_message = matchlist(l:line, l:pattern_message)
30
31         if !empty(l:match_message)
32             let l:line = l:match_message[2] + 0
33             let l:type = l:match_message[4] =~? 'warning' ? 'W' : 'E'
34             let l:text = l:match_message[3]
35
36             call add(l:output, {
37             \   'lnum': l:line,
38             \   'text': l:text,
39             \   'type': l:type,
40             \})
41
42             continue
43         endif
44
45         " Parse column position
46         let l:match_column_token = matchlist(l:line, l:pattern_column_token)
47
48         if !empty(l:output) && !empty(l:match_column_token)
49             let l:previous = l:output[len(l:output) - 1]
50             let l:previous['col'] = len(l:match_column_token[0])
51
52             continue
53         endif
54     endfor
55
56     return l:output
57 endfunction
58
59 call ale#linter#Define('xml', {
60 \   'name': 'xmllint',
61 \   'output_stream': 'stderr',
62 \   'executable': {b -> ale#Var(b, 'xml_xmllint_executable')},
63 \   'command': function('ale_linters#xml#xmllint#GetCommand'),
64 \   'callback': 'ale_linters#xml#xmllint#Handle',
65 \ })