summaryrefslogtreecommitdiff
path: root/ale_linters/clojure/clj_kondo.vim
blob: b470cf0c7dce8d78d6d25f6e63aaf131df9aec22 (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
" Author: Masashi Iizuka <liquidz.uo@gmail.com>
" Description: linter for clojure using clj-kondo https://github.com/borkdude/clj-kondo

call ale#Set('clojure_clj_kondo_options', '--cache')

function! ale_linters#clojure#clj_kondo#GetCommand(buffer) abort
    let l:options = ale#Var(a:buffer, 'clojure_clj_kondo_options')

    let l:command = 'clj-kondo'
    \   . ale#Pad(l:options)
    \   . ' --lint -'
    \   . ' --filename %s'

    return l:command
endfunction

function! ale_linters#clojure#clj_kondo#HandleCljKondoFormat(buffer, lines) abort
    " output format
    " <filename>:<line>:<column>: <issue type>: <message>
    let l:pattern = '\v^[a-zA-Z]?:?[^:]+:(\d+)?:(\d+)?:? ((Exception|error|warning): ?(.+))$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:type = 'E'

        if l:match[4] is? 'warning'
            let l:type = 'W'
        endif

        call add(l:output, {
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'text': l:match[3],
        \   'type': l:type,
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('clojure', {
\   'name': 'clj-kondo',
\   'output_stream': 'stdout',
\   'executable': 'clj-kondo',
\   'command': function('ale_linters#clojure#clj_kondo#GetCommand'),
\   'callback': 'ale_linters#clojure#clj_kondo#HandleCljKondoFormat',
\})