Simplify the code for most linters and tests with closures

This commit is contained in:
w0rp
2018-08-02 23:44:12 +01:00
parent 9ef266d050
commit 217284360d
102 changed files with 631 additions and 1232 deletions
+5
View File
@@ -197,6 +197,11 @@ function! ale#Var(buffer, variable_name) abort
return get(l:vars, l:full_name, g:[l:full_name])
endfunction
" As above, but curry the arguments so only the buffer number is required.
function! ale#VarFunc(variable_name) abort
return {buf -> ale#Var(buf, a:variable_name)}
endfunction
" Initialize a variable with a default value, if it isn't already set.
"
" Every variable name will be prefixed with 'ale_'.
+34 -8
View File
@@ -54,9 +54,14 @@ function! ale#assert#Linter(expected_executable, expected_command) abort
endif
else
let l:command = ale#linter#GetCommand(l:buffer, l:linter)
endif
if type(l:command) is v:t_string
" Replace %e with the escaped executable, so tests keep passing after
" linters are changed to use %e.
let l:command = substitute(l:command, '%e', '\=ale#Escape(l:executable)', 'g')
else
call map(l:command, 'substitute(v:val, ''%e'', ''\=ale#Escape(l:executable)'', ''g'')')
endif
AssertEqual
@@ -126,7 +131,9 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort
execute 'runtime ale_linters/' . a:filetype . '/' . a:name . '.vim'
call ale#test#SetDirectory('/testplugin/test/command_callback')
if !exists('g:dir')
call ale#test#SetDirectory('/testplugin/test/command_callback')
endif
command! -nargs=+ WithChainResults :call ale#assert#WithChainResults(<args>)
command! -nargs=+ AssertLinter :call ale#assert#Linter(<args>)
@@ -140,14 +147,33 @@ function! ale#assert#TearDownLinterTest() abort
unlet! g:ale_create_dummy_temporary_file
let s:chain_results = []
delcommand WithChainResults
delcommand AssertLinter
delcommand AssertLinterNotExecuted
delcommand AssertLSPOptions
delcommand AssertLSPLanguage
delcommand AssertLSPProject
if exists(':WithChainResults')
delcommand WithChainResults
endif
call ale#test#RestoreDirectory()
if exists(':AssertLinter')
delcommand AssertLinter
endif
if exists(':AssertLinterNotExecuted')
delcommand AssertLinterNotExecuted
endif
if exists(':AssertLSPOptions')
delcommand AssertLSPOptions
endif
if exists(':AssertLSPLanguage')
delcommand AssertLSPLanguage
endif
if exists(':AssertLSPProject')
delcommand AssertLSPProject
endif
if exists('g:dir')
call ale#test#RestoreDirectory()
endif
Restore
+1 -1
View File
@@ -256,7 +256,7 @@ function! ale#c#IncludeOptions(include_paths) abort
return ''
endif
return ' ' . join(l:option_list) . ' '
return join(l:option_list)
endfunction
let g:ale_c_build_dir_names = get(g:, 'ale_c_build_dir_names', [
+5
View File
@@ -23,6 +23,11 @@ function! ale#node#FindExecutable(buffer, base_var_name, path_list) abort
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction
" As above, but curry the arguments so only the buffer number is required.
function! ale#node#FindExecutableFunc(base_var_name, path_list) abort
return {buf -> ale#node#FindExecutable(buf, a:base_var_name, a:path_list)}
endfunction
" Create a executable string which executes a Node.js script command with a
" Node.js executable if needed.
"