Add support for multiple filetypes in filetype aliasing
This commit is contained in:
parent
8b890caa31
commit
475dd2e76a
@ -174,26 +174,25 @@ function! ale#linter#Define(filetype, linter) abort
|
|||||||
call add(s:linters[a:filetype], l:new_linter)
|
call add(s:linters[a:filetype], l:new_linter)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#linter#GetAll(filetype) abort
|
function! ale#linter#GetAll(filetypes) abort
|
||||||
if a:filetype ==# ''
|
let l:combined_linters = []
|
||||||
" Empty filetype? Nothing to be done about that.
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
if has_key(s:linters, a:filetype)
|
for l:filetype in a:filetypes
|
||||||
" We already loaded the linter files for this filetype, so stop here.
|
" Haven't we loaded the linter files for this filetype yet?
|
||||||
return s:linters[a:filetype]
|
if !has_key(s:linters, l:filetype)
|
||||||
endif
|
" So load it
|
||||||
|
execute 'silent! runtime! ale_linters/' . l:filetype . '/*.vim'
|
||||||
|
|
||||||
" Load all linters for a given filetype.
|
" Still don't have the linter files? There must be occured an error
|
||||||
execute 'silent! runtime! ale_linters/' . a:filetype . '/*.vim'
|
if !has_key(s:linters, l:filetype)
|
||||||
|
let s:linters[l:filetype] = []
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
if !has_key(s:linters, a:filetype)
|
call extend(l:combined_linters, get(s:linters, l:filetype, []))
|
||||||
" If we couldn't load any linters, let everyone know.
|
endfor
|
||||||
let s:linters[a:filetype] = []
|
|
||||||
endif
|
|
||||||
|
|
||||||
return s:linters[a:filetype]
|
return l:combined_linters
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#linter#ResolveFiletype(original_filetype) abort
|
function! ale#linter#ResolveFiletype(original_filetype) abort
|
||||||
@ -209,6 +208,10 @@ function! ale#linter#ResolveFiletype(original_filetype) abort
|
|||||||
\ )
|
\ )
|
||||||
\)
|
\)
|
||||||
|
|
||||||
|
if type(l:filetype) != type([])
|
||||||
|
return [l:filetype]
|
||||||
|
endif
|
||||||
|
|
||||||
return l:filetype
|
return l:filetype
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -380,6 +380,14 @@ g:ale_linter_aliases *g:ale_linter_aliases*
|
|||||||
not the aliased type (`'php'`). This allows an aliased type to run a
|
not the aliased type (`'php'`). This allows an aliased type to run a
|
||||||
different set of linters from the type it is being mapped to.
|
different set of linters from the type it is being mapped to.
|
||||||
|
|
||||||
|
Passing a list of filetypes is also supported. Say you want to lint
|
||||||
|
javascript and css embedded in HTML (using linters that support that).
|
||||||
|
You could alias `html` like so:
|
||||||
|
|
||||||
|
`let g:ale_linter_aliases = {'html': ['html', 'javascript', 'css']}`
|
||||||
|
|
||||||
|
Note that `html` itself was included as an alias. That is because aliases
|
||||||
|
will override the original linters for the aliased filetepe.
|
||||||
|
|
||||||
g:ale_linters *g:ale_linters*
|
g:ale_linters *g:ale_linters*
|
||||||
|
|
||||||
|
@ -39,5 +39,19 @@ Execute (Define multiple linters for different filetypes):
|
|||||||
Then (Linters for dot-seperated filetypes should be properly handled):
|
Then (Linters for dot-seperated filetypes should be properly handled):
|
||||||
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1.testft2')
|
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1.testft2')
|
||||||
|
|
||||||
|
Execute (Define multiple aliases for a filetype):
|
||||||
|
call ale#linter#Define('testft1', g:testlinter1)
|
||||||
|
call ale#linter#Define('testft2', g:testlinter2)
|
||||||
|
let ale_linter_aliases = {'testft3': ['testft1', 'testft2']}
|
||||||
|
Then (Linters should be transparently aliased):
|
||||||
|
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft3')
|
||||||
|
|
||||||
|
Execute (Alias a filetype to itself plus another one):
|
||||||
|
call ale#linter#Define('testft1', g:testlinter1)
|
||||||
|
call ale#linter#Define('testft2', g:testlinter2)
|
||||||
|
let ale_linter_aliases = {'testft1': ['testft1', 'testft2']}
|
||||||
|
Then (The original linters should still be there):
|
||||||
|
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')
|
||||||
|
|
||||||
Execute (Try to load a linter from disk):
|
Execute (Try to load a linter from disk):
|
||||||
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0}], ale#linter#Get('testft')
|
AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0}], ale#linter#Get('testft')
|
||||||
|
Loading…
Reference in New Issue
Block a user