Add tests for the command and executable callbacks, and make them use local node_modulse esxecutables like other linters
This commit is contained in:
parent
3aff1df961
commit
cd5da50531
@ -1,12 +1,25 @@
|
||||
" Author: zanona <https://github.com/zanona>
|
||||
" Author: zanona <https://github.com/zanona>, w0rp <devw0rp@gmail.com>
|
||||
" Description: This file adds support for checking Less code with lessc.
|
||||
|
||||
call ale#Set('less_lessc_executable', 'lessc')
|
||||
call ale#Set('less_lessc_options', '')
|
||||
call ale#Set('less_lessc_use_global', 0)
|
||||
|
||||
function! ale_linters#less#lessc#GetExecutable(buffer) abort
|
||||
return ale#node#FindExecutable(a:buffer, 'less_lessc', [
|
||||
\ 'node_modules/.bin/lessc',
|
||||
\])
|
||||
endfunction
|
||||
|
||||
function! ale_linters#less#lessc#GetCommand(buffer) abort
|
||||
return 'lessc'
|
||||
\ . ' --no-color --lint --include-path=' . expand('%:p:h')
|
||||
\ . ' ' . ale#Var(a:buffer, 'less_lessc_options')
|
||||
let l:executable = ale_linters#less#lessc#GetExecutable(a:buffer)
|
||||
let l:dir = expand('#' . a:buffer . ':p:h')
|
||||
let l:options = ale#Var(a:buffer, 'less_lessc_options')
|
||||
|
||||
return ale#Escape(l:executable)
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path=' . ale#Escape(l:dir)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' -'
|
||||
endfunction
|
||||
|
||||
@ -29,8 +42,8 @@ endfunction
|
||||
|
||||
call ale#linter#Define('less', {
|
||||
\ 'name': 'lessc',
|
||||
\ 'executable': 'lessc',
|
||||
\ 'output_stream': 'stderr',
|
||||
\ 'executable_callback': 'ale_linters#less#lessc#GetExecutable',
|
||||
\ 'command_callback': 'ale_linters#less#lessc#GetCommand',
|
||||
\ 'callback': 'ale_linters#less#lessc#Handle',
|
||||
\ 'output_stream': 'stderr',
|
||||
\})
|
||||
|
@ -5,6 +5,14 @@ ALE Less Integration *ale-less-options*
|
||||
===============================================================================
|
||||
lessc *ale-less-lessc*
|
||||
|
||||
g:ale_less_lessc_executable *g:ale_less_lessc_executable*
|
||||
*b:ale_less_lessc_executable*
|
||||
Type: |String|
|
||||
Default: `'lessc'`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
g:ale_less_lessc_options *g:ale_less_lessc_options*
|
||||
*b:ale_less_lessc_options*
|
||||
Type: |String|
|
||||
@ -13,6 +21,14 @@ g:ale_less_lessc_options *g:ale_less_lessc_options*
|
||||
This variable can be set to pass additional options to lessc.
|
||||
|
||||
|
||||
g:ale_less_lessc_use_global *g:ale_less_lessc_use_global*
|
||||
*b:ale_less_lessc_use_global*
|
||||
Type: |String|
|
||||
Default: `0`
|
||||
|
||||
See |ale-integrations-local-executables|
|
||||
|
||||
|
||||
===============================================================================
|
||||
prettier *ale-less-prettier*
|
||||
|
||||
@ -20,4 +36,4 @@ See |ale-javascript-prettier| for information about the available options.
|
||||
|
||||
|
||||
===============================================================================
|
||||
|
||||
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:
|
||||
|
@ -105,7 +105,7 @@ CONTENTS *ale-contents*
|
||||
latex.................................|ale-latex-options|
|
||||
write-good..........................|ale-latex-write-good|
|
||||
less..................................|ale-less-options|
|
||||
lessc...............................|ale-less-lessc-options|
|
||||
lessc...............................|ale-less-lessc|
|
||||
prettier............................|ale-less-prettier|
|
||||
llvm..................................|ale-llvm-options|
|
||||
llc.................................|ale-llvm-llc|
|
||||
|
0
test/command_callback/lessc_paths/node_modules/.bin/lessc
generated
vendored
Executable file
0
test/command_callback/lessc_paths/node_modules/.bin/lessc
generated
vendored
Executable file
82
test/command_callback/test_lessc_command_callback.vader
Normal file
82
test/command_callback/test_lessc_command_callback.vader
Normal file
@ -0,0 +1,82 @@
|
||||
Before:
|
||||
Save g:ale_less_lessc_executable
|
||||
Save g:ale_less_lessc_use_global
|
||||
Save g:ale_less_lessc_options
|
||||
|
||||
unlet! b:executable
|
||||
|
||||
unlet! g:ale_less_lessc_executable
|
||||
unlet! g:ale_less_lessc_use_global
|
||||
unlet! g:ale_less_lessc_options
|
||||
|
||||
call ale#test#SetDirectory('/testplugin/test/command_callback')
|
||||
call ale#test#SetFilename('testfile.less')
|
||||
|
||||
runtime ale_linters/less/lessc.vim
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:executable
|
||||
unlet! b:ale_less_lessc_executable
|
||||
unlet! b:ale_less_lessc_use_global
|
||||
unlet! b:ale_less_lessc_options
|
||||
|
||||
call ale#test#SetFilename('test.txt')
|
||||
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#linter#Reset()
|
||||
|
||||
Execute(node_modules directories should be discovered):
|
||||
call ale#test#SetFilename('lessc_paths/nested/testfile.less')
|
||||
|
||||
let b:executable = ale#path#Winify(
|
||||
\ g:dir
|
||||
\ . '/lessc_paths/node_modules/.bin/lessc'
|
||||
\)
|
||||
|
||||
AssertEqual
|
||||
\ b:executable,
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape(b:executable)
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir . '/lessc_paths/nested'))
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
||||
|
||||
Execute(The global override should work):
|
||||
let b:ale_less_lessc_executable = 'foobar'
|
||||
let b:ale_less_lessc_use_global = 1
|
||||
|
||||
call ale#test#SetFilename('lessc_paths/nested/testfile.less')
|
||||
|
||||
AssertEqual
|
||||
\ 'foobar',
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('foobar')
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir . '/lessc_paths/nested'))
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
||||
|
||||
Execute(Extra options should be configurable):
|
||||
let b:ale_less_lessc_options = '--whatever'
|
||||
|
||||
AssertEqual
|
||||
\ 'lessc',
|
||||
\ ale_linters#less#lessc#GetExecutable(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ ale#Escape('lessc')
|
||||
\ . ' --no-color --lint'
|
||||
\ . ' --include-path='
|
||||
\ . ale#Escape(ale#path#Winify(g:dir))
|
||||
\ . ' --whatever'
|
||||
\ . ' -',
|
||||
\ ale_linters#less#lessc#GetCommand(bufnr(''))
|
Loading…
Reference in New Issue
Block a user