File: w3.vim

package info (click to toggle)
vim-syntastic 3.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,860 kB
  • sloc: erlang: 248; python: 30; sh: 26; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,942 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"============================================================================
"File:        w3.vim
"Description: Syntax checking plugin for syntastic
"Maintainer:  Martin Grenfell <martin.grenfell at gmail dot com>
"License:     This program is free software. It comes without any warranty,
"             to the extent permitted by applicable law. You can redistribute
"             it and/or modify it under the terms of the Do What The Fuck You
"             Want To Public License, Version 2, as published by Sam Hocevar.
"             See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================

if exists('g:loaded_syntastic_html_w3_checker')
    finish
endif
let g:loaded_syntastic_html_w3_checker = 1

let s:save_cpo = &cpo
set cpo&vim

" Constants {{{1

let s:DEFAULTS = {
    \ 'html': {
        \ 'ctype':   'text/html',
        \ 'doctype': 'HTML5' },
    \ 'svg': {
        \ 'ctype':   'image/svg+xml',
        \ 'doctype': 'SVG 1.1' },
    \ 'xhtml': {
        \ 'ctype':   'application/xhtml+xml',
        \ 'doctype': 'XHTML 1.1' } }

" }}}1

" @vimlint(EVL101, 1, l:ctype)
" @vimlint(EVL101, 1, l:doctype)
function! SyntaxCheckers_html_w3_GetLocList() dict " {{{1
    let buf = bufnr('')
    let type = self.getFiletype()
    let fname = syntastic#util#shescape(fnamemodify(bufname(buf), ':p'))
    let api = syntastic#util#var(type . '_w3_api', 'https://validator.w3.org/check')

    for key in keys(s:DEFAULTS[type])
        let l:{key} = syntastic#util#var(type . '_w3_' . key, get(s:DEFAULTS[type], key))
    endfor

    " vint: -ProhibitUsingUndeclaredVariable
    let makeprg = self.getExecEscaped() . ' -q -L -s --compressed -F output=json' .
        \ (doctype !=# '' ? ' -F doctype=' . syntastic#util#shescape(doctype) : '') .
        \ ' -F uploaded_file=@' . fname .
            \ '\;type=' . ctype .
            \ '\;filename=' . fname .
        \ ' ' . api
    " vint: ProhibitUsingUndeclaredVariable

    let errorformat =
        \ '%A %\+{,' .
        \ '%C %\+"lastLine": %l\,%\?,' .
        \ '%C %\+"lastColumn": %c\,%\?,' .
        \ '%C %\+"message": "%m"\,%\?,' .
        \ '%C %\+"type": "%trror"\,%\?,' .
        \ '%-G %\+"type": "%tnfo"\,%\?,' .
        \ '%C %\+"subtype": "%tarning"\,%\?,' .
        \ '%Z %\+}\,,' .
        \ '%-G%.%#'

    let loclist = SyntasticMake({
        \ 'makeprg': makeprg,
        \ 'errorformat': errorformat,
        \ 'defaults': {'bufnr': bufnr('')},
        \ 'returns': [0] })

    for e in loclist
        let e['text'] = substitute(e['text'], '\m\\\([\"]\)', '\1', 'g')
    endfor

    return loclist
endfunction " }}}1
" @vimlint(EVL104, 0, l:doctype)
" @vimlint(EVL101, 0, l:ctype)

call g:SyntasticRegistry.CreateAndRegisterChecker({
    \ 'filetype': 'html',
    \ 'name': 'w3',
    \ 'exec': 'curl' })

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: set sw=4 sts=4 et fdm=marker: