2017-04-20 02:37:08 -04:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: Reek, a code smell detector for Ruby files
|
|
|
|
|
2017-07-26 19:45:25 -04:00
|
|
|
call ale#Set('ruby_reek_show_context', 0)
|
|
|
|
call ale#Set('ruby_reek_show_wiki_link', 0)
|
2017-04-20 02:37:08 -04:00
|
|
|
|
|
|
|
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
2017-07-26 19:45:25 -04:00
|
|
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
2017-04-20 02:37:08 -04:00
|
|
|
for l:location in l:error.lines
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:location,
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ 'text': s:BuildText(a:buffer, l:error),
|
2017-11-18 19:54:09 -05:00
|
|
|
\ 'code': l:error.smell_type,
|
2017-04-20 02:37:08 -04:00
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:BuildText(buffer, error) abort
|
2017-11-18 19:54:09 -05:00
|
|
|
let l:parts = []
|
2017-04-20 02:37:08 -04:00
|
|
|
|
|
|
|
if ale#Var(a:buffer, 'ruby_reek_show_context')
|
2017-11-18 19:54:09 -05:00
|
|
|
call add(l:parts, a:error.context)
|
2017-04-20 02:37:08 -04:00
|
|
|
endif
|
|
|
|
|
2017-11-18 19:54:09 -05:00
|
|
|
call add(l:parts, a:error.message)
|
2017-04-20 02:37:08 -04:00
|
|
|
|
|
|
|
if ale#Var(a:buffer, 'ruby_reek_show_wiki_link')
|
2017-11-18 19:54:09 -05:00
|
|
|
call add(l:parts, '[' . a:error.wiki_link . ']')
|
2017-04-20 02:37:08 -04:00
|
|
|
endif
|
|
|
|
|
2017-11-18 19:54:09 -05:00
|
|
|
return join(l:parts, ' ')
|
2017-04-20 02:37:08 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('ruby', {
|
|
|
|
\ 'name': 'reek',
|
|
|
|
\ 'executable': 'reek',
|
|
|
|
\ 'command': 'reek -f json --no-progress --no-color',
|
|
|
|
\ 'callback': 'ale_linters#ruby#reek#Handle',
|
|
|
|
\})
|