]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/html/tidy.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 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / ale / ale_linters / html / tidy.vim
1 " Author: KabbAmine <amine.kabb@gmail.com>
2 " Description: This file adds support for checking HTML code with tidy.
3
4 let g:ale_html_tidy_executable = get(g:, 'ale_html_tidy_executable', 'tidy')
5 let g:ale_html_tidy_options = get(g:, 'ale_html_tidy_options', '-q -e -language en')
6
7 function! ale_linters#html#tidy#GetCommand(buffer) abort
8     " Specify file encoding in options
9     " (Idea taken from https://github.com/scrooloose/syntastic/blob/master/syntax_checkers/html/tidy.vim)
10     let l:file_encoding = get({
11     \   'ascii':        '-ascii',
12     \   'big5':         '-big5',
13     \   'cp1252':       '-win1252',
14     \   'cp850':        '-ibm858',
15     \   'cp932':        '-shiftjis',
16     \   'iso-2022-jp':  '-iso-2022',
17     \   'latin1':       '-latin1',
18     \   'macroman':     '-mac',
19     \   'sjis':         '-shiftjis',
20     \   'utf-16le':     '-utf16le',
21     \   'utf-16':       '-utf16',
22     \   'utf-8':        '-utf8',
23     \ }, &fileencoding, '-utf8')
24
25     " On macOS, old tidy (released on 31 Oct 2006) is installed. It does not
26     " consider HTML5 so we should avoid it.
27     let l:executable = ale#Var(a:buffer, 'html_tidy_executable')
28
29     if has('mac') && l:executable is# 'tidy' && exists('*exepath')
30     \  && exepath(l:executable) is# '/usr/bin/tidy'
31         return ''
32     endif
33
34     return printf('%s %s %s -',
35     \   l:executable,
36     \   ale#Var(a:buffer, 'html_tidy_options'),
37     \   l:file_encoding
38     \)
39 endfunction
40
41 function! ale_linters#html#tidy#Handle(buffer, lines) abort
42     " Matches patterns lines like the following:
43     " line 7 column 5 - Warning: missing </title> before </head>
44     let l:pattern = '^line \(\d\+\) column \(\d\+\) - \(Warning\|Error\): \(.\+\)$'
45     let l:output = []
46
47     for l:match in ale#util#GetMatches(a:lines, l:pattern)
48         let l:line = l:match[1] + 0
49         let l:col = l:match[2] + 0
50         let l:type = l:match[3] is# 'Error' ? 'E' : 'W'
51         let l:text = l:match[4]
52
53         call add(l:output, {
54         \   'lnum': l:line,
55         \   'col': l:col,
56         \   'text': l:text,
57         \   'type': l:type,
58         \})
59     endfor
60
61     return l:output
62 endfunction
63
64 call ale#linter#Define('html', {
65 \   'name': 'tidy',
66 \   'executable': {b -> ale#Var(b, 'html_tidy_executable')},
67 \   'output_stream': 'stderr',
68 \   'command': function('ale_linters#html#tidy#GetCommand'),
69 \   'callback': 'ale_linters#html#tidy#Handle',
70 \ })