From 725957de6e8cdbe9ca9d295e2e5ae273260e6c7a Mon Sep 17 00:00:00 2001 From: diartyz Date: Tue, 6 Dec 2016 21:14:14 +0800 Subject: [PATCH] add stylelint support --- ale_linters/css/stylelint.vim | 8 ++++++++ ale_linters/sass/stylelint.vim | 8 ++++++++ ale_linters/scss/stylelint.vim | 8 ++++++++ autoload/ale/handlers.vim | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 ale_linters/css/stylelint.vim create mode 100644 ale_linters/sass/stylelint.vim create mode 100644 ale_linters/scss/stylelint.vim diff --git a/ale_linters/css/stylelint.vim b/ale_linters/css/stylelint.vim new file mode 100644 index 0000000..8d65665 --- /dev/null +++ b/ale_linters/css/stylelint.vim @@ -0,0 +1,8 @@ +" Author: diartyz + +call ale#linter#Define('css', { +\ 'name': 'stylelint', +\ 'executable': 'stylelint', +\ 'command': g:ale#util#stdin_wrapper . ' .css stylelint', +\ 'callback': 'ale#handlers#HandleStyleLintFormat', +\}) diff --git a/ale_linters/sass/stylelint.vim b/ale_linters/sass/stylelint.vim new file mode 100644 index 0000000..ae0b655 --- /dev/null +++ b/ale_linters/sass/stylelint.vim @@ -0,0 +1,8 @@ +" Author: diartyz + +call ale#linter#Define('sass', { +\ 'name': 'stylelint', +\ 'executable': 'stylelint', +\ 'command': g:ale#util#stdin_wrapper . ' .sass stylelint', +\ 'callback': 'ale#handlers#HandleStyleLintFormat', +\}) diff --git a/ale_linters/scss/stylelint.vim b/ale_linters/scss/stylelint.vim new file mode 100644 index 0000000..135fb8e --- /dev/null +++ b/ale_linters/scss/stylelint.vim @@ -0,0 +1,8 @@ +" Author: diartyz + +call ale#linter#Define('scss', { +\ 'name': 'stylelint', +\ 'executable': 'stylelint', +\ 'command': g:ale#util#stdin_wrapper . ' .scss stylelint', +\ 'callback': 'ale#handlers#HandleStyleLintFormat', +\}) diff --git a/autoload/ale/handlers.vim b/autoload/ale/handlers.vim index 177cdc4..526b9b5 100644 --- a/autoload/ale/handlers.vim +++ b/autoload/ale/handlers.vim @@ -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