summaryrefslogtreecommitdiff
path: root/ale_linters/markdown/mdl.vim
blob: 9bb20318e2c7222b895fb3aacf3f45142d414f28 (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: Steve Dignam <steve@dignam.xyz>, Josh Leeb-du Toit <joshleeb.com>
" Description: Support for mdl, a markdown linter.

call ale#Set('markdown_mdl_executable', 'mdl')
call ale#Set('markdown_mdl_options', '')

function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
    " matches: '(stdin):173: MD004 Unordered list style'
    let l:pattern = ':\(\d*\): \(.*\)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        call add(l:output, {
        \   'lnum': l:match[1] + 0,
        \   'text': l:match[2],
        \   'type': 'W',
        \})
    endfor

    return l:output
endfunction

function! ale_linters#markdown#mdl#GetCommand(buffer) abort
    let l:executable = ale#Var(a:buffer, 'markdown_mdl_executable')
    let l:options = ale#Var(a:buffer, 'markdown_mdl_options')

    return l:executable . (!empty(l:options) ? ' ' . l:options : '')
endfunction


call ale#linter#Define('markdown', {
\   'name': 'mdl',
\   'executable': 'mdl',
\   'command_callback': 'ale_linters#markdown#mdl#GetCommand',
\   'callback': 'ale_linters#markdown#mdl#Handle'
\})