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

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / eruby / ruumba.vim
1 " Author: aclemons - https://github.com/aclemons
2 " based on the ale rubocop linter
3 " Description: Ruumba, RuboCop linting for ERB templates.
4
5 call ale#Set('eruby_ruumba_executable', 'ruumba')
6 call ale#Set('eruby_ruumba_options', '')
7
8 function! ale_linters#eruby#ruumba#GetCommand(buffer) abort
9     let l:executable = ale#Var(a:buffer, 'eruby_ruumba_executable')
10
11     return ale#ruby#EscapeExecutable(l:executable, 'ruumba')
12     \   . ' --format json --force-exclusion '
13     \   . ale#Var(a:buffer, 'eruby_ruumba_options')
14     \   . ' --stdin %s'
15 endfunction
16
17 function! ale_linters#eruby#ruumba#Handle(buffer, lines) abort
18     try
19         let l:errors = json_decode(a:lines[0])
20     catch
21         return []
22     endtry
23
24     if !has_key(l:errors, 'summary')
25     \|| l:errors['summary']['offense_count'] == 0
26     \|| empty(l:errors['files'])
27         return []
28     endif
29
30     let l:output = []
31
32     for l:error in l:errors['files'][0]['offenses']
33         let l:start_col = l:error['location']['column'] + 0
34         call add(l:output, {
35         \   'lnum': l:error['location']['line'] + 0,
36         \   'col': l:start_col,
37         \   'end_col': l:start_col + l:error['location']['length'] - 1,
38         \   'code': l:error['cop_name'],
39         \   'text': l:error['message'],
40         \   'type': ale_linters#eruby#ruumba#GetType(l:error['severity']),
41         \})
42     endfor
43
44     return l:output
45 endfunction
46
47 function! ale_linters#eruby#ruumba#GetType(severity) abort
48     if a:severity is? 'convention'
49     \|| a:severity is? 'warning'
50     \|| a:severity is? 'refactor'
51         return 'W'
52     endif
53
54     return 'E'
55 endfunction
56
57 call ale#linter#Define('eruby', {
58 \   'name': 'ruumba',
59 \   'executable': {b -> ale#Var(b, 'eruby_ruumba_executable')},
60 \   'command': function('ale_linters#eruby#ruumba#GetCommand'),
61 \   'callback': 'ale_linters#eruby#ruumba#Handle',
62 \})