Fix #1128 - Add g:ale_linters_explicit for only enabling linters explicitly
This commit is contained in:
parent
2e9cd978a2
commit
6b2c61a5cc
@ -21,6 +21,8 @@ let s:default_ale_linter_aliases = {
|
||||
"
|
||||
" Only cargo is enabled for Rust by default.
|
||||
" rpmlint is disabled by default because it can result in code execution.
|
||||
"
|
||||
" NOTE: Update the g:ale_linters documentation when modifying this.
|
||||
let s:default_ale_linters = {
|
||||
\ 'csh': ['shell'],
|
||||
\ 'go': ['gofmt', 'golint', 'go vet'],
|
||||
@ -308,11 +310,26 @@ function! s:GetLinterNames(original_filetype) abort
|
||||
return l:buffer_ale_linters
|
||||
endif
|
||||
|
||||
for l:dict in [l:buffer_ale_linters, g:ale_linters, s:default_ale_linters]
|
||||
if has_key(l:dict, a:original_filetype)
|
||||
return l:dict[a:original_filetype]
|
||||
endif
|
||||
endfor
|
||||
" Try to get a buffer-local setting for the filetype
|
||||
if has_key(l:buffer_ale_linters, a:original_filetype)
|
||||
return l:buffer_ale_linters[a:original_filetype]
|
||||
endif
|
||||
|
||||
" Try to get a global setting for the filetype
|
||||
if has_key(g:ale_linters, a:original_filetype)
|
||||
return g:ale_linters[a:original_filetype]
|
||||
endif
|
||||
|
||||
" If the user has configured ALE to only enable linters explicitly, then
|
||||
" don't enable any linters by default.
|
||||
if g:ale_linters_explicit
|
||||
return []
|
||||
endif
|
||||
|
||||
" Try to get a default setting for the filetype
|
||||
if has_key(s:default_ale_linters, a:original_filetype)
|
||||
return s:default_ale_linters[a:original_filetype]
|
||||
endif
|
||||
|
||||
return 'all'
|
||||
endfunction
|
||||
|
32
doc/ale.txt
32
doc/ale.txt
@ -946,23 +946,25 @@ g:ale_linters *g:ale_linters*
|
||||
Type: |Dictionary|
|
||||
Default: `{}`
|
||||
|
||||
The |g:ale_linters| option sets a |Dictionary| mapping a filetype
|
||||
to a |List| of linter programs to be run when checking particular filetypes.
|
||||
Only the filetypes specified in the dictionary will be limited in terms
|
||||
of which linters will be run.
|
||||
The |g:ale_linters| option sets a |Dictionary| mapping a filetype to a
|
||||
|List| of linter programs to be run when checking particular filetypes.
|
||||
|
||||
This |Dictionary| will be merged with a default dictionary containing the
|
||||
following values: >
|
||||
|
||||
{
|
||||
\ 'csh': ['shell'],
|
||||
\ 'go': ['gofmt', 'golint', 'go vet'],
|
||||
\ 'help': [],
|
||||
\ 'python': ['flake8', 'mypy', 'pylint'],
|
||||
\ 'rust': ['cargo'],
|
||||
\ 'spec': [],
|
||||
\ 'text': [],
|
||||
\ 'zsh': ['shell'],
|
||||
\}
|
||||
<
|
||||
This option can be used to enable only a particular set of linters for a
|
||||
file. For example, you can enable only 'eslint' for JavaScript files: >
|
||||
file. For example, you can enable only `eslint` for JavaScript files: >
|
||||
|
||||
let g:ale_linters = {'javascript': ['eslint']}
|
||||
<
|
||||
@ -971,14 +973,15 @@ g:ale_linters *g:ale_linters*
|
||||
|
||||
let g:ale_linters = {'javascript': []}
|
||||
<
|
||||
All linters available for a given filetype can be enabled by using the
|
||||
string `'all'`: >
|
||||
All linters will be run for unspecified filetypes. All available linters can
|
||||
be enabled explicitly for a given filetype by passing the string `'all'`,
|
||||
instead of a List. >
|
||||
|
||||
let g:ale_linters = {'c': 'all'}
|
||||
<
|
||||
Linters can be configured in each buffer with buffer-local variables. ALE
|
||||
will first look for linters for filetypes in the `b:ale_linters` variable,
|
||||
then `g:ale_linters`, and then a default Dictionary.
|
||||
then `g:ale_linters`, and then the default Dictionary mentioned above.
|
||||
|
||||
`b:ale_linters` can be set to a List, or the string `'all'`. When linters
|
||||
for two different filetypes share the same name, the first linter loaded
|
||||
@ -994,6 +997,19 @@ g:ale_linters *g:ale_linters*
|
||||
" Explicitly enable all available linters for the filetype.
|
||||
let b:ale_linters = 'all'
|
||||
<
|
||||
ALE can be configured to disable all linters unless otherwise specified with
|
||||
`g:ale_enabled` or `b:ale_enabled` with the option |g:ale_linters_explicit|.
|
||||
|
||||
|
||||
g:ale_linters_explicit *g:ale_linters_explicit*
|
||||
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
|
||||
When set to `1`, only the linters from |g:ale_linters| and |b:ale_linters|
|
||||
will be enabled. The default behavior for ALE is to enable as many linters
|
||||
as possible, unless otherwise specified.
|
||||
|
||||
|
||||
g:ale_loclist_msg_format *g:ale_loclist_msg_format*
|
||||
|
||||
|
@ -68,7 +68,9 @@ let g:ale_filetype_blacklist = [
|
||||
\]
|
||||
|
||||
" This Dictionary configures which linters are enabled for which languages.
|
||||
let g:ale_linters = get(g:, 'ale_linters', {})
|
||||
call ale#Set('linters', {})
|
||||
" This option can be changed to only enable explicitly selected linters.
|
||||
call ale#Set('linters_explicit', 0)
|
||||
|
||||
" This Dictionary configures which functions will be used for fixing problems.
|
||||
let g:ale_fixers = get(g:, 'ale_fixers', {})
|
||||
|
68
test/test_filetype_linter_defaults.vader
Normal file
68
test/test_filetype_linter_defaults.vader
Normal file
@ -0,0 +1,68 @@
|
||||
Before:
|
||||
Save g:ale_linters
|
||||
Save g:ale_linters_explicit
|
||||
|
||||
let g:ale_linters_explicit = 0
|
||||
let g:ale_linters = {}
|
||||
|
||||
function! GetLinterNames(filetype) abort
|
||||
return map(ale#linter#Get(a:filetype), 'v:val.name')
|
||||
endfunction
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(The defaults for the csh filetype should be correct):
|
||||
AssertEqual ['shell'], GetLinterNames('csh')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('csh')
|
||||
|
||||
Execute(The defaults for the go filetype should be correct):
|
||||
AssertEqual ['gofmt', 'golint', 'go vet'], GetLinterNames('go')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('go')
|
||||
|
||||
Execute(The defaults for the help filetype should be correct):
|
||||
AssertEqual [], GetLinterNames('help')
|
||||
|
||||
Execute(The defaults for the python filetype should be correct):
|
||||
AssertEqual ['flake8', 'mypy', 'pylint'], GetLinterNames('python')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('python')
|
||||
|
||||
Execute(The defaults for the rust filetype should be correct):
|
||||
AssertEqual ['cargo'], GetLinterNames('rust')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('rust')
|
||||
|
||||
Execute(The defaults for the spec filetype should be correct):
|
||||
AssertEqual [], GetLinterNames('spec')
|
||||
|
||||
Execute(The defaults for the text filetype should be correct):
|
||||
AssertEqual [], GetLinterNames('text')
|
||||
|
||||
Execute(The defaults for the zsh filetype should be correct):
|
||||
AssertEqual ['shell'], GetLinterNames('zsh')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('zsh')
|
||||
|
||||
Execute(The defaults for the verilog filetype should be correct):
|
||||
" This filetype isn't configured with default, so we can test loading all
|
||||
" available linters with this.
|
||||
AssertEqual ['iverilog', 'verilator'], GetLinterNames('verilog')
|
||||
|
||||
let g:ale_linters_explicit = 1
|
||||
|
||||
AssertEqual [], GetLinterNames('verilog')
|
@ -1,5 +1,6 @@
|
||||
Before:
|
||||
Save g:ale_linters, g:ale_linter_aliases
|
||||
Save g:ale_linters
|
||||
Save g:ale_linter_aliases
|
||||
|
||||
let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
||||
let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1, 'aliases': [], 'lsp': '', 'add_newline': 0}
|
||||
|
Loading…
Reference in New Issue
Block a user