Add node_modules support for JSHint, and use the global config as a fallback.

This commit is contained in:
w0rp 2016-10-23 13:25:50 +01:00
parent 36461b69d7
commit 226b4ed586
2 changed files with 41 additions and 10 deletions

View File

@ -4,17 +4,31 @@
let g:ale_javascript_jshint_executable = let g:ale_javascript_jshint_executable =
\ get(g:, 'ale_javascript_jshint_executable', 'jshint') \ get(g:, 'ale_javascript_jshint_executable', 'jshint')
function! ale_linters#javascript#jshint#GetCommand(buffer) let g:ale_javascript_jshint_use_global =
" Set this to the location of the jshint configuration file to \ get(g:, 'ale_javascript_jshint_use_global', 0)
" use a fixed location for .jshintrc
if exists('g:ale_jshint_config_loc') function! ale_linters#javascript#jshint#GetExecutable(buffer) abort
let l:jshint_config = g:ale_jshint_config_loc if g:ale_javascript_jshint_use_global
else return g:ale_javascript_jshint_executable
" Look for the JSHint config in parent directories.
let l:jshint_config = ale#util#FindNearestFile(a:buffer, '.jshintrc')
endif 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) if !empty(l:jshint_config)
let l:command .= ' --config ' . fnameescape(l:jshint_config) let l:command .= ' --config ' . fnameescape(l:jshint_config)
@ -27,7 +41,7 @@ endfunction
call ale#linter#Define('javascript', { call ale#linter#Define('javascript', {
\ 'name': 'jshint', \ 'name': 'jshint',
\ 'executable': g:ale_javascript_jshint_executable, \ 'executable_callback': 'ale_linters#javascript#jshint#GetExecutable',
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand', \ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
\ 'callback': 'ale#handlers#HandleUnixFormatAsError', \ 'callback': 'ale#handlers#HandleUnixFormatAsError',
\}) \})

View File

@ -399,8 +399,25 @@ g:ale_javascript_jshint_executable *g:ale_javascript_jshint_executable*
Type: |String| Type: |String|
Default: `'jshint'` Default: `'jshint'`
ALE will first discover the jshint path in an ancestor node_modules
directory. If no such path exists, this variable will be used instead.
This variable can be changed to change the path to jshint. This variable can be changed to change the path to jshint.
If you wish to use only a globally installed version of jshint, set
|g:ale_javascript_jshint_use_global| to `1`.
g:ale_javascript_jshint_use_global *g:ale_javascript_jshint_use_global*
Type: |String|
Default: `0`
This variable controls whether or not ALE will search for a local path for
jshint first. If this variable is set to `1`, then ALE will always use the
global version of jshint, in preference to locally installed versions of
jshint in node_modules.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
4.3. phpcs *ale-linter-options-phpcs* 4.3. phpcs *ale-linter-options-phpcs*