Skip to content

Commit

Permalink
#927 Allow b:ale_linter_aliases to be set to a String
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Oct 26, 2018
1 parent 320c74c commit 77aacf0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion autoload/ale/linter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,9 @@ endfunction
function! s:GetAliasedFiletype(original_filetype) abort
let l:buffer_aliases = get(b:, 'ale_linter_aliases', {})

" b:ale_linter_aliases can be set to a List.
" b:ale_linter_aliases can be set to a List or String.
if type(l:buffer_aliases) is v:t_list
\|| type(l:buffer_aliases) is v:t_string
return l:buffer_aliases
endif

Expand Down
6 changes: 4 additions & 2 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1310,10 +1310,12 @@ g:ale_linter_aliases *g:ale_linter_aliases*
ALE will first look for aliases for filetypes in the `b:ale_linter_aliases`
variable, then `g:ale_linter_aliases`, and then a default Dictionary.

`b:ale_linter_aliases` can be set to a |List|, to tell ALE to load the
linters for specific filetypes for a given buffer. >
`b:ale_linter_aliases` can be set to a |List| or a |String|, to tell ALE to
load the linters for specific filetypes for a given buffer. >
let b:ale_linter_aliases = ['html', 'javascript', 'css']
" OR, Alias a filetype to only a single filetype with a String.
let b:ale_linter_aliases = 'javascript'
<
No linters will be loaded when the buffer's filetype is empty.

Expand Down
11 changes: 11 additions & 0 deletions test/test_linter_retrieval.vader
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ Execute (The local alias option shouldn't completely replace the global one):
" global Dictionary.
let b:ale_linter_aliases = {'testft3': ['testft1']}

AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1')

Execute (Lists should be accepted for local aliases):
call ale#linter#Define('testft1', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2)
Expand All @@ -139,6 +141,15 @@ Execute (Lists should be accepted for local aliases):

AssertEqual [g:testlinter2], ale#linter#Get('anything.else')

Execute (Strings should be accepted for local aliases):
call ale#linter#Define('testft1', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2)
let g:ale_linter_aliases = {'testft1': ['testft1', 'testft2']}
" We should load the testft2 linters for this buffer, with no duplicates.
let b:ale_linter_aliases = 'testft2'

AssertEqual [g:testlinter2], ale#linter#Get('anything.else')

Execute (Buffer-local overrides for aliases should be used):
call ale#linter#Define('testft1', g:testlinter1)
call ale#linter#Define('testft2', g:testlinter2)
Expand Down

0 comments on commit 77aacf0

Please sign in to comment.