]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/slim/slimlint.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:

Merge commit 'd49e95aa7ba744f0a7f544aca43afdb6aab41f24' as '.vim/bundle/asyncomplete...
[etc/vim.git] / .vim / bundle / ale / ale_linters / slim / slimlint.vim
1 " Author: Markus Doits - https://github.com/doits
2 " Description: slim-lint for Slim files
3
4 function! ale_linters#slim#slimlint#GetCommand(buffer) abort
5     let l:command = 'slim-lint %t'
6
7     let l:rubocop_config = ale#path#FindNearestFile(a:buffer, '.rubocop.yml')
8
9     " Set SLIM_LINT_RUBOCOP_CONF variable as it is needed for slim-lint to
10     " pick up the rubocop config.
11     "
12     " See https://github.com/sds/slim-lint/blob/master/lib/slim_lint/linter/README.md#rubocop
13     if !empty(l:rubocop_config)
14         if has('win32')
15             let l:command = 'set SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' && ' . l:command
16         else
17             let l:command = 'SLIM_LINT_RUBOCOP_CONF=' . ale#Escape(l:rubocop_config) . ' ' . l:command
18         endif
19     endif
20
21     return l:command
22 endfunction
23
24 function! ale_linters#slim#slimlint#Handle(buffer, lines) abort
25     " Matches patterns like the following:
26     " <path>:5 [W] LineLength: Line is too long. [150/120]
27     let l:pattern = '\v^.*:(\d+) \[([EW])\] (.+)$'
28     let l:output = []
29
30     for l:match in ale#util#GetMatches(a:lines, l:pattern)
31         let l:item = {
32         \   'lnum': l:match[1] + 0,
33         \   'type': l:match[2],
34         \   'text': l:match[3]
35         \}
36
37         let l:code_match = matchlist(l:item.text, '\v^([^:]+): (.+)$')
38
39         if !empty(l:code_match)
40             let l:item.code = l:code_match[1]
41             let l:item.text = l:code_match[2]
42         endif
43
44         call add(l:output, l:item)
45     endfor
46
47     return l:output
48 endfunction
49
50 call ale#linter#Define('slim', {
51 \   'name': 'slimlint',
52 \   'executable': 'slim-lint',
53 \   'command': function('ale_linters#slim#slimlint#GetCommand'),
54 \   'callback': 'ale_linters#slim#slimlint#Handle'
55 \})