summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/events.vim8
-rw-r--r--doc/ale.txt4
-rw-r--r--test/sign/test_sign_placement.vader3
-rw-r--r--test/test_lint_on_filetype_changed.vader27
4 files changed, 41 insertions, 1 deletions
diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim
index a3b74677..efae11c1 100644
--- a/autoload/ale/events.vim
+++ b/autoload/ale/events.vim
@@ -33,7 +33,13 @@ endfunction
function! ale#events#FileTypeEvent(buffer, new_filetype) abort
let l:filetype = getbufvar(a:buffer, 'ale_original_filetype', '')
- if a:new_filetype isnot# l:filetype
+ " If we're setting the filetype for the first time after it was blank,
+ " and the option for linting on enter is off, then we should set this
+ " filetype as the original filetype. Otherwise ALE will still appear to
+ " lint files because of the BufEnter event, etc.
+ if empty(l:filetype) && !ale#Var(a:buffer, 'lint_on_enter')
+ call setbufvar(a:buffer, 'ale_original_filetype', a:new_filetype)
+ elseif a:new_filetype isnot# l:filetype
call ale#Queue(300, 'lint_file', a:buffer)
endif
endfunction
diff --git a/doc/ale.txt b/doc/ale.txt
index 362171cb..fe91d4da 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -683,6 +683,10 @@ g:ale_lint_on_filetype_changed *g:ale_lint_on_filetype_changed*
changed quickly several times in a row, but resulting in only one lint
cycle.
+ If |g:ale_lint_on_enter| is set to `0`, then ALE will not lint a file when
+ the filetype is initially set. Otherwise ALE would still lint files when
+ buffers are opened, and the option for doing so is turned off.
+
g:ale_lint_on_save *g:ale_lint_on_save*
diff --git a/test/sign/test_sign_placement.vader b/test/sign/test_sign_placement.vader
index abae765b..bb29b643 100644
--- a/test/sign/test_sign_placement.vader
+++ b/test/sign/test_sign_placement.vader
@@ -3,6 +3,9 @@ Before:
let g:ale_set_signs = 1
+ call ale#linter#Reset()
+ sign unplace *
+
function! GenerateResults(buffer, output)
return [
\ {
diff --git a/test/test_lint_on_filetype_changed.vader b/test/test_lint_on_filetype_changed.vader
index 44446ef0..591a5120 100644
--- a/test/test_lint_on_filetype_changed.vader
+++ b/test/test_lint_on_filetype_changed.vader
@@ -3,6 +3,8 @@ Before:
let g:queue_calls = []
+ unlet! b:ale_lint_on_enter
+
function! ale#Queue(...)
call add(g:queue_calls, a:000)
endfunction
@@ -10,6 +12,7 @@ Before:
After:
Restore
+ unlet! b:ale_lint_on_enter
unlet! g:queue_calls
" Reload the ALE code to load the real function again.
@@ -45,3 +48,27 @@ Execute(Linting should be queued when the filetype changes):
call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
AssertEqual [[300, 'lint_file', bufnr('')]], g:queue_calls
+
+Execute(Linting shouldn't be done when the original filetype was blank and linting on enter is off):
+ let b:ale_lint_on_enter = 0
+ let b:ale_original_filetype = ''
+
+ call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
+
+ AssertEqual [], g:queue_calls
+
+Execute(Linting should be done when the original filetype was blank and linting on enter is on):
+ let b:ale_lint_on_enter = 1
+ let b:ale_original_filetype = ''
+
+ call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
+
+ AssertEqual [[300, 'lint_file', bufnr('')]], g:queue_calls
+
+Execute(The new filetype should become the "original" one if the original was blank and linting on enter is off):
+ let b:ale_lint_on_enter = 0
+ let b:ale_original_filetype = ''
+
+ call ale#events#FileTypeEvent(bufnr(''), 'bazboz')
+
+ AssertEqual 'bazboz', b:ale_original_filetype