diff options
author | w0rp <w0rp@users.noreply.github.com> | 2016-10-24 20:23:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-24 20:23:15 +0100 |
commit | 79552872f3d1e33840a63025e7454c880a80ba56 (patch) | |
tree | bdb8690dc3085493747a947f8299247bb41a15a2 /ale_linters/javascript/jshint.vim | |
parent | 36461b69d7dbf0abe494cd450dd9233eed7b672f (diff) | |
parent | 226b4ed58681b2bdac494e989adae81df653f341 (diff) | |
download | ale-79552872f3d1e33840a63025e7454c880a80ba56.zip |
Merge pull request #142 from w0rp/use-local-jshint-program
Add node_modules support for JSHint, and use the global config as a fallback
Diffstat (limited to 'ale_linters/javascript/jshint.vim')
-rw-r--r-- | ale_linters/javascript/jshint.vim | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/ale_linters/javascript/jshint.vim b/ale_linters/javascript/jshint.vim index 327158a8..f82011dd 100644 --- a/ale_linters/javascript/jshint.vim +++ b/ale_linters/javascript/jshint.vim @@ -4,17 +4,31 @@ let g:ale_javascript_jshint_executable = \ get(g:, 'ale_javascript_jshint_executable', 'jshint') -function! ale_linters#javascript#jshint#GetCommand(buffer) - " Set this to the location of the jshint configuration file to - " use a fixed location for .jshintrc - if exists('g:ale_jshint_config_loc') - let l:jshint_config = g:ale_jshint_config_loc - else - " Look for the JSHint config in parent directories. - let l:jshint_config = ale#util#FindNearestFile(a:buffer, '.jshintrc') +let g:ale_javascript_jshint_use_global = +\ get(g:, 'ale_javascript_jshint_use_global', 0) + +function! ale_linters#javascript#jshint#GetExecutable(buffer) abort + if g:ale_javascript_jshint_use_global + return g:ale_javascript_jshint_executable endif - let l:command = g:ale_javascript_jshint_executable . ' --reporter unix' + return ale#util#ResolveLocalPath( + \ a:buffer, + \ 'node_modules/.bin/jshint', + \ g:ale_javascript_jshint_executable + \) +endfunction + +function! ale_linters#javascript#jshint#GetCommand(buffer) + " 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) @@ -27,7 +41,7 @@ endfunction call ale#linter#Define('javascript', { \ 'name': 'jshint', -\ 'executable': g:ale_javascript_jshint_executable, +\ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable', \ 'command_callback': 'ale_linters#javascript#jshint#GetCommand', \ 'callback': 'ale#handlers#HandleUnixFormatAsError', \}) |