summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-10-11 23:11:45 +0100
committerw0rp <devw0rp@gmail.com>2016-10-11 23:11:45 +0100
commit78bcf96e345c9aa31412ae06e1da2bbe6a568ff5 (patch)
tree1eabb9c650ba0a36386225f802d978d4963340f2 /autoload
parent69116966162a15127c088cce9319228ec32ba7f5 (diff)
downloadale-78bcf96e345c9aa31412ae06e1da2bbe6a568ff5.zip
Fix #87 - Allow linter filetypes to be aliased
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/linter.vim72
1 files changed, 62 insertions, 10 deletions
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index 010256d1..0cd3f9b1 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -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