aboutsummaryrefslogtreecommitdiff
path: root/.vim/autoload/neomake/makers/ft/markdown.vim
blob: 114648877bf8a1289de873201750ca86234e7db4 (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
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
92
93
94
95
96
97
function! neomake#makers#ft#markdown#SupersetOf() abort
    return 'text'
endfunction

function! neomake#makers#ft#markdown#EnabledMakers() abort
    let makers = executable('mdl') ? ['mdl'] : ['markdownlint']
    if executable('vale') | let makers += ['vale'] | endif
    return makers + neomake#makers#ft#text#EnabledMakers()
endfunction

function! neomake#makers#ft#markdown#mdl() abort
    let maker = {
                \
                \ 'errorformat':
                \   '%W%f:%l: %m,%-G%.%#',
                \ 'output_stream': 'stdout',
                \ }
    function! maker.postprocess(entry) abort
        if a:entry.text[0:1] ==# 'MD'
            let [code, text] = split(a:entry.text, '\v^MD\d+\zs ')
            let a:entry.nr = str2nr(code[2:])
            let a:entry.text = printf('%s (%s)', text, code)
        endif
        return a:entry
    endfunction
    return maker
endfunction

function! neomake#makers#ft#markdown#markdownlint() abort
    return {
                \ 'errorformat': '%f: %l: %m'
                \ }
endfunction

let s:alex_supports_stdin = {}
function! neomake#makers#ft#markdown#alex() abort
    let maker = {
                \ 'errorformat':
                \   '%P%f,'
                \   .'%-Q,'
                \   .'%*[ ]%l:%c-%*\d:%n%*[ ]%tarning%*[ ]%m,'
                \   .'%-G%.%#'
                \ }

    function! maker.supports_stdin(_jobinfo) abort
        let exe = exists('*exepath') ? exepath(self.exe) : self.exe
        let support = get(s:alex_supports_stdin, exe, -1)
        if support == -1
            let ver = neomake#compat#systemlist(['alex', '--version'])
            let ver_split = split(ver[0], '\.')
            if len(ver_split) > 1 && (ver_split[0] > 0 || +ver_split[1] >= 6)
                let support = 1
            else
                let support = 0
            endif
            let s:alex_supports_stdin[exe] = support
            call neomake#log#debug('alex: stdin support: '.support.'.')
        endif
        if support
            let self.args += ['--stdin']
            let self.tempfile_name = ''
        endif
        return support
    endfunction

    return maker
endfunction

function! neomake#makers#ft#markdown#ProcessVale(context) abort
    let entries = []
    for [filename, items] in items(a:context['json'])
        for data in items
            let entry = {
                        \ 'maker_name': 'vale',
                        \ 'filename': filename,
                        \ 'text': data.Message,
                        \ 'lnum': data.Line,
                        \ 'col': data.Span[0],
                        \ 'length': data.Span[1] - data.Span[0] + 1,
                        \ 'type': toupper(data.Severity[0])
                        \ }
            call add(entries, entry)
        endfor
    endfor
    return entries
endfunction

function! neomake#makers#ft#markdown#vale() abort
    return {
                \ 'args': [
                \   '--no-wrap',
                \   '--output', 'JSON'
                \ ],
                \ 'process_json': function('neomake#makers#ft#markdown#ProcessVale')
                \ }
endfunction
" vim: ts=4 sw=4 et