#1108 Support using Lists and 'all' for b:ale_linters
This commit is contained in:
parent
099df0af52
commit
b98387d0fa
@ -289,11 +289,19 @@ function! ale#linter#ResolveFiletype(original_filetype) abort
|
||||
endfunction
|
||||
|
||||
function! s:GetLinterNames(original_filetype) abort
|
||||
for l:dict in [
|
||||
\ get(b:, 'ale_linters', {}),
|
||||
\ g:ale_linters,
|
||||
\ s:default_ale_linters,
|
||||
\]
|
||||
let l:buffer_ale_linters = get(b:, 'ale_linters', {})
|
||||
|
||||
" b:ale_linters can be set to 'all'
|
||||
if l:buffer_ale_linters is# 'all'
|
||||
return 'all'
|
||||
endif
|
||||
|
||||
" b:ale_linters can be set to a List.
|
||||
if type(l:buffer_ale_linters) is type([])
|
||||
return l:buffer_ale_linters
|
||||
endif
|
||||
|
||||
for l:dict in [l:buffer_ale_linters, g:ale_linters, s:default_ale_linters]
|
||||
if has_key(l:dict, a:original_filetype)
|
||||
return l:dict[a:original_filetype]
|
||||
endif
|
||||
|
16
doc/ale.txt
16
doc/ale.txt
@ -946,6 +946,20 @@ g:ale_linters *g:ale_linters*
|
||||
will first look for linters for filetypes in the `b:ale_linters` variable,
|
||||
then `g:ale_linters`, and then a default Dictionary.
|
||||
|
||||
`b:ale_linters` can be set to a List, or the string `'all'`. When linters
|
||||
for two different filetypes share the same name, the first linter loaded
|
||||
will be used. Any ambiguity can be resolved by using a Dictionary specifying
|
||||
which linter to run for which filetype instead. >
|
||||
|
||||
" Use ESLint for the buffer if the filetype includes 'javascript'.
|
||||
let b:ale_linters = {'javascript': ['eslint'], 'html': ['tidy']}
|
||||
" Use a List for the same setting. This will work in most cases.
|
||||
let b:ale_linters = ['eslint', 'tidy']
|
||||
" Disable all linters for the buffer.
|
||||
let b:ale_linters = []
|
||||
" Explicitly enable all available linters for the filetype.
|
||||
let b:ale_linters = 'all'
|
||||
<
|
||||
|
||||
g:ale_max_buffer_history_size *g:ale_max_buffer_history_size*
|
||||
|
||||
@ -1018,7 +1032,7 @@ g:ale_pattern_options *g:ale_pattern_options*
|
||||
" Use just ESLint for linting and fixing files which end in '.foo.js'
|
||||
let g:ale_pattern_options = {
|
||||
\ '\.foo\.js$': {
|
||||
\ 'ale_linters': {'javascript': ['eslint']},
|
||||
\ 'ale_linters': ['eslint'],
|
||||
\ 'ale_fixers: ['eslint'],
|
||||
\ },
|
||||
\}
|
||||
|
@ -42,6 +42,30 @@ Execute (You should be able to select linters with a buffer option):
|
||||
|
||||
AssertEqual [g:testlinter1], ale#linter#Get('testft')
|
||||
|
||||
Execute (b:ale_linters should work when set to a List):
|
||||
call ale#linter#Define('testft', g:testlinter1)
|
||||
call ale#linter#Define('testft', g:testlinter2)
|
||||
let g:ale_linters = {'testft': ['testlinter1', 'testlinter2']}
|
||||
let b:ale_linters = ['testlinter1']
|
||||
|
||||
AssertEqual [g:testlinter1], ale#linter#Get('testft')
|
||||
|
||||
Execute (b:ale_linters should disable all linters when set to an empty List):
|
||||
call ale#linter#Define('testft', g:testlinter1)
|
||||
call ale#linter#Define('testft', g:testlinter2)
|
||||
let g:ale_linters = {'testft': ['testlinter1', 'testlinter2']}
|
||||
let b:ale_linters = []
|
||||
|
||||
AssertEqual [], ale#linter#Get('testft')
|
||||
|
||||
Execute (b:ale_linters should enable all available linters when set to 'all'):
|
||||
call ale#linter#Define('testft', g:testlinter1)
|
||||
call ale#linter#Define('testft', g:testlinter2)
|
||||
let g:ale_linters = {'testft': ['testlinter1']}
|
||||
let b:ale_linters = 'all'
|
||||
|
||||
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft')
|
||||
|
||||
Execute (Buffer settings shouldn't completely replace global settings):
|
||||
call ale#linter#Define('testft', g:testlinter1)
|
||||
call ale#linter#Define('testft', g:testlinter2)
|
||||
|
Loading…
Reference in New Issue
Block a user