summaryrefslogtreecommitdiff
path: root/ale_linters/javascript/jshint.vim
blob: 24c3875c9ae03a1907c24aa60fe6d7cd394af395 (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: Chris Kyrouac - https://github.com/fijshion
" Description: JSHint for Javascript files

let g:ale_javascript_jshint_executable =
\   get(g:, 'ale_javascript_jshint_executable', 'jshint')

let g:ale_javascript_jshint_use_global =
\   get(g:, 'ale_javascript_jshint_use_global', 0)

function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
    if ale#Var(a:buffer, 'javascript_jshint_use_global')
        return ale#Var(a:buffer, 'javascript_jshint_executable')
    endif

    return ale#util#ResolveLocalPath(
    \   a:buffer,
    \   'node_modules/.bin/jshint',
    \   ale#Var(a:buffer, 'javascript_jshint_executable')
    \)
endfunction

function! ale_linters#javascript#jshint#GetCommand(buffer) abort
    " Search for a local JShint config locaation, and default to a global one.
    let l:jshint_config = ale#util#ResolveLocalPath(
    \   a:buffer,
    \   '.jshintrc',
    \   get(g:, 'ale_jshint_config_loc', '')
    \)

    let l:command = ale_linters#javascript#jshint#GetExecutable(a:buffer)
    let l:command .= ' --reporter unix'

    if !empty(l:jshint_config)
        let l:command .= ' --config ' . fnameescape(l:jshint_config)
    endif

    let l:command .= ' -'

    return l:command
endfunction

call ale#linter#Define('javascript', {
\   'name': 'jshint',
\   'executable_callback': 'ale_linters#javascript#jshint#GetExecutable',
\   'command_callback': 'ale_linters#javascript#jshint#GetCommand',
\   'callback': 'ale#handlers#HandleUnixFormatAsError',
\})