mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-06 12:44:23 +08:00
Add --globals vim to luacheck automatically
luacheck will run with `--globals vim` automatically if the file is in runtimepath and `--globals` hasn't already been configured.
This commit is contained in:
@@ -4,8 +4,43 @@
|
|||||||
call ale#Set('lua_luacheck_executable', 'luacheck')
|
call ale#Set('lua_luacheck_executable', 'luacheck')
|
||||||
call ale#Set('lua_luacheck_options', '')
|
call ale#Set('lua_luacheck_options', '')
|
||||||
|
|
||||||
|
function! s:IsInRuntimepath(buffer) abort
|
||||||
|
let l:runtimepath_dirs = split(&runtimepath, ',')
|
||||||
|
|
||||||
|
for l:dir in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
|
||||||
|
for l:runtime_dir in l:runtimepath_dirs
|
||||||
|
if l:dir is# l:runtime_dir
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! ale_linters#lua#luacheck#GetCommand(buffer) abort
|
function! ale_linters#lua#luacheck#GetCommand(buffer) abort
|
||||||
return '%e' . ale#Pad(ale#Var(a:buffer, 'lua_luacheck_options'))
|
let l:options = ale#Var(a:buffer, 'lua_luacheck_options')
|
||||||
|
|
||||||
|
" Add `--globals vim` by default if the file is in runtimepath.
|
||||||
|
if l:options !~# '--globals'
|
||||||
|
let l:in_runtime = getbufvar(a:buffer, 'ale_in_runtimepath', v:null)
|
||||||
|
|
||||||
|
if l:in_runtime is v:null
|
||||||
|
let l:in_runtime = s:IsInRuntimepath(a:buffer)
|
||||||
|
" Save the result of check this buffer so we only check once.
|
||||||
|
call setbufvar(a:buffer, 'ale_in_runtimepath', l:in_runtime)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if l:in_runtime
|
||||||
|
if !empty(l:options)
|
||||||
|
let l:options .= ' '
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:options .= '--globals vim'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
return '%e' . ale#Pad(l:options)
|
||||||
\ . ' --formatter plain --codes --filename %s -'
|
\ . ' --formatter plain --codes --filename %s -'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
Before:
|
Before:
|
||||||
call ale#assert#SetUpLinterTest('lua', 'luacheck')
|
call ale#assert#SetUpLinterTest('lua', 'luacheck')
|
||||||
|
" Default to testing linting Lua not in Vim directories.
|
||||||
|
call ale#test#SetFilename('/test.lua')
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
" Clear the variable for saving the result of the runtime check.
|
||||||
|
" We don't want to cache the result between tests.
|
||||||
|
unlet! b:ale_in_runtimepath
|
||||||
call ale#assert#TearDownLinterTest()
|
call ale#assert#TearDownLinterTest()
|
||||||
|
|
||||||
Execute(The lua luacheck command callback should return the correct default string):
|
Execute(The luacheck default command should be correct):
|
||||||
AssertLinter 'luacheck',
|
AssertLinter 'luacheck',
|
||||||
\ ale#Escape('luacheck') . ' --formatter plain --codes --filename %s -'
|
\ ale#Escape('luacheck') . ' --formatter plain --codes --filename %s -'
|
||||||
|
|
||||||
Execute(The lua luacheck command callback should let you set options):
|
Execute(You should be able to set luacheck options):
|
||||||
let g:ale_lua_luacheck_options = '--config filename'
|
let g:ale_lua_luacheck_options = '--config filename'
|
||||||
|
|
||||||
AssertLinter 'luacheck',
|
AssertLinter 'luacheck',
|
||||||
@@ -21,3 +26,14 @@ Execute(The luacheck executable should be configurable):
|
|||||||
|
|
||||||
AssertLinter 'luacheck.sh',
|
AssertLinter 'luacheck.sh',
|
||||||
\ ale#Escape('luacheck.sh') . ' --formatter plain --codes --filename %s -'
|
\ ale#Escape('luacheck.sh') . ' --formatter plain --codes --filename %s -'
|
||||||
|
|
||||||
|
Execute(The luacheck command should include vim as a global if in runtimepath):
|
||||||
|
call ale#test#SetFilename('test.lua')
|
||||||
|
AssertLinter 'luacheck',
|
||||||
|
\ ale#Escape('luacheck') . ' --globals vim --formatter plain --codes --filename %s -'
|
||||||
|
|
||||||
|
Execute(The default Vim globals should not be set if globals are already set):
|
||||||
|
call ale#test#SetFilename('test.lua')
|
||||||
|
let g:ale_lua_luacheck_options = '--globals foo'
|
||||||
|
AssertLinter 'luacheck',
|
||||||
|
\ ale#Escape('luacheck') . ' --globals foo --formatter plain --codes --filename %s -'
|
||||||
|
|||||||
Reference in New Issue
Block a user