summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/events.vim10
-rw-r--r--autoload/ale/toggle.vim8
-rw-r--r--doc/ale.txt4
-rw-r--r--test/test_ale_fix.vader24
-rw-r--r--test/test_ale_toggle.vader8
-rw-r--r--test/test_autocmd_commands.vader26
-rw-r--r--test/test_lint_file_linters.vader15
7 files changed, 58 insertions, 37 deletions
diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim
index a7f6b378..c7d17ea5 100644
--- a/autoload/ale/events.vim
+++ b/autoload/ale/events.vim
@@ -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
diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim
index e8cb83a5..6809edd1 100644
--- a/autoload/ale/toggle.vim
+++ b/autoload/ale/toggle.vim
@@ -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
diff --git a/doc/ale.txt b/doc/ale.txt
index 368ba9e8..9b18d3d3 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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*
diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader
index 9968c4a5..fac9a25b 100644
--- a/test/test_ale_fix.vader
+++ b/test/test_ale_fix.vader
@@ -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.
diff --git a/test/test_ale_toggle.vader b/test/test_ale_toggle.vader
index c3bd2f52..a57546fc 100644
--- a/test/test_ale_toggle.vader
+++ b/test/test_ale_toggle.vader
@@ -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
diff --git a/test/test_autocmd_commands.vader b/test/test_autocmd_commands.vader
index 6bc3f5cd..88504a9b 100644
--- a/test/test_autocmd_commands.vader
+++ b/test/test_autocmd_commands.vader
@@ -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>'')))',
diff --git a/test/test_lint_file_linters.vader b/test/test_lint_file_linters.vader
index bea8c3f0..2e992e13 100644
--- a/test/test_lint_file_linters.vader
+++ b/test/test_lint_file_linters.vader
@@ -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