summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/engine.vim3
-rw-r--r--autoload/ale/linter.vim14
-rw-r--r--test/test_linter_defintion_processing.vader42
-rw-r--r--test/test_linter_retrieval.vader6
4 files changed, 60 insertions, 5 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index eb7780fc..efd5dac1 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -28,6 +28,8 @@ function! ale#engine#InitBufferInfo(buffer) abort
if !has_key(g:ale_buffer_info, a:buffer)
" job_list will hold the list of jobs
" loclist holds the loclist items after all jobs have completed.
+ " lint_file_loclist holds items from the last run including linters
+ " which use the lint_file option.
" new_loclist holds loclist items while jobs are being run.
" temporary_file_list holds temporary files to be cleaned up
" temporary_directory_list holds temporary directories to be cleaned up
@@ -35,6 +37,7 @@ function! ale#engine#InitBufferInfo(buffer) abort
let g:ale_buffer_info[a:buffer] = {
\ 'job_list': [],
\ 'loclist': [],
+ \ 'lint_file_loclist': [],
\ 'new_loclist': [],
\ 'temporary_file_list': [],
\ 'temporary_directory_list': [],
diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim
index cafba2a2..9a838ffa 100644
--- a/autoload/ale/linter.vim
+++ b/autoload/ale/linter.vim
@@ -142,13 +142,25 @@ function! ale#linter#PreProcess(linter) abort
throw "`output_stream` must be 'stdout', 'stderr', or 'both'"
endif
+ " An option indicating that this linter should only be run against the
+ " file on disk.
+ let l:obj.lint_file = get(a:linter, 'lint_file', 0)
+
+ if !s:IsBoolean(l:obj.lint_file)
+ throw '`lint_file` must be `0` or `1`'
+ endif
+
" An option indicating that the buffer should be read.
- let l:obj.read_buffer = get(a:linter, 'read_buffer', 1)
+ let l:obj.read_buffer = get(a:linter, 'read_buffer', !l:obj.lint_file)
if !s:IsBoolean(l:obj.read_buffer)
throw '`read_buffer` must be `0` or `1`'
endif
+ if l:obj.lint_file && l:obj.read_buffer
+ throw 'Only one of `lint_file` or `read_buffer` can be `1`'
+ endif
+
return l:obj
endfunction
diff --git a/test/test_linter_defintion_processing.vader b/test/test_linter_defintion_processing.vader
index 3acc194e..91667e01 100644
--- a/test/test_linter_defintion_processing.vader
+++ b/test/test_linter_defintion_processing.vader
@@ -282,4 +282,44 @@ Execute(PreProcess should set a default value for read_buffer):
\ 'command': 'x',
\}
- AssertEqual ale#linter#PreProcess(g:linter).read_buffer, 1
+ AssertEqual 1, ale#linter#PreProcess(g:linter).read_buffer
+
+Execute(PreProcess should process the lint_file option correctly):
+ let g:linter = {
+ \ 'name': 'x',
+ \ 'callback': 'x',
+ \ 'executable': 'x',
+ \ 'command': 'x',
+ \ 'lint_file': 'x',
+ \}
+
+ AssertThrows call ale#linter#PreProcess(g:linter)
+ AssertEqual '`lint_file` must be `0` or `1`', g:vader_exception
+
+ let g:linter.lint_file = 0
+
+ AssertEqual 0, ale#linter#PreProcess(g:linter).lint_file
+ " The default for read_buffer should be 1 when lint_file is 0
+ AssertEqual 1, ale#linter#PreProcess(g:linter).read_buffer
+
+ let g:linter.lint_file = 1
+
+ AssertEqual 1, ale#linter#PreProcess(g:linter).lint_file
+ " The default for read_buffer should change to 0 when lint_file is 1.
+ AssertEqual 0, ale#linter#PreProcess(g:linter).read_buffer
+
+ let g:linter.read_buffer = 1
+
+ " We shouldn't be able to set both options to 1 at the same time.
+ AssertThrows call ale#linter#PreProcess(g:linter)
+ AssertEqual 'Only one of `lint_file` or `read_buffer` can be `1`', g:vader_exception
+
+Execute(PreProcess should set a default value for lint_file):
+ let g:linter = {
+ \ 'name': 'x',
+ \ 'callback': 'x',
+ \ 'executable': 'x',
+ \ 'command': 'x',
+ \}
+
+ AssertEqual 0, ale#linter#PreProcess(g:linter).lint_file
diff --git a/test/test_linter_retrieval.vader b/test/test_linter_retrieval.vader
index bc5b62ef..e0d6c284 100644
--- a/test/test_linter_retrieval.vader
+++ b/test/test_linter_retrieval.vader
@@ -1,6 +1,6 @@
Before:
- let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1}
- let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0}
+ let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout', 'read_buffer': 1, 'lint_file': 0}
+ let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout', 'read_buffer': 0, 'lint_file': 1}
call ale#linter#Reset()
let g:ale_linters = {}
@@ -40,4 +40,4 @@ Then (Linters for dot-seperated filetypes should be properly handled):
AssertEqual [g:testlinter1, g:testlinter2], ale#linter#Get('testft1.testft2')
Execute (Try to load a linter from disk):
- AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1}], ale#linter#Get('testft')
+ AssertEqual [{'name': 'testlinter', 'output_stream': 'stdout', 'executable': 'testlinter', 'command': 'testlinter', 'callback': 'testCB', 'read_buffer': 1, 'lint_file': 0}], ale#linter#Get('testft')