2017-11-12 11:25:24 +00:00
|
|
|
" Author: zanona <https://github.com/zanona>, w0rp <devw0rp@gmail.com>
|
2017-11-09 11:49:44 +00:00
|
|
|
" Description: This file adds support for checking Less code with lessc.
|
|
|
|
|
2017-11-12 11:25:24 +00:00
|
|
|
call ale#Set('less_lessc_executable', 'lessc')
|
2017-11-09 11:49:44 +00:00
|
|
|
call ale#Set('less_lessc_options', '')
|
2018-04-09 18:11:20 +00:00
|
|
|
call ale#Set('less_lessc_use_global', get(g:, 'ale_use_global_executables', 0))
|
2017-11-12 11:25:24 +00:00
|
|
|
|
|
|
|
function! ale_linters#less#lessc#GetExecutable(buffer) abort
|
|
|
|
return ale#node#FindExecutable(a:buffer, 'less_lessc', [
|
|
|
|
\ 'node_modules/.bin/lessc',
|
|
|
|
\])
|
|
|
|
endfunction
|
2017-11-09 11:49:44 +00:00
|
|
|
|
|
|
|
function! ale_linters#less#lessc#GetCommand(buffer) abort
|
2017-11-12 11:25:24 +00:00
|
|
|
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 : '')
|
2017-11-09 15:45:14 +00:00
|
|
|
\ . ' -'
|
2017-11-09 11:49:44 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#less#lessc#Handle(buffer, lines) abort
|
2017-11-12 11:35:01 +00:00
|
|
|
let l:dir = expand('#' . a:buffer . ':p:h')
|
2017-11-09 11:49:44 +00: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 11:35:01 +00:00
|
|
|
let l:item = {
|
2017-11-09 11:49:44 +00:00
|
|
|
\ 'lnum': l:match[4] + 0,
|
|
|
|
\ 'col': l:match[5] + 0,
|
|
|
|
\ 'text': l:match[2],
|
|
|
|
\ 'type': 'E',
|
2017-11-12 11:35:01 +00: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 11:49:44 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('less', {
|
|
|
|
\ 'name': 'lessc',
|
2017-11-12 11:25:24 +00:00
|
|
|
\ 'executable_callback': 'ale_linters#less#lessc#GetExecutable',
|
2017-11-09 11:49:44 +00:00
|
|
|
\ 'command_callback': 'ale_linters#less#lessc#GetCommand',
|
|
|
|
\ 'callback': 'ale_linters#less#lessc#Handle',
|
2017-11-12 11:25:24 +00:00
|
|
|
\ 'output_stream': 'stderr',
|
2017-11-09 11:49:44 +00:00
|
|
|
\})
|