summaryrefslogtreecommitdiff
path: root/ale_linters/coffee/coffeelint.vim
blob: 9db3399c8cb0f84c05886c2b0d256b7c2de818a5 (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
" Author: Prashanth Chandra https://github.com/prashcr
" Description: coffeelint linter for coffeescript files

function! ale_linters#coffee#coffeelint#GetExecutable(buffer) abort
    return ale#path#ResolveLocalPath(
    \   a:buffer,
    \   'node_modules/.bin/coffeelint',
    \   'coffeelint'
    \)
endfunction

function! ale_linters#coffee#coffeelint#GetCommand(buffer) abort
    return ale_linters#coffee#coffeelint#GetExecutable(a:buffer)
    \   . ' --stdin --reporter csv'
endfunction

function! ale_linters#coffee#coffeelint#Handle(buffer, lines) abort
    " Matches patterns like the following:
    "
    " path,lineNumber,lineNumberEnd,level,message
    " stdin,14,,error,Throwing strings is forbidden
    "
    " Note that we currently ignore lineNumberEnd for multiline errors
    let l:pattern = 'stdin,\(\d\+\),\(\d*\),\(.\{-1,}\),\(.\+\)'
    let l:output = []

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

    return l:output
endfunction

call ale#linter#Define('coffee', {
\   'name': 'coffeelint',
\   'executable_callback': 'ale_linters#coffee#coffeelint#GetExecutable',
\   'command_callback': 'ale_linters#coffee#coffeelint#GetCommand',
\   'callback': 'ale_linters#coffee#coffeelint#Handle',
\})