]> git.madduck.net Git - etc/vim.git/blob - ale_linters/chef/cookstyle.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] / ale_linters / chef / cookstyle.vim
1 " Author: Raphael Hoegger - https://github.com/pfuender
2 " Description: Cookstyle (RuboCop based), a code style analyzer for Ruby files
3
4 call ale#Set('chef_cookstyle_executable', 'cookstyle')
5 call ale#Set('chef_cookstyle_options', '')
6
7 function! ale_linters#chef#cookstyle#GetCommand(buffer) abort
8     let l:options = ale#Var(a:buffer, 'chef_cookstyle_options')
9
10     return '%e' . ale#Pad(escape(l:options, '~')) . ' --force-exclusion --format json --stdin ' . ' %s'
11 endfunction
12
13 function! ale_linters#chef#cookstyle#Handle(buffer, lines) abort
14     if len(a:lines) == 0
15         return []
16     endif
17
18     let l:errors = ale#util#FuzzyJSONDecode(a:lines[0], {})
19
20     if !has_key(l:errors, 'summary')
21     \|| l:errors['summary']['offense_count'] == 0
22     \|| empty(l:errors['files'])
23         return []
24     endif
25
26     let l:output = []
27
28     for l:error in l:errors['files'][0]['offenses']
29         let l:start_col = str2nr(l:error['location']['start_column'])
30         let l:end_col = str2nr(l:error['location']['last_column'])
31
32         if !l:end_col
33             let l:end_col = l:start_col + 1
34         endif
35
36         call add(l:output, {
37         \   'lnum': str2nr(l:error['location']['line']),
38         \   'col': l:start_col,
39         \   'end_col': l:end_col,
40         \   'code': l:error['cop_name'],
41         \   'text': l:error['message'],
42         \   'type': l:error['severity'] is? 'convention' ? 'W' : 'E',
43         \})
44     endfor
45
46     return l:output
47 endfunction
48
49 call ale#linter#Define('chef', {
50 \   'name': 'cookstyle',
51 \   'executable': {b -> ale#Var(b, 'chef_cookstyle_executable')},
52 \   'command': function('ale_linters#chef#cookstyle#GetCommand'),
53 \   'callback': 'ale_linters#chef#cookstyle#Handle',
54 \})