Fix #87 - Allow linter filetypes to be aliased
This commit is contained in:
@@ -4,6 +4,21 @@
|
||||
|
||||
let s:linters = {}
|
||||
|
||||
" Default filetype aliaes.
|
||||
" The user defined aliases will be merged with this Dictionary.
|
||||
let s:default_ale_linter_aliases = {
|
||||
\ 'javscript.jsx': 'javascript',
|
||||
\ 'zsh': 'sh',
|
||||
\ 'csh': 'sh',
|
||||
\}
|
||||
|
||||
" Default linters to run for particular filetypes.
|
||||
" The user defined linter selections will be merged with this Dictionary.
|
||||
let s:default_ale_linters = {
|
||||
\ 'zsh': ['shell'],
|
||||
\ 'csh': ['shell'],
|
||||
\}
|
||||
|
||||
function! ale#linter#Define(filetype, linter) abort
|
||||
if !has_key(s:linters, a:filetype)
|
||||
let s:linters[a:filetype] = []
|
||||
@@ -37,25 +52,19 @@ function! ale#linter#Define(filetype, linter) abort
|
||||
call add(s:linters[a:filetype], l:new_linter)
|
||||
endfunction
|
||||
|
||||
function! ale#linter#Get(filetype) abort
|
||||
function! s:LoadLinters(filetype) abort
|
||||
if a:filetype ==# ''
|
||||
" Empty filetype? Nothing to be done about that.
|
||||
return []
|
||||
endif
|
||||
|
||||
if has_key(s:linters, a:filetype)
|
||||
" We already loaded a linter, great!
|
||||
" We already loaded the linter files for this filetype, so stop here.
|
||||
return s:linters[a:filetype]
|
||||
endif
|
||||
|
||||
if has_key(g:ale_linters, a:filetype)
|
||||
" Filter loaded linters according to list of linters specified in option.
|
||||
for l:linter in g:ale_linters[a:filetype]
|
||||
execute 'runtime! ale_linters/' . a:filetype . '/' . l:linter . '.vim'
|
||||
endfor
|
||||
else
|
||||
execute 'runtime! ale_linters/' . a:filetype . '/*.vim'
|
||||
endif
|
||||
" Load all linters for a given filetype.
|
||||
execute 'runtime! ale_linters/' . a:filetype . '/*.vim'
|
||||
|
||||
if !has_key(s:linters, a:filetype)
|
||||
" If we couldn't load any linters, let everyone know.
|
||||
@@ -64,3 +73,46 @@ function! ale#linter#Get(filetype) abort
|
||||
|
||||
return s:linters[a:filetype]
|
||||
endfunction
|
||||
|
||||
function! ale#linter#Get(original_filetype) abort
|
||||
" Try and get an aliased file type either from the user's Dictionary, or
|
||||
" our default Dictionary, otherwise use the filetype as-is.
|
||||
let l:filetype = get(
|
||||
\ g:ale_linter_aliases,
|
||||
\ a:original_filetype,
|
||||
\ get(
|
||||
\ s:default_ale_linter_aliases,
|
||||
\ a:original_filetype,
|
||||
\ a:original_filetype
|
||||
\ )
|
||||
\)
|
||||
|
||||
" Try and get a list of linters to run, using the original file type,
|
||||
" not the aliased filetype. We have some linters to limit by default,
|
||||
" and users may define their own list of linters to run.
|
||||
let l:linter_names = get(
|
||||
\ g:ale_linters,
|
||||
\ a:original_filetype,
|
||||
\ get(
|
||||
\ s:default_ale_linters,
|
||||
\ a:original_filetype,
|
||||
\ 'all'
|
||||
\ )
|
||||
\)
|
||||
|
||||
let l:all_linters = s:LoadLinters(l:filetype)
|
||||
let l:combined_linters = []
|
||||
|
||||
if type(l:linter_names) == type('') && l:linter_names ==# 'all'
|
||||
let l:combined_linters = l:all_linters
|
||||
elseif type(l:linter_names) == type([])
|
||||
" Select only the linters we or the user has specified.
|
||||
for l:linter in l:all_linters
|
||||
if index(l:linter_names, l:linter.name)
|
||||
call add(l:combined_linters, l:linter)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return l:combined_linters
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user