]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/css.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / css.vim
1 scriptencoding utf-8
2 " Author: w0rp <devw0rp@gmail.com>
3 " Description: Error handling for CSS linters.
4
5 function! ale#handlers#css#HandleCSSLintFormat(buffer, lines) abort
6     " Matches patterns line the following:
7     "
8     " something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors)
9     " something.css: line 2, col 5, Warning - Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | run-in | ruby | ruby-base | ruby-text | ruby-base-container | ruby-text-container | contents | none | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex) but found 'wat'. (known-properties)
10     "
11     " These errors can be very massive, so the type will be moved to the front
12     " so you can actually read the error type.
13     let l:pattern = '\v^.*: line (\d+), col (\d+), (Error|Warning) - (.+)$'
14     let l:output = []
15
16     for l:match in ale#util#GetMatches(a:lines, l:pattern)
17         let l:item = {
18         \   'lnum': l:match[1] + 0,
19         \   'col': l:match[2] + 0,
20         \   'type': l:match[3] is# 'Warning' ? 'W' : 'E',
21         \   'text': l:match[4],
22         \}
23
24         let l:code_match = matchlist(l:match[4], '\v(.+) \(([^(]+)\)$')
25
26         " Split up the error code and the text if we find one.
27         if !empty(l:code_match)
28             let l:item.text = l:code_match[1]
29             let l:item.code = l:code_match[2]
30         endif
31
32         call add(l:output, l:item)
33     endfor
34
35     return l:output
36 endfunction
37
38 function! ale#handlers#css#HandleStyleLintFormat(buffer, lines) abort
39     let l:exception_pattern = '\v^Error:'
40
41     for l:line in a:lines[:10]
42         if len(matchlist(l:line, l:exception_pattern)) > 0
43             return [{
44             \   'lnum': 1,
45             \   'text': 'stylelint exception thrown (type :ALEDetail for more information)',
46             \   'detail': join(a:lines, "\n"),
47             \}]
48         endif
49     endfor
50
51     " Matches patterns line the following:
52     "
53     " src/main.css
54     "  108:10  ✖  Unexpected leading zero         number-leading-zero
55     "  116:20  ✖  Expected a trailing semicolon   declaration-block-trailing-semicolon
56     let l:pattern = '\v^.* (\d+):(\d+) \s+(\S+)\s+ (.*[^ ])\s+([^ ]+)\s*$'
57     let l:output = []
58
59     for l:match in ale#util#GetMatches(a:lines, l:pattern)
60         call add(l:output, {
61         \   'lnum': l:match[1] + 0,
62         \   'col': l:match[2] + 0,
63         \   'type': l:match[3] is# '✖' ? 'E' : 'W',
64         \   'text': l:match[4],
65         \   'code': l:match[5],
66         \})
67     endfor
68
69     return l:output
70 endfunction