From 27e2f53ac9892e8285d629228d5c25bdcdf84803 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 12 Nov 2017 00:11:50 +0000 Subject: #1108 Support setting b:ale_linter_aliases to a List --- autoload/ale/linter.vim | 9 ++++++++- doc/ale.txt | 6 ++++++ test/test_linter_retrieval.vader | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index 00ab916a..c6667d95 100644 --- a/autoload/ale/linter.vim +++ b/autoload/ale/linter.vim @@ -261,12 +261,19 @@ function! ale#linter#GetAll(filetypes) abort 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. + if type(l:buffer_aliases) is type([]) + return l:buffer_aliases + endif + " Check for aliased filetypes first in a buffer variable, " then the global variable, " then in the default mapping, " otherwise use the original filetype. for l:dict in [ - \ get(b:, 'ale_linter_aliases', {}), + \ l:buffer_aliases, \ g:ale_linter_aliases, \ s:default_ale_linter_aliases, \] diff --git a/doc/ale.txt b/doc/ale.txt index 488c222a..ae692698 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -904,6 +904,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. > + + let b:ale_linter_aliases = ['html', 'javascript', 'css'] +< + No linters will be loaded when the buffer's filetype is empty. g:ale_linters *g:ale_linters* *b:ale_linters* diff --git a/test/test_linter_retrieval.vader b/test/test_linter_retrieval.vader index 265738fb..5d5b582d 100644 --- a/test/test_linter_retrieval.vader +++ b/test/test_linter_retrieval.vader @@ -126,6 +126,21 @@ Execute (The local alias option shouldn't completely replace the global one): " global Dictionary. let b:ale_linter_aliases = {'testft3': ['testft1']} +Execute (Lists 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) + let g:ale_linter_aliases = {'testft1': ['testft2']} + let b:ale_linter_aliases = {'testft1': ['testft1', 'testft2']} + AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1') Execute (Linters should be loaded from disk appropriately): -- cgit v1.2.3