ale/ale_linters/javascript/jshint.vim

48 lines
1.5 KiB
VimL
Raw Normal View History

2016-09-15 20:37:37 -04:00
" Author: Chris Kyrouac - https://github.com/fijshion
2016-10-03 14:55:55 -04:00
" Description: JSHint for Javascript files
2016-09-15 20:37:37 -04:00
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
2017-04-17 18:29:02 -04:00
return ale#path#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.
2017-04-17 18:29:02 -04:00
let l:jshint_config = ale#path#ResolveLocalPath(
\ a:buffer,
\ '.jshintrc',
\ get(g:, 'ale_jshint_config_loc', '')
\)
let l:command = ale#Escape(ale_linters#javascript#jshint#GetExecutable(a:buffer))
let l:command .= ' --reporter unix --extract auto'
if !empty(l:jshint_config)
let l:command .= ' --config ' . ale#Escape(l:jshint_config)
endif
let l:command .= ' -'
return l:command
endfunction
2016-09-14 16:34:18 -04:00
call ale#linter#Define('javascript', {
2016-09-15 20:37:37 -04:00
\ 'name': 'jshint',
\ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable',
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
\ 'callback': 'ale#handlers#unix#HandleAsError',
2016-09-14 16:34:18 -04:00
\})