Syntaxerl linter feature check (#861)

* Add feature check for SyntaxErl linter

* Escape SyntaxErl executable path in commands
This commit is contained in:
Dmitri Vereshchagin 2017-08-19 20:54:23 +03:00 committed by w0rp
parent 20e64fbae0
commit b2d3764a18
3 changed files with 47 additions and 32 deletions

View File

@ -2,7 +2,6 @@
" Description: SyntaxErl linter for Erlang files " Description: SyntaxErl linter for Erlang files
call ale#Set('erlang_syntaxerl_executable', 'syntaxerl') call ale#Set('erlang_syntaxerl_executable', 'syntaxerl')
call ale#Set('erlang_syntaxerl_use_basename', 0)
function! ale_linters#erlang#syntaxerl#GetExecutable(buffer) abort function! ale_linters#erlang#syntaxerl#GetExecutable(buffer) abort
@ -10,14 +9,15 @@ function! ale_linters#erlang#syntaxerl#GetExecutable(buffer) abort
endfunction endfunction
function! ale_linters#erlang#syntaxerl#GetCommand(buffer) abort function! ale_linters#erlang#syntaxerl#FeatureCheck(buffer) abort
let l:base_options = ale#Var(a:buffer, 'erlang_syntaxerl_use_basename') return s:GetEscapedExecutable(a:buffer) . ' -h'
\ ? ' -b %s' endfunction
\ : ''
return ale_linters#erlang#syntaxerl#GetExecutable(a:buffer)
\ . l:base_options function! ale_linters#erlang#syntaxerl#GetCommand(buffer, output) abort
\ . ' %t' let l:use_b_option = match(a:output, '\C\V-b, --base\>') > -1
return s:GetEscapedExecutable(a:buffer) . (l:use_b_option ? ' -b %s %t' : ' %t')
endfunction endfunction
@ -37,9 +37,17 @@ function! ale_linters#erlang#syntaxerl#Handle(buffer, lines) abort
endfunction endfunction
function! s:GetEscapedExecutable(buffer) abort
return ale#Escape(ale_linters#erlang#syntaxerl#GetExecutable(a:buffer))
endfunction
call ale#linter#Define('erlang', { call ale#linter#Define('erlang', {
\ 'name': 'syntaxerl', \ 'name': 'syntaxerl',
\ 'executable_callback': 'ale_linters#erlang#syntaxerl#GetExecutable', \ 'executable_callback': 'ale_linters#erlang#syntaxerl#GetExecutable',
\ 'command_callback': 'ale_linters#erlang#syntaxerl#GetCommand', \ 'command_chain': [
\ {'callback': 'ale_linters#erlang#syntaxerl#FeatureCheck'},
\ {'callback': 'ale_linters#erlang#syntaxerl#GetCommand'},
\ ],
\ 'callback': 'ale_linters#erlang#syntaxerl#Handle', \ 'callback': 'ale_linters#erlang#syntaxerl#Handle',
\}) \})

View File

@ -25,17 +25,5 @@ g:ale_erlang_syntaxerl_executable *g:ale_erlang_syntaxerl_executable*
This variable can be changed to specify the syntaxerl executable. This variable can be changed to specify the syntaxerl executable.
g:ale_erlang_syntaxerl_use_basename *g:ale_erlang_syntaxerl_use_basename*
*b:ale_erlang_syntaxerl_use_basename*
Type: |Number|
Default: `0`
When set to `1`, the `-b` argument for telling SyntaxErl about the path to the
file being checked will be used. The argument is only available in newer
versions of SyntaxErl.
This option will be enabled by default in future.
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View File

@ -1,20 +1,19 @@
Before: Before:
Save g:ale_erlang_syntaxerl_executable Save g:ale_erlang_syntaxerl_executable
Save g:ale_erlang_syntaxerl_use_basename
unlet! g:ale_erlang_syntaxerl_executable unlet! g:ale_erlang_syntaxerl_executable
unlet! b:ale_erlang_syntaxerl_executable unlet! b:ale_erlang_syntaxerl_executable
unlet! b:ale_erlang_syntaxerl_use_basename
runtime ale_linters/erlang/syntaxerl.vim runtime ale_linters/erlang/syntaxerl.vim
After: After:
Restore Restore
call ale#linter#Reset() call ale#linter#Reset()
Execute (The SyntaxErl executable should be correct): Execute (The executable should be correct):
AssertEqual 'syntaxerl', ale_linters#erlang#syntaxerl#GetExecutable(bufnr('')) AssertEqual 'syntaxerl', ale_linters#erlang#syntaxerl#GetExecutable(bufnr(''))
let g:ale_erlang_syntaxerl_executable = '/some/other/syntaxerl' let g:ale_erlang_syntaxerl_executable = '/some/other/syntaxerl'
@ -23,17 +22,37 @@ Execute (The SyntaxErl executable should be correct):
let b:ale_erlang_syntaxerl_executable = '/yet/another/syntaxerl' let b:ale_erlang_syntaxerl_executable = '/yet/another/syntaxerl'
AssertEqual '/yet/another/syntaxerl', ale_linters#erlang#syntaxerl#GetExecutable(bufnr('')) AssertEqual '/yet/another/syntaxerl', ale_linters#erlang#syntaxerl#GetExecutable(bufnr(''))
Execute (The default SyntaxErl command should be correct):
AssertEqual 'syntaxerl %t', ale_linters#erlang#syntaxerl#GetCommand(bufnr(''))
Execute (The executable name should be used in the command): Execute (The executable should be presented in the feature check command):
let g:ale_erlang_syntaxerl_executable = '/some/other/syntaxerl' let g:ale_erlang_syntaxerl_executable = '/some/other/syntaxerl'
AssertEqual '/some/other/syntaxerl %t', ale_linters#erlang#syntaxerl#GetCommand(bufnr('')) AssertEqual "'/some/other/syntaxerl' -h", ale_linters#erlang#syntaxerl#FeatureCheck(bufnr(''))
let b:ale_erlang_syntaxerl_executable = '/yet/another/syntaxerl' let b:ale_erlang_syntaxerl_executable = '/yet/another/syntaxerl'
AssertEqual '/yet/another/syntaxerl %t', ale_linters#erlang#syntaxerl#GetCommand(bufnr('')) AssertEqual "'/yet/another/syntaxerl' -h", ale_linters#erlang#syntaxerl#FeatureCheck(bufnr(''))
Execute (The basename option should be set when the option is on):
let b:ale_erlang_syntaxerl_use_basename = 1
AssertEqual 'syntaxerl -b %s %t', ale_linters#erlang#syntaxerl#GetCommand(bufnr('')) Execute (The executable should be presented in the command):
let g:ale_erlang_syntaxerl_executable = '/some/other/syntaxerl'
AssertEqual "'/some/other/syntaxerl' %t", ale_linters#erlang#syntaxerl#GetCommand(bufnr(''), [])
let b:ale_erlang_syntaxerl_executable = '/yet/another/syntaxerl'
AssertEqual "'/yet/another/syntaxerl' %t", ale_linters#erlang#syntaxerl#GetCommand(bufnr(''), [])
Execute (The -b option should be used when available):
AssertEqual "'syntaxerl' %t", ale_linters#erlang#syntaxerl#GetCommand(bufnr(''), [
\ 'Syntax checker for Erlang (0.14.0)',
\ 'Usage: syntaxerl [-d | --debug] <FILENAME>',
\ ' syntaxerl <-h | --help>',
\ ' -d, --debug Enable debug output',
\ ' -h, --help Show this message',
\ ])
AssertEqual "'syntaxerl' -b %s %t", ale_linters#erlang#syntaxerl#GetCommand(bufnr(''), [
\ 'Syntax checker for Erlang (0.14.0)',
\ 'Usage: syntaxerl [-b | --base <FILENAME>] [-d | --debug] <FILENAME>',
\ ' syntaxerl <-h | --help>',
\ ' -b, --base Set original filename',
\ ' -d, --debug Enable debug output',
\ ' -h, --help Show this message',
\ ])