diff --git a/ale_linters/less/lessc.vim b/ale_linters/less/lessc.vim index 76b7f133..8b7985a3 100755 --- a/ale_linters/less/lessc.vim +++ b/ale_linters/less/lessc.vim @@ -1,12 +1,25 @@ -" Author: zanona +" Author: zanona , w0rp " 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', \}) diff --git a/doc/ale-less.txt b/doc/ale-less.txt index cac9c9af..a372afe0 100644 --- a/doc/ale-less.txt +++ b/doc/ale-less.txt @@ -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: diff --git a/doc/ale.txt b/doc/ale.txt index 41e96618..ff38cbbe 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -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| diff --git a/test/command_callback/lessc_paths/node_modules/.bin/lessc b/test/command_callback/lessc_paths/node_modules/.bin/lessc new file mode 100755 index 00000000..e69de29b diff --git a/test/command_callback/test_lessc_command_callback.vader b/test/command_callback/test_lessc_command_callback.vader new file mode 100644 index 00000000..785c38c0 --- /dev/null +++ b/test/command_callback/test_lessc_command_callback.vader @@ -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(''))