2017-11-12 06:25:24 -05:00
|
|
|
" Author: zanona <https://github.com/zanona>, w0rp <devw0rp@gmail.com>
|
2017-11-09 06:49:44 -05:00
|
|
|
" Description: This file adds support for checking Less code with lessc.
|
|
|
|
|
2017-11-12 06:25:24 -05:00
|
|
|
call ale#Set('less_lessc_executable', 'lessc')
|
2017-11-09 06:49:44 -05:00
|
|
|
call ale#Set('less_lessc_options', '')
|
2018-04-09 14:11:20 -04:00
|
|
|
call ale#Set('less_lessc_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-11-12 06:25:24 -05:00
|
|
|
|
2017-11-09 06:49:44 -05:00
|
|
|
function! ale_linters#less#lessc#GetCommand(buffer) abort
|
2018-08-02 18:44:12 -04:00
|
|
|
return '%e --no-color --lint'
|
|
|
|
\ . ' --include-path=' . ale#Escape(expand('#' . a:buffer . ':p:h'))
|
|
|
|
\ . ale#Pad(ale#Var(a:buffer, 'less_lessc_options'))
|
2017-11-09 10:45:14 -05:00
|
|
|
\ . ' -'
|
2017-11-09 06:49:44 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#less#lessc#Handle(buffer, lines) abort
|
2017-11-12 06:35:01 -05:00
|
|
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
2017-11-09 06:49:44 -05:00
|
|
|
" 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)
|
2017-11-12 06:35:01 -05:00
|
|
|
let l:item = {
|
2017-11-09 06:49:44 -05:00
|
|
|
\ 'lnum': l:match[4] + 0,
|
|
|
|
\ 'col': l:match[5] + 0,
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'type': 'E',
|
2017-11-12 06:35:01 -05:00
|
|
|
\}
|
|
|
|
|
|
|
|
if l:match[3] isnot# '-'
|
|
|
|
let l:item.filename = ale#path#GetAbsPath(l:dir, l:match[3])
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, l:item)
|
2017-11-09 06:49:44 -05:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('less', {
|
|
|
|
\ 'name': 'lessc',
|
2019-02-22 13:05:04 -05:00
|
|
|
\ 'executable': {b -> ale#node#FindExecutable(b, 'less_lessc', [
|
2018-08-02 18:44:12 -04:00
|
|
|
\ 'node_modules/.bin/lessc',
|
2019-02-22 13:05:04 -05:00
|
|
|
\ ])},
|
|
|
|
\ 'command': function('ale_linters#less#lessc#GetCommand'),
|
2017-11-09 06:49:44 -05:00
|
|
|
\ 'callback': 'ale_linters#less#lessc#Handle',
|
2017-11-12 06:25:24 -05:00
|
|
|
\ 'output_stream': 'stderr',
|
2017-11-09 06:49:44 -05:00
|
|
|
\})
|