summaryrefslogtreecommitdiff
path: root/ale_linters/solidity/solhint.vim
blob: cab2c18a0766941b1ce74216fe09cd9e75da6019 (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
" Author: Franco Victorio - https://github.com/fvictorio
" Description: Report errors in Solidity code with solhint

function! ale_linters#solidity#solhint#Handle(buffer, lines) abort
    " Matches patterns like the following:
    " /path/to/file/file.sol: line 1, col 10, Error - 'addOne' is defined but never used. (no-unused-vars)

    let l:pattern = '\v^[^:]+: line (\d+), col (\d+), (Error|Warning) - (.*)$'
    let l:output = []

    for l:match in ale#util#GetMatches(a:lines, l:pattern)
        let l:isError = l:match[3] is? 'error'
        call add(l:output, {
        \   'lnum': l:match[1] + 0,
        \   'col': l:match[2] + 0,
        \   'text': l:match[4],
        \   'type': l:isError ? 'E' : 'W'
        \})
    endfor

    return l:output
endfunction

call ale#linter#Define('solidity', {
\   'name': 'solhint',
\   'executable': 'solhint',
\   'command': 'solhint --formatter compact %t',
\   'callback': 'ale_linters#solidity#solhint#Handle',
\})