#857 - Add b:ale_fix_on_save for controlling fixing on save for specific buffers
This commit is contained in:
parent
1575b3d7dd
commit
50f7ad3552
@ -12,11 +12,13 @@ function! ale#events#QuitRecently(buffer) abort
|
||||
endfunction
|
||||
|
||||
function! ale#events#SaveEvent(buffer) abort
|
||||
call setbufvar(a:buffer, 'ale_save_event_fired', 1)
|
||||
let l:should_lint = ale#Var(a:buffer, 'enabled')
|
||||
\ && g:ale_lint_on_save
|
||||
let l:should_lint = ale#Var(a:buffer, 'enabled') && g:ale_lint_on_save
|
||||
|
||||
if g:ale_fix_on_save
|
||||
if l:should_lint
|
||||
call setbufvar(a:buffer, 'ale_save_event_fired', 1)
|
||||
endif
|
||||
|
||||
if ale#Var(a:buffer, 'fix_on_save')
|
||||
let l:will_fix = ale#fix#Fix('save_file')
|
||||
let l:should_lint = l:should_lint && !l:will_fix
|
||||
endif
|
||||
|
@ -49,9 +49,7 @@ function! ale#toggle#InitAuGroups() abort
|
||||
|
||||
augroup ALERunOnSaveGroup
|
||||
autocmd!
|
||||
if (g:ale_enabled && g:ale_lint_on_save) || g:ale_fix_on_save
|
||||
autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
|
||||
endif
|
||||
autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnInsertLeave
|
||||
@ -73,10 +71,6 @@ function! ale#toggle#InitAuGroups() abort
|
||||
augroup END
|
||||
|
||||
if !g:ale_enabled
|
||||
if !g:ale_fix_on_save
|
||||
augroup! ALERunOnSaveGroup
|
||||
endif
|
||||
|
||||
augroup! ALEPatternOptionsGroup
|
||||
augroup! ALERunOnTextChangedGroup
|
||||
augroup! ALERunOnEnterGroup
|
||||
|
@ -669,6 +669,7 @@ g:ale_fixers *g:ale_fixers*
|
||||
|
||||
|
||||
g:ale_fix_on_save *g:ale_fix_on_save*
|
||||
b:ale_fix_on_save *b:ale_fix_on_save*
|
||||
|
||||
Type: |Number|
|
||||
Default: `0`
|
||||
@ -679,6 +680,9 @@ g:ale_fix_on_save *g:ale_fix_on_save*
|
||||
after files are fixed, only when the buffer is open, or re-opened. Changes
|
||||
to the file will be saved to the file on disk.
|
||||
|
||||
Fixing files can be disabled or enabled for individual buffers by setting
|
||||
`b:ale_fix_on_save` to `0` or `1`.
|
||||
|
||||
|
||||
g:ale_history_enabled *g:ale_history_enabled*
|
||||
|
||||
|
@ -77,6 +77,7 @@ After:
|
||||
unlet! g:ale_set_lists_synchronously
|
||||
unlet! g:ale_emulate_job_failure
|
||||
unlet! b:ale_fixers
|
||||
unlet! b:ale_fix_on_save
|
||||
delfunction AddCarets
|
||||
delfunction AddDollars
|
||||
delfunction DoNothing
|
||||
@ -412,6 +413,29 @@ Expect(There should be only two lines):
|
||||
a
|
||||
b
|
||||
|
||||
Execute(b:ale_fix_on_save = 1 should override g:ale_fix_on_save = 0):
|
||||
let g:ale_fix_on_save = 0
|
||||
let b:ale_fix_on_save = 1
|
||||
|
||||
let g:ale_fixers.testft = ['RemoveLastLineOneArg']
|
||||
call ale#events#SaveEvent(bufnr(''))
|
||||
|
||||
Expect(There should be only two lines):
|
||||
a
|
||||
b
|
||||
|
||||
Execute(b:ale_fix_on_save = 0 should override g:ale_fix_on_save = 1):
|
||||
let g:ale_fix_on_save = 1
|
||||
let b:ale_fix_on_save = 0
|
||||
|
||||
let g:ale_fixers.testft = ['RemoveLastLineOneArg']
|
||||
call ale#events#SaveEvent(bufnr(''))
|
||||
|
||||
Expect(The lines should be the same):
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
Execute(ALEFix functions returning jobs should be able to accept one argument):
|
||||
if has('win32')
|
||||
" Just skip this test on Windows, we can't run it.
|
||||
|
@ -131,7 +131,13 @@ Execute(ALEToggle should reset everything and then run again):
|
||||
AssertEqual [], getloclist(0), 'The loclist was not cleared'
|
||||
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
|
||||
AssertEqual [], getmatches(), 'The highlights were not cleared'
|
||||
AssertEqual ['ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups()
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'ALECleanupGroup',
|
||||
\ 'ALEHighlightBufferGroup',
|
||||
\ 'ALERunOnSaveGroup',
|
||||
\ ],
|
||||
\ ParseAuGroups()
|
||||
|
||||
" Toggle ALE on, everything should be set up and run again.
|
||||
ALEToggle
|
||||
|
@ -155,32 +155,10 @@ Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
|
||||
\ ],
|
||||
\ CheckAutocmd('ALERunOnFiletypeChangeGroup')
|
||||
|
||||
Execute (g:ale_lint_on_save = 0 should bind no events):
|
||||
let g:ale_lint_on_save = 0
|
||||
let g:ale_fix_on_save = 0
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALERunOnSaveGroup')
|
||||
|
||||
Execute (g:ale_lint_on_save = 1 should bind no events):
|
||||
let g:ale_lint_on_save = 1
|
||||
let g:ale_fix_on_save = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALERunOnSaveGroup')
|
||||
|
||||
Execute (g:ale_lint_on_save = 0 and g:ale_fix_on_save = 1 should bind events):
|
||||
let g:ale_lint_on_save = 0
|
||||
let g:ale_fix_on_save = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALERunOnSaveGroup')
|
||||
|
||||
Execute (g:ale_fix_on_save = 1 should bind events even when ALE is disabled):
|
||||
Execute (The SaveEvent should always be bound):
|
||||
let g:ale_enabled = 0
|
||||
let g:ale_lint_on_save = 0
|
||||
let g:ale_fix_on_save = 1
|
||||
let g:ale_fix_on_save = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
|
@ -1,4 +1,6 @@
|
||||
Before:
|
||||
Save g:ale_fix_on_save
|
||||
Save g:ale_enabled
|
||||
Save g:ale_run_synchronously
|
||||
Save g:ale_set_lists_synchronously
|
||||
Save g:ale_buffer_info
|
||||
@ -7,6 +9,7 @@ Before:
|
||||
let g:ale_buffer_info = {}
|
||||
let g:ale_run_synchronously = 1
|
||||
let g:ale_set_lists_synchronously = 1
|
||||
let b:ale_save_event_fired = 0
|
||||
call ale#ResetLintFileMarkers()
|
||||
|
||||
let g:buffer_result = [
|
||||
@ -261,7 +264,10 @@ Execute(The Save event should respect the buffer number):
|
||||
\], GetSimplerLoclist()
|
||||
|
||||
Execute(The Save event should set b:ale_save_event_fired to 1):
|
||||
let b:ale_enabled = 0
|
||||
let g:ale_lint_on_save = 1
|
||||
let b:ale_enabled = 1
|
||||
|
||||
call ale#linter#Reset()
|
||||
call ale#events#SaveEvent(bufnr(''))
|
||||
|
||||
" This flag needs to be set so windows can be opened, etc.
|
||||
@ -289,3 +295,10 @@ Execute(lint_file linters should stay running after checking without them):
|
||||
AssertEqual 2, len(g:ale_buffer_info[bufnr('')].job_list)
|
||||
|
||||
call ale#engine#WaitForJobs(2000)
|
||||
|
||||
Execute(The save event should not lint the buffer when ALE is disabled):
|
||||
let g:ale_enabled = 0
|
||||
call ale#events#SaveEvent(bufnr(''))
|
||||
|
||||
AssertEqual [], GetSimplerLoclist()
|
||||
AssertEqual 0, b:ale_save_event_fired
|
||||
|
Loading…
Reference in New Issue
Block a user