diff options
author | Raphael Hoegger <pfuender@users.noreply.github.com> | 2019-04-10 19:52:52 +0200 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-04-10 18:52:52 +0100 |
commit | 81423701b0378af56d53402b1a95026b71369246 (patch) | |
tree | 21dd9e07e9cde7b3cfa7d10e416064dcb12e1bcf /ale_linters | |
parent | abcefe7a6e2555db924d56e3d88f28cf5b6a55e8 (diff) | |
download | ale-81423701b0378af56d53402b1a95026b71369246.zip |
Adding new linter "cookstyle" for chef recipes (Issue #1187) (#2362)
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/chef/cookstyle.vim | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ale_linters/chef/cookstyle.vim b/ale_linters/chef/cookstyle.vim new file mode 100644 index 00000000..50bae2aa --- /dev/null +++ b/ale_linters/chef/cookstyle.vim @@ -0,0 +1,54 @@ +" Author: Raphael Hoegger - https://github.com/pfuender +" Description: Cookstyle (RuboCop based), a code style analyzer for Ruby files + +call ale#Set('chef_cookstyle_executable', 'cookstyle') +call ale#Set('chef_cookstyle_options', '') + +function! ale_linters#chef#cookstyle#GetCommand(buffer) abort + let l:options = ale#Var(a:buffer, 'chef_cookstyle_options') + + return '%e' . ale#Pad(escape(l:options, '~')) . ' --force-exclusion --format json --stdin ' . ' %s' +endfunction + +function! ale_linters#chef#cookstyle#Handle(buffer, lines) abort + if len(a:lines) == 0 + return [] + endif + + let l:errors = ale#util#FuzzyJSONDecode(a:lines[0], {}) + + if !has_key(l:errors, 'summary') + \|| l:errors['summary']['offense_count'] == 0 + \|| empty(l:errors['files']) + return [] + endif + + let l:output = [] + + for l:error in l:errors['files'][0]['offenses'] + let l:start_col = str2nr(l:error['location']['start_column']) + let l:end_col = str2nr(l:error['location']['last_column']) + + if !l:end_col + let l:end_col = l:start_col + 1 + endif + + call add(l:output, { + \ 'lnum': str2nr(l:error['location']['line']), + \ 'col': l:start_col, + \ 'end_col': l:end_col, + \ 'code': l:error['cop_name'], + \ 'text': l:error['message'], + \ 'type': l:error['severity'] is? 'convention' ? 'W' : 'E', + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('chef', { +\ 'name': 'cookstyle', +\ 'executable': {b -> ale#Var(b, 'chef_cookstyle_executable')}, +\ 'command': function('ale_linters#chef#cookstyle#GetCommand'), +\ 'callback': 'ale_linters#chef#cookstyle#Handle', +\}) |