mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 20:54:26 +08:00
Close #1417 - Support wildcard filetypes for fixers
This commit is contained in:
@@ -356,9 +356,21 @@ function! s:RunFixer(options) abort
|
|||||||
call ale#fix#ApplyFixes(l:buffer, l:input)
|
call ale#fix#ApplyFixes(l:buffer, l:input)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GetCallbacks(buffer, linters) abort
|
function! s:AddSubCallbacks(full_list, callbacks) abort
|
||||||
if len(a:linters)
|
if type(a:callbacks) == type('')
|
||||||
let l:callback_list = a:linters
|
call add(a:full_list, a:callbacks)
|
||||||
|
elseif type(a:callbacks) == type([])
|
||||||
|
call extend(a:full_list, a:callbacks)
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:GetCallbacks(buffer, fixers) abort
|
||||||
|
if len(a:fixers)
|
||||||
|
let l:callback_list = a:fixers
|
||||||
elseif type(get(b:, 'ale_fixers')) is type([])
|
elseif type(get(b:, 'ale_fixers')) is type([])
|
||||||
" Lists can be used for buffer-local variables only
|
" Lists can be used for buffer-local variables only
|
||||||
let l:callback_list = b:ale_fixers
|
let l:callback_list = b:ale_fixers
|
||||||
@@ -367,16 +379,18 @@ function! s:GetCallbacks(buffer, linters) abort
|
|||||||
" callbacks to run.
|
" callbacks to run.
|
||||||
let l:fixers = ale#Var(a:buffer, 'fixers')
|
let l:fixers = ale#Var(a:buffer, 'fixers')
|
||||||
let l:callback_list = []
|
let l:callback_list = []
|
||||||
|
let l:matched = 0
|
||||||
|
|
||||||
for l:sub_type in split(&filetype, '\.')
|
for l:sub_type in split(&filetype, '\.')
|
||||||
let l:sub_type_callacks = get(l:fixers, l:sub_type, [])
|
if s:AddSubCallbacks(l:callback_list, get(l:fixers, l:sub_type))
|
||||||
|
let l:matched = 1
|
||||||
if type(l:sub_type_callacks) == type('')
|
|
||||||
call add(l:callback_list, l:sub_type_callacks)
|
|
||||||
else
|
|
||||||
call extend(l:callback_list, l:sub_type_callacks)
|
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
" If we couldn't find fixers for a filetype, default to '*' fixers.
|
||||||
|
if !l:matched
|
||||||
|
call s:AddSubCallbacks(l:callback_list, get(l:fixers, '*'))
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if empty(l:callback_list)
|
if empty(l:callback_list)
|
||||||
|
|||||||
@@ -938,6 +938,14 @@ g:ale_fixers *g:ale_fixers*
|
|||||||
`b:ale_fixers` can be set to a |List| of callbacks instead, which can be
|
`b:ale_fixers` can be set to a |List| of callbacks instead, which can be
|
||||||
more convenient.
|
more convenient.
|
||||||
|
|
||||||
|
A special `'*'` key be used as a wildcard filetype for configuring fixers
|
||||||
|
for every other type of file. For example: >
|
||||||
|
|
||||||
|
" Fix Python files with 'bar'.
|
||||||
|
" Don't fix 'html' files.
|
||||||
|
" Fix everything else with 'foo'.
|
||||||
|
let g:ale_fixers = {'python': ['bar'], 'html': [], '*': ['foo']}
|
||||||
|
<
|
||||||
|
|
||||||
g:ale_fix_on_save *g:ale_fix_on_save*
|
g:ale_fix_on_save *g:ale_fix_on_save*
|
||||||
b:ale_fix_on_save *b:ale_fix_on_save*
|
b:ale_fix_on_save *b:ale_fix_on_save*
|
||||||
|
|||||||
@@ -257,6 +257,25 @@ Expect(Only the second function should be applied):
|
|||||||
$b
|
$b
|
||||||
$c
|
$c
|
||||||
|
|
||||||
|
Execute(The * fixers shouldn't be used if an empty list is set for fixers):
|
||||||
|
let g:ale_fixers.testft = []
|
||||||
|
let g:ale_fixers['*'] = ['AddDollars']
|
||||||
|
ALEFix
|
||||||
|
|
||||||
|
Expect(Nothing should be changed):
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
Execute(* fixers should be used if no filetype is matched):
|
||||||
|
let g:ale_fixers = {'*': ['AddDollars']}
|
||||||
|
ALEFix
|
||||||
|
|
||||||
|
Expect(The file should be changed):
|
||||||
|
$a
|
||||||
|
$b
|
||||||
|
$c
|
||||||
|
|
||||||
Execute(ALEFix should allow commands to be run):
|
Execute(ALEFix should allow commands to be run):
|
||||||
if has('win32')
|
if has('win32')
|
||||||
" Just skip this test on Windows, we can't run it.
|
" Just skip this test on Windows, we can't run it.
|
||||||
|
|||||||
Reference in New Issue
Block a user