Add a function for finding nearest files, and use it to fix JSHint so it will find configuration files automatically.
This commit is contained in:
parent
bd2f39f21a
commit
c6dc324add
@ -7,11 +7,27 @@ endif
|
|||||||
|
|
||||||
let g:loaded_ale_linters_javascript_jshint = 1
|
let g:loaded_ale_linters_javascript_jshint = 1
|
||||||
|
|
||||||
" Set this to the location of the jshint configuration file
|
function! ale_linters#javascript#jshint#GetCommand(buffer)
|
||||||
if !exists('g:ale_jshint_config_loc')
|
" Set this to the location of the jshint configuration file to
|
||||||
let g:ale_jshint_config_loc = '.jshintrc'
|
" use a fixed location for .jshintrc
|
||||||
|
if exists('g:ale_jshint_config_loc')
|
||||||
|
let jshint_config = g:ale_jshint_config_loc
|
||||||
|
else
|
||||||
|
" Look for the JSHint config in parent directories.
|
||||||
|
let jshint_config = ale#util#FindNearestFile(a:buffer, '.jshintrc')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let command = 'jshint --reporter unix'
|
||||||
|
|
||||||
|
if jshint_config
|
||||||
|
let command .= ' --config ' . shellescape(jshint_config)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let command .= ' -'
|
||||||
|
|
||||||
|
return command
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#javascript#jshint#Handle(buffer, lines)
|
function! ale_linters#javascript#jshint#Handle(buffer, lines)
|
||||||
" Matches patterns line the following:
|
" Matches patterns line the following:
|
||||||
"
|
"
|
||||||
@ -54,13 +70,13 @@ endfunction
|
|||||||
call ALEAddLinter('javascript', {
|
call ALEAddLinter('javascript', {
|
||||||
\ 'name': 'jshint',
|
\ 'name': 'jshint',
|
||||||
\ 'executable': 'jshint',
|
\ 'executable': 'jshint',
|
||||||
\ 'command': 'jshint --reporter unix --config ' . g:ale_jshint_config_loc . ' -',
|
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
|
||||||
\ 'callback': 'ale_linters#javascript#jshint#Handle',
|
\ 'callback': 'ale_linters#javascript#jshint#Handle',
|
||||||
\})
|
\})
|
||||||
|
|
||||||
call ALEAddLinter('javascript.jsx', {
|
call ALEAddLinter('javascript.jsx', {
|
||||||
\ 'name': 'jshint',
|
\ 'name': 'jshint',
|
||||||
\ 'executable': 'jshint',
|
\ 'executable': 'jshint',
|
||||||
\ 'command': 'jshint --reporter unix --config ' . g:ale_jshint_config_loc . ' -',
|
\ 'command_callback': 'ale_linters#javascript#jshint#GetCommand',
|
||||||
\ 'callback': 'ale_linters#javascript#jshint#Handle',
|
\ 'callback': 'ale_linters#javascript#jshint#Handle',
|
||||||
\})
|
\})
|
||||||
|
@ -24,3 +24,9 @@ let g:ale#util#stdin_wrapper = s:FindWrapperScript()
|
|||||||
function! ale#util#GetLineCount(buffer)
|
function! ale#util#GetLineCount(buffer)
|
||||||
return len(getbufline(a:buffer, 1, '$'))
|
return len(getbufline(a:buffer, 1, '$'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Given a buffer and a filename, find the nearest file by searching upwards
|
||||||
|
" through the paths relative to the given buffer.
|
||||||
|
function! ale#util#FindNearestFile(buffer, filename)
|
||||||
|
return findfile(a:filename, fnamemodify(bufname(a:buffer), ':p') . ';')
|
||||||
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user