summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rwxr-xr-xale_linters/less/lessc.vim56
-rw-r--r--doc/ale-less.txt29
-rw-r--r--doc/ale.txt2
-rwxr-xr-xtest/command_callback/lessc_paths/node_modules/.bin/lessc0
-rw-r--r--test/command_callback/test_lessc_command_callback.vader82
-rw-r--r--test/handler/test_lessc_handler.vader69
7 files changed, 238 insertions, 1 deletions
diff --git a/README.md b/README.md
index 2a74d858..24f3deb0 100644
--- a/README.md
+++ b/README.md
@@ -109,6 +109,7 @@ formatting.
| JSON | [jsonlint](http://zaa.ch/jsonlint/), [prettier](https://github.com/prettier/prettier) |
| Kotlin | [kotlinc](https://kotlinlang.org) !!, [ktlint](https://ktlint.github.io) !! see `:help ale-integration-kotlin` for configuration instructions |
| LaTeX | [chktex](http://www.nongnu.org/chktex/), [lacheck](https://www.ctan.org/pkg/lacheck), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) |
+| Less | [lessc](https://www.npmjs.com/package/less) |
| LLVM | [llc](https://llvm.org/docs/CommandGuide/llc.html) |
| Lua | [luacheck](https://github.com/mpeterv/luacheck) |
| Mail | [proselint](http://proselint.com/), [vale](https://github.com/ValeLint/vale) |
diff --git a/ale_linters/less/lessc.vim b/ale_linters/less/lessc.vim
new file mode 100755
index 00000000..108679de
--- /dev/null
+++ b/ale_linters/less/lessc.vim
@@ -0,0 +1,56 @@
+" 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
+ 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
+
+function! ale_linters#less#lessc#Handle(buffer, lines) abort
+ let l:dir = expand('#' . a:buffer . ':p:h')
+ " Matches patterns like the following:
+ let l:pattern = '^\(\w\+\): \(.\{-}\) in \(.\{-}\) on line \(\d\+\), column \(\d\+\):$'
+ let l:output = []
+
+ for l:match in ale#util#GetMatches(a:lines, l:pattern)
+ let l:item = {
+ \ 'lnum': l:match[4] + 0,
+ \ 'col': l:match[5] + 0,
+ \ 'text': l:match[2],
+ \ 'type': 'E',
+ \}
+
+ if l:match[3] isnot# '-'
+ let l:item.filename = ale#path#GetAbsPath(l:dir, l:match[3])
+ endif
+
+ call add(l:output, l:item)
+ endfor
+
+ return l:output
+endfunction
+
+call ale#linter#Define('less', {
+\ 'name': 'lessc',
+\ '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 a6b5998e..a372afe0 100644
--- a/doc/ale-less.txt
+++ b/doc/ale-less.txt
@@ -3,10 +3,37 @@ 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|
+ Default: `''`
+
+ 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*
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 ae692698..ff38cbbe 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -105,6 +105,7 @@ CONTENTS *ale-contents*
latex.................................|ale-latex-options|
write-good..........................|ale-latex-write-good|
less..................................|ale-less-options|
+ lessc...............................|ale-less-lessc|
prettier............................|ale-less-prettier|
llvm..................................|ale-llvm-options|
llc.................................|ale-llvm-llc|
@@ -297,6 +298,7 @@ Notes:
* JSON: `jsonlint`, `prettier`
* Kotlin: `kotlinc`, `ktlint`
* LaTeX (tex): `chktex`, `lacheck`, `proselint`, `write-good`
+* Less: `lessc`
* LLVM: `llc`
* Lua: `luacheck`
* Mail: `proselint`, `vale`
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
--- /dev/null
+++ b/test/command_callback/lessc_paths/node_modules/.bin/lessc
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(''))
diff --git a/test/handler/test_lessc_handler.vader b/test/handler/test_lessc_handler.vader
new file mode 100644
index 00000000..530c5824
--- /dev/null
+++ b/test/handler/test_lessc_handler.vader
@@ -0,0 +1,69 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test/handler')
+ call ale#test#SetFilename('testfile.less')
+
+ runtime ale_linters/less/lessc.vim
+
+After:
+ call ale#test#RestoreDirectory()
+ call ale#linter#Reset()
+
+Execute(The lessc handler should handle errors for the current file correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'type': 'E',
+ \ 'text': 'Unrecognised input. Possibly missing something',
+ \ },
+ \ ],
+ \ ale_linters#less#lessc#Handle(bufnr(''), [
+ \ 'ParseError: Unrecognised input. Possibly missing something in - on line 2, column 1:',
+ \ '1 vwewww',
+ \ '2 ',
+ \])
+
+Execute(The lessc handler should handle errors for other files in the same directory correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'type': 'E',
+ \ 'text': 'Unrecognised input. Possibly missing something',
+ \ 'filename': ale#path#Winify(g:dir . '/imported.less')
+ \ },
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'type': 'E',
+ \ 'text': 'Unrecognised input. Possibly missing something',
+ \ 'filename': ale#path#Winify(g:dir . '/imported.less')
+ \ },
+ \ ],
+ \ ale_linters#less#lessc#Handle(bufnr(''), [
+ \ 'ParseError: Unrecognised input. Possibly missing something in imported.less on line 2, column 1:',
+ \ '1 vwewww',
+ \ '2 ',
+ \ 'ParseError: Unrecognised input. Possibly missing something in ./imported.less on line 2, column 1:',
+ \ '1 vwewww',
+ \ '2 ',
+ \])
+
+Execute(The lessc handler should handle errors for files in directories above correctly):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 1,
+ \ 'type': 'E',
+ \ 'text': 'Unrecognised input. Possibly missing something',
+ \ 'filename': ale#path#Winify(g:dir . '/../imported2.less')
+ \ },
+ \ ],
+ \ ale_linters#less#lessc#Handle(bufnr(''), [
+ \ 'ParseError: Unrecognised input. Possibly missing something in ../imported2.less on line 2, column 1:',
+ \ '1 vwewww',
+ \ '2 ',
+ \])