add stylelint support

This commit is contained in:
diartyz 2016-12-06 21:14:14 +08:00
parent 1a749a6b43
commit 725957de6e
4 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,8 @@
" Author: diartyz <diartyz@gmail.com>
call ale#linter#Define('css', {
\ 'name': 'stylelint',
\ 'executable': 'stylelint',
\ 'command': g:ale#util#stdin_wrapper . ' .css stylelint',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\})

View File

@ -0,0 +1,8 @@
" Author: diartyz <diartyz@gmail.com>
call ale#linter#Define('sass', {
\ 'name': 'stylelint',
\ 'executable': 'stylelint',
\ 'command': g:ale#util#stdin_wrapper . ' .sass stylelint',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\})

View File

@ -0,0 +1,8 @@
" Author: diartyz <diartyz@gmail.com>
call ale#linter#Define('scss', {
\ 'name': 'stylelint',
\ 'executable': 'stylelint',
\ 'command': g:ale#util#stdin_wrapper . ' .scss stylelint',
\ 'callback': 'ale#handlers#HandleStyleLintFormat',
\})

View File

@ -181,3 +181,37 @@ function! ale#handlers#HandleCSSLintFormat(buffer, lines) abort
return l:output
endfunction
function! ale#handlers#HandleStyleLintFormat(buffer, lines) abort
" Matches patterns line the following:
"
" src/main.css
" 108:10 ✖ Unexpected leading zero number-leading-zero
" 116:20 ✖ Expected a trailing semicolon declaration-block-trailing-semicolon
let l:pattern = '^.* \(\d\+\):\(\d\+\) \s\+\(\S\+\)\s\+ \(\u.\+\) \(.\+\)$'
let l:output = []
for l:line in a:lines
let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0
continue
endif
let l:text = l:match[4]
let l:type = l:match[3]
" vcol is Needed to indicate that the column is a character.
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:match[1] + 0,
\ 'vcol': 0,
\ 'col': l:match[2] + 0,
\ 'text': l:text,
\ 'type': l:type ==# '✖' ? 'E' : 'W',
\ 'nr': -1,
\})
endfor
return l:output
endfunction