summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorBjorn Neergaard <bjorn@neersighted.com>2016-10-21 21:02:20 -0500
committerBjorn Neergaard <bjorn@neersighted.com>2016-10-21 21:02:20 -0500
commitf49f615ef647fdd33d82dc6d2646cd70367f7426 (patch)
treea7df71e177c3884b845d6599813fd9fbb7a8c014 /autoload
parent216eadbcbead15613e1725aa023bbcfd014b7573 (diff)
downloadale-f49f615ef647fdd33d82dc6d2646cd70367f7426.zip
Add support for dot-seperate linters, improve linter tests
This PR first and formost implements support for dot-seperate filetypes, a very trivial change. This closes #132 But more importantly, this PR vastly improves the test quality for `ale#linter#Get`. It enables us to reset the state of ale's internal linter cache, to facilitate better testing, as well as making use of mocked linters instead of depending on linters on disk (which may change). In addition, a dummy linter is defined to test the autoloading behavior. Header guards were removed from all linters as: * A: ale won't try and load linters if they already exist in memory * B: we can't reset state for testing if they can't be loaded again
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/linter.vim87
1 files changed, 49 insertions, 38 deletions
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index e6dc9b16..9f4eb798 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -7,7 +7,6 @@ let s:linters = {}
" Default filetype aliaes.
" The user defined aliases will be merged with this Dictionary.
let s:default_ale_linter_aliases = {
-\ 'javascript.jsx': 'javascript',
\ 'zsh': 'sh',
\ 'csh': 'sh',
\}
@@ -19,6 +18,11 @@ let s:default_ale_linters = {
\ 'csh': ['shell'],
\}
+" Testing/debugging helper to unload all linters.
+function! ale#linter#Reset() abort
+ let s:linters = {}
+endfunction
+
function! ale#linter#Define(filetype, linter) abort
if !has_key(s:linters, a:filetype)
let s:linters[a:filetype] = []
@@ -74,45 +78,52 @@ function! s:LoadLinters(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)
+function! ale#linter#Get(original_filetypes) abort
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) >= 0
- call add(l:combined_linters, l:linter)
- endif
- endfor
- endif
+ " Handle dot-seperated filetypes.
+ for l:original_filetype in split(a:original_filetypes, '\.')
+ " 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,
+ \ l:original_filetype,
+ \ get(
+ \ s:default_ale_linter_aliases,
+ \ l:original_filetype,
+ \ l: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,
+ \ l:original_filetype,
+ \ get(
+ \ s:default_ale_linters,
+ \ l:original_filetype,
+ \ 'all'
+ \ )
+ \)
+
+ let l:all_linters = s:LoadLinters(l:filetype)
+ let l:filetype_linters = []
+
+ if type(l:linter_names) == type('') && l:linter_names ==# 'all'
+ let l:filetype_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) >= 0
+ call add(l:filetype_linters, l:linter)
+ endif
+ endfor
+ endif
+
+ call extend(l:combined_linters, l:filetype_linters)
+ endfor
return l:combined_linters
endfunction