Use the configured mdl executable, escape it in the command, and add test for it

This commit is contained in:
w0rp 2018-03-03 13:27:19 +00:00
parent 857723e7d5
commit 565ffa0dc5
2 changed files with 41 additions and 9 deletions

View File

@ -4,6 +4,18 @@
call ale#Set('markdown_mdl_executable', 'mdl') call ale#Set('markdown_mdl_executable', 'mdl')
call ale#Set('markdown_mdl_options', '') 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 function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
" matches: '(stdin):173: MD004 Unordered list style' " matches: '(stdin):173: MD004 Unordered list style'
let l:pattern = ':\(\d*\): \(.*\)$' let l:pattern = ':\(\d*\): \(.*\)$'
@ -20,17 +32,9 @@ function! ale_linters#markdown#mdl#Handle(buffer, lines) abort
return l:output return l:output
endfunction 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', { call ale#linter#Define('markdown', {
\ 'name': 'mdl', \ 'name': 'mdl',
\ 'executable': 'mdl', \ 'executable_callback': 'ale_linters#markdown#mdl#GetExecutable',
\ 'command_callback': 'ale_linters#markdown#mdl#GetCommand', \ 'command_callback': 'ale_linters#markdown#mdl#GetCommand',
\ 'callback': 'ale_linters#markdown#mdl#Handle' \ 'callback': 'ale_linters#markdown#mdl#Handle'
\}) \})

View File

@ -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'