2017-04-20 06:37:08 +00:00
|
|
|
" Author: Eddie Lebow https://github.com/elebow
|
|
|
|
" Description: Reek, a code smell detector for Ruby files
|
|
|
|
|
2017-07-26 23:45:25 +00:00
|
|
|
call ale#Set('ruby_reek_show_context', 0)
|
|
|
|
call ale#Set('ruby_reek_show_wiki_link', 0)
|
2017-04-20 06:37:08 +00:00
|
|
|
|
2018-07-01 09:21:59 +00:00
|
|
|
function! ale_linters#ruby#reek#VersionCheck(buffer) abort
|
|
|
|
" If we have previously stored the version number in a cache, then
|
|
|
|
" don't look it up again.
|
|
|
|
if ale#semver#HasVersion('reek')
|
|
|
|
" Returning an empty string skips this command.
|
|
|
|
return ''
|
|
|
|
endif
|
2017-04-20 06:37:08 +00:00
|
|
|
|
2018-07-01 09:21:59 +00:00
|
|
|
return 'reek --version'
|
|
|
|
endfunction
|
2017-04-20 06:37:08 +00:00
|
|
|
|
2018-07-01 09:21:59 +00:00
|
|
|
function! ale_linters#ruby#reek#GetCommand(buffer, version_output) abort
|
|
|
|
let l:version = ale#semver#GetVersion('reek', a:version_output)
|
|
|
|
|
|
|
|
" Tell reek what the filename is if the version of reek is new enough.
|
|
|
|
let l:display_name_args = ale#semver#GTE(l:version, [5, 0, 0])
|
|
|
|
\ ? ' --stdin-filename %s'
|
|
|
|
\ : ''
|
|
|
|
|
|
|
|
return 'reek -f json --no-progress --no-color'
|
|
|
|
\ . l:display_name_args
|
2017-04-20 06:37:08 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:BuildText(buffer, error) abort
|
2017-11-19 00:54:09 +00:00
|
|
|
let l:parts = []
|
2017-04-20 06:37:08 +00:00
|
|
|
|
|
|
|
if ale#Var(a:buffer, 'ruby_reek_show_context')
|
2017-11-19 00:54:09 +00:00
|
|
|
call add(l:parts, a:error.context)
|
2017-04-20 06:37:08 +00:00
|
|
|
endif
|
|
|
|
|
2017-11-19 00:54:09 +00:00
|
|
|
call add(l:parts, a:error.message)
|
2017-04-20 06:37:08 +00:00
|
|
|
|
|
|
|
if ale#Var(a:buffer, 'ruby_reek_show_wiki_link')
|
2017-11-19 00:54:09 +00:00
|
|
|
call add(l:parts, '[' . a:error.wiki_link . ']')
|
2017-04-20 06:37:08 +00:00
|
|
|
endif
|
|
|
|
|
2017-11-19 00:54:09 +00:00
|
|
|
return join(l:parts, ' ')
|
2017-04-20 06:37:08 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-07-01 09:21:59 +00:00
|
|
|
function! ale_linters#ruby#reek#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
for l:error in ale#util#FuzzyJSONDecode(a:lines, [])
|
|
|
|
for l:location in l:error.lines
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:location,
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ 'text': s:BuildText(a:buffer, l:error),
|
|
|
|
\ 'code': l:error.smell_type,
|
|
|
|
\})
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
2017-04-20 06:37:08 +00:00
|
|
|
call ale#linter#Define('ruby', {
|
2018-07-01 09:21:59 +00:00
|
|
|
\ 'name': 'reek',
|
|
|
|
\ 'executable': 'reek',
|
|
|
|
\ 'command_chain': [
|
|
|
|
\ {'callback': 'ale_linters#ruby#reek#VersionCheck'},
|
|
|
|
\ {'callback': 'ale_linters#ruby#reek#GetCommand'},
|
|
|
|
\ ],
|
2017-04-20 06:37:08 +00:00
|
|
|
\ 'callback': 'ale_linters#ruby#reek#Handle',
|
|
|
|
\})
|