2017-03-13 23:21:59 +00:00
|
|
|
" Author: Markus Doits - https://github.com/doits
|
2017-09-02 14:48:00 +00:00
|
|
|
" Description: slim-lint for Slim files
|
|
|
|
|
|
|
|
function! ale_linters#slim#slimlint#GetCommand(buffer) abort
|
|
|
|
let l:command = 'slim-lint %t'
|
|
|
|
|
|
|
|
let l:rubocop_config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
|
|
|
|
|
2017-09-18 10:28:37 +00:00
|
|
|
" Set SLIM_LINT_RUBOCOP_CONF variable as it is needed for slim-lint to
|
2017-09-02 14:48:00 +00:00
|
|
|
" pick up the rubocop config.
|
|
|
|
"
|
|
|
|
" See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop
|
|
|
|
if !empty(l:rubocop_config)
|
2019-04-07 14:34:39 +00:00
|
|
|
if has('win32')
|
2019-02-06 18:05:13 +00:00
|
|
|
let l:command = 'set SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' && ' . l:command
|
|
|
|
else
|
|
|
|
let l:command = 'SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' ' . l:command
|
|
|
|
endif
|
2017-09-02 14:48:00 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
return l:command
|
|
|
|
endfunction
|
2017-03-13 23:21:59 +00:00
|
|
|
|
|
|
|
function! ale_linters#slim#slimlint#Handle(buffer, lines) abort
|
|
|
|
" Matches patterns like the following:
|
|
|
|
" <path>:5 [W] LineLength: Line is too long. [150/120]
|
|
|
|
let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
|
|
|
|
let l:output = []
|
|
|
|
|
2017-04-17 23:35:53 +00:00
|
|
|
for l:match in ale#util#GetMatches(a:lines, l:pattern)
|
2017-11-19 01:08:20 +00:00
|
|
|
let l:item = {
|
2017-03-13 23:21:59 +00:00
|
|
|
\ 'lnum': l:match[1] + 0,
|
|
|
|
\ 'type': l:match[2],
|
|
|
|
\ 'text': l:match[3]
|
2017-11-19 01:08:20 +00:00
|
|
|
\}
|
|
|
|
|
|
|
|
let l:code_match = matchlist(l:item.text, '\v^([^:]+): (.+)$')
|
|
|
|
|
|
|
|
if !empty(l:code_match)
|
|
|
|
let l:item.code = l:code_match[1]
|
|
|
|
let l:item.text = l:code_match[2]
|
|
|
|
endif
|
|
|
|
|
|
|
|
call add(l:output, l:item)
|
2017-03-13 23:21:59 +00:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('slim', {
|
|
|
|
\ 'name': 'slimlint',
|
|
|
|
\ 'executable': 'slim-lint',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'command': function('ale_linters#slim#slimlint#GetCommand'),
|
2017-03-13 23:21:59 +00:00
|
|
|
\ 'callback': 'ale_linters#slim#slimlint#Handle'
|
|
|
|
\})
|