summaryrefslogtreecommitdiff
path: root/ale_linters/less/lessc.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-11-12 11:35:14 +0000
committerw0rp <devw0rp@gmail.com>2017-11-12 11:35:14 +0000
commit5b3094558bb8e890404c2ea8e65f0fc9a520a322 (patch)
tree5261596fe241c24b6e1550e04f74db8f6dab9ce3 /ale_linters/less/lessc.vim
parent0741612db704b05e6c8da680865febe96d88759b (diff)
parent7edcb2210b2b60d5eaf81381e5d9443369576c28 (diff)
downloadale-5b3094558bb8e890404c2ea8e65f0fc9a520a322.zip
Merge branch 'zanona-less-lessc-linter'
Diffstat (limited to 'ale_linters/less/lessc.vim')
-rwxr-xr-xale_linters/less/lessc.vim56
1 files changed, 56 insertions, 0 deletions
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',
+\})