1
0
Fork 0
mirror of synced 2024-12-23 07:20:42 -05:00
ultimate-vim/sources_non_forked/ale/ale_linters/ruby/reek.vim

79 lines
2.4 KiB
VimL
Raw Normal View History

" Author: Eddie Lebow https://github.com/elebow
" Description: Reek, a code smell detector for Ruby files
call ale#Set('ruby_reek_show_context', 0)
call ale#Set('ruby_reek_show_wiki_link', 0)
2018-09-24 20:40:17 -04:00
call ale#Set('ruby_reek_options', '')
call ale#Set('ruby_reek_executable', 'reek')
2018-07-04 06:53:25 -04: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
2018-09-24 20:40:17 -04:00
let l:executable = ale#Var(a:buffer, 'ruby_reek_executable')
return ale#handlers#ruby#EscapeExecutable(l:executable, 'reek')
\ . ' --version'
2018-07-04 06:53:25 -04:00
endfunction
2018-07-04 06:53:25 -04:00
function! ale_linters#ruby#reek#GetCommand(buffer, version_output) abort
let l:version = ale#semver#GetVersion('reek', a:version_output)
2018-09-24 20:40:17 -04:00
let l:executable = ale#Var(a:buffer, 'ruby_reek_executable')
2018-07-04 06:53:25 -04:00
" 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'
\ : ''
2018-09-24 20:40:17 -04:00
return ale#handlers#ruby#EscapeExecutable(l:executable, 'reek')
2018-11-01 06:03:42 -04:00
\ . ' -f json --no-progress --no-color --force-exclusion'
2018-07-04 06:53:25 -04:00
\ . l:display_name_args
endfunction
function! s:BuildText(buffer, error) abort
let l:parts = []
if ale#Var(a:buffer, 'ruby_reek_show_context')
call add(l:parts, a:error.context)
endif
call add(l:parts, a:error.message)
if ale#Var(a:buffer, 'ruby_reek_show_wiki_link')
call add(l:parts, '[' . a:error.wiki_link . ']')
endif
return join(l:parts, ' ')
endfunction
2018-07-04 06:53:25 -04: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
call ale#linter#Define('ruby', {
2018-07-04 06:53:25 -04:00
\ 'name': 'reek',
2018-09-24 20:40:17 -04:00
\ 'executable_callback': ale#VarFunc('ruby_reek_executable'),
2018-07-04 06:53:25 -04:00
\ 'command_chain': [
\ {'callback': 'ale_linters#ruby#reek#VersionCheck'},
\ {'callback': 'ale_linters#ruby#reek#GetCommand'},
\ ],
\ 'callback': 'ale_linters#ruby#reek#Handle',
\})