#1108 Support selecting fixers with Lists
This commit is contained in:
parent
b789b9eaad
commit
f6ac8a9eb9
@ -332,18 +332,25 @@ function! s:RunFixer(options) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GetCallbacks() abort
|
function! s:GetCallbacks() abort
|
||||||
let l:fixers = ale#Var(bufnr(''), 'fixers')
|
if type(get(b:, 'ale_fixers')) is type([])
|
||||||
let l:callback_list = []
|
" Lists can be used for buffer-local variables only
|
||||||
|
let l:callback_list = b:ale_fixers
|
||||||
|
else
|
||||||
|
" buffer and global options can use dictionaries mapping filetypes to
|
||||||
|
" callbacks to run.
|
||||||
|
let l:fixers = ale#Var(bufnr(''), 'fixers')
|
||||||
|
let l:callback_list = []
|
||||||
|
|
||||||
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, [])
|
let l:sub_type_callacks = get(l:fixers, l:sub_type, [])
|
||||||
|
|
||||||
if type(l:sub_type_callacks) == type('')
|
if type(l:sub_type_callacks) == type('')
|
||||||
call add(l:callback_list, l:sub_type_callacks)
|
call add(l:callback_list, l:sub_type_callacks)
|
||||||
else
|
else
|
||||||
call extend(l:callback_list, l:sub_type_callacks)
|
call extend(l:callback_list, l:sub_type_callacks)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
if empty(l:callback_list)
|
if empty(l:callback_list)
|
||||||
return []
|
return []
|
||||||
|
19
doc/ale.txt
19
doc/ale.txt
@ -490,6 +490,18 @@ upon some lines immediately, then run `eslint` from the ALE registry, and
|
|||||||
then call a lambda function which will remove every single line comment
|
then call a lambda function which will remove every single line comment
|
||||||
from the file.
|
from the file.
|
||||||
|
|
||||||
|
For buffer-local settings, such as in |g:ale_pattern_options| or in ftplugin
|
||||||
|
files, a |List| may be used for configuring the fixers instead.
|
||||||
|
>
|
||||||
|
" Same as the above, only a List can be used instead of a Dictionary.
|
||||||
|
let b:ale_fixers = [
|
||||||
|
\ 'DoSomething',
|
||||||
|
\ 'eslint',
|
||||||
|
\ {buffer, lines -> filter(lines, 'v:val !=~ ''^\s*//''')},
|
||||||
|
\]
|
||||||
|
|
||||||
|
ALEFix
|
||||||
|
<
|
||||||
For convenience, a plug mapping is defined for |ALEFix|, so you can set up a
|
For convenience, a plug mapping is defined for |ALEFix|, so you can set up a
|
||||||
keybind easily for fixing files. >
|
keybind easily for fixing files. >
|
||||||
|
|
||||||
@ -694,6 +706,8 @@ g:ale_fixers *g:ale_fixers*
|
|||||||
See |ale-fix| for more information.
|
See |ale-fix| for more information.
|
||||||
|
|
||||||
This variable can be overridden with variables in each buffer.
|
This variable can be overridden with variables in each buffer.
|
||||||
|
`b:ale_fixers` can be set to a |List| of callbacks instead, which can be
|
||||||
|
more convenient.
|
||||||
|
|
||||||
|
|
||||||
g:ale_fix_on_save *g:ale_fix_on_save*
|
g:ale_fix_on_save *g:ale_fix_on_save*
|
||||||
@ -999,14 +1013,15 @@ g:ale_pattern_options *g:ale_pattern_options*
|
|||||||
buffer variables. This option can be set to automatically configure
|
buffer variables. This option can be set to automatically configure
|
||||||
different settings for different files. For example: >
|
different settings for different files. For example: >
|
||||||
|
|
||||||
|
" Use just ESLint for linting and fixing files which end in '.foo.js'
|
||||||
let g:ale_pattern_options = {
|
let g:ale_pattern_options = {
|
||||||
\ '\.foo\.js$': {
|
\ '\.foo\.js$': {
|
||||||
\ 'ale_linters': {'javascript': ['eslint']},
|
\ 'ale_linters': {'javascript': ['eslint']},
|
||||||
|
\ 'ale_fixers: ['eslint'],
|
||||||
\ },
|
\ },
|
||||||
\}
|
\}
|
||||||
<
|
<
|
||||||
The above example will match any filename ending in `.foo.js`, and use
|
See |b:ale_linters| and |b:ale_fixers| for information for those options.
|
||||||
only `eslint` for checking those files by setting `b:ale_linters`.
|
|
||||||
|
|
||||||
Filenames are matched with |match()|, and patterns depend on the |magic|
|
Filenames are matched with |match()|, and patterns depend on the |magic|
|
||||||
setting, unless prefixed with the special escape sequences like `'\v'`,
|
setting, unless prefixed with the special escape sequences like `'\v'`,
|
||||||
|
@ -330,6 +330,15 @@ Expect(There should be only two lines):
|
|||||||
a
|
a
|
||||||
b
|
b
|
||||||
|
|
||||||
|
Execute(ALEFix should allow Lists to be used for buffer-local fixer settings):
|
||||||
|
let g:ale_fixers.testft = ['AddCarets', 'AddDollars']
|
||||||
|
let b:ale_fixers = ['RemoveLastLine']
|
||||||
|
ALEFix
|
||||||
|
|
||||||
|
Expect(There should be only two lines):
|
||||||
|
a
|
||||||
|
b
|
||||||
|
|
||||||
Given testft (A file with three lines):
|
Given testft (A file with three lines):
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
|
Loading…
Reference in New Issue
Block a user