summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-03-03 13:27:19 +0000
committerw0rp <devw0rp@gmail.com>2018-03-03 13:27:19 +0000
commit565ffa0dc5e2fe53663f7228c05ad927c190b9e6 (patch)
tree53f894eee6a185a46746b528f969d139e4785a37
parent857723e7d569c8260d95d2ce261fbf064e5bfa9f (diff)
downloadale-565ffa0dc5e2fe53663f7228c05ad927c190b9e6.zip
Use the configured mdl executable, escape it in the command, and add test for it
-rw-r--r--ale_linters/markdown/mdl.vim22
-rw-r--r--test/command_callback/test_markdown_mdl_command_callback.vader28
2 files changed, 41 insertions, 9 deletions
diff --git a/ale_linters/markdown/mdl.vim b/ale_linters/markdown/mdl.vim
index 9bb20318..16b08cc5 100644
--- a/ale_linters/markdown/mdl.vim
+++ b/ale_linters/markdown/mdl.vim
@@ -4,6 +4,18 @@
call ale#Set('markdown_mdl_executable', 'mdl')
call ale#Set('markdown_mdl_options', '')
+function! ale_linters#markdown#mdl#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'markdown_mdl_executable')
+endfunction
+
+function! ale_linters#markdown#mdl#GetCommand(buffer) abort
+ let l:executable = ale_linters#markdown#mdl#GetExecutable(a:buffer)
+ let l:options = ale#Var(a:buffer, 'markdown_mdl_options')
+
+ return ale#Escape(l:executable)
+ \ . (!empty(l:options) ? ' ' . l:options : '')
+endfunction
+
function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
" matches: '(stdin):173: MD004 Unordered list style'
let l:pattern = ':\(\d*\): \(.*\)$'
@@ -20,17 +32,9 @@ function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
return l:output
endfunction
-function! ale_linters#markdown#mdl#GetCommand(buffer) abort
- let l:executable = ale#Var(a:buffer, 'markdown_mdl_executable')
- let l:options = ale#Var(a:buffer, 'markdown_mdl_options')
-
- return l:executable . (!empty(l:options) ? ' ' . l:options : '')
-endfunction
-
-
call ale#linter#Define('markdown', {
\ 'name': 'mdl',
-\ 'executable': 'mdl',
+\ 'executable_callback': 'ale_linters#markdown#mdl#GetExecutable',
\ 'command_callback': 'ale_linters#markdown#mdl#GetCommand',
\ 'callback': 'ale_linters#markdown#mdl#Handle'
\})
diff --git a/test/command_callback/test_markdown_mdl_command_callback.vader b/test/command_callback/test_markdown_mdl_command_callback.vader
new file mode 100644
index 00000000..3a68a4b2
--- /dev/null
+++ b/test/command_callback/test_markdown_mdl_command_callback.vader
@@ -0,0 +1,28 @@
+Before:
+ Save g:ale_markdown_mdl_executable
+ Save g:ale_markdown_mdl_options
+
+ unlet! g:ale_markdown_mdl_executable
+ unlet! g:ale_markdown_mdl_options
+
+ runtime ale_linters/markdown/mdl.vim
+
+After:
+ Restore
+
+ call ale#linter#Reset()
+
+Execute(The default command should be correct):
+ AssertEqual ale_linters#markdown#mdl#GetExecutable(bufnr('')), 'mdl'
+ AssertEqual
+ \ ale_linters#markdown#mdl#GetCommand(bufnr('')),
+ \ ale#Escape('mdl')
+
+Execute(The executable and options should be configurable):
+ let g:ale_markdown_mdl_executable = 'foo bar'
+ let g:ale_markdown_mdl_options = '--wat'
+
+ AssertEqual ale_linters#markdown#mdl#GetExecutable(bufnr('')), 'foo bar'
+ AssertEqual
+ \ ale_linters#markdown#mdl#GetCommand(bufnr('')),
+ \ ale#Escape('foo bar') . ' --wat'