summaryrefslogtreecommitdiff
path: root/ale_linters/elixir/dialyxir.vim
blob: d28d3c7068877d9da1c678b72cde32577c2ad96a (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
" Author: Fran C. - https://github.com/franciscoj
" Description: Add dialyzer support for elixir through dialyxir
" https://github.com/jeremyjh/dialyxir

function! ale_linters#elixir#dialyxir#Handle(buffer, lines) abort
    " Matches patterns line the following:
    "
    " lib/filename.ex:19: Function fname/1 has no local return
    let l:pattern = '\v(.+):(\d+): (.+)$'
    let l:output = []
    let l:type = 'W'

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        if bufname(a:buffer) == l:match[1]
            call add(l:output, {
            \   'bufnr': a:buffer,
            \   'lnum': l:match[2] + 0,
            \   'col': 0,
            \   'type': l:type,
            \   'text': l:match[3],
            \})
        endif
    endfor

    return l:output
endfunction

function! ale_linters#elixir#dialyxir#GetCommand(buffer) abort
    let l:project_root = ale#handlers#elixir#FindMixProjectRoot(a:buffer)

    return ale#path#CdString(l:project_root)
    \ . ' mix help dialyzer && mix dialyzer'
endfunction

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