Flog checker: cleanup.

This commit is contained in:
LCD 47 2015-07-19 18:33:36 +03:00
parent 5db87b9ec8
commit 6929f24e45
2 changed files with 42 additions and 32 deletions

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START lockvar! g:_SYNTASTIC_START
endif endif
let g:_SYNTASTIC_VERSION = '3.6.0-130' let g:_SYNTASTIC_VERSION = '3.6.0-132'
lockvar g:_SYNTASTIC_VERSION lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1 " Sanity checks {{{1

View File

@ -23,54 +23,64 @@ if !exists('g:syntastic_ruby_flog_threshold_error')
let g:syntastic_ruby_flog_threshold_error = 90 let g:syntastic_ruby_flog_threshold_error = 90
endif endif
if !exists('g:syntastic_ruby_flog_sort')
let g:syntastic_ruby_flog_sort = 1
endif
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
function! SyntaxCheckers_ruby_flog_GetLocList() dict function! SyntaxCheckers_ruby_flog_GetLocList() dict " {{{1
let makeprg = self.makeprgBuild({}) let makeprg = self.makeprgBuild({ 'args': '-a' })
" Example output: " Example output:
" 93.25: MyClass::my_method my_file:42 " 93.25: MyClass::my_method my_file:42
" let errorformat = '%\m%\s%#%m: %.%# %f:%l'
" %p for the leading spaces
" %m for the message (score)
" :\ %.%#: for anything in between the :
" %l for the line number
let errorformat = '%p%m:\ %.%#:%l'
let loclist = SyntasticMake({ let loclist = SyntasticMake({
\ 'makeprg': makeprg, \ 'makeprg': makeprg,
\ 'defaults': {'bufnr': bufnr('')}, \ 'errorformat': errorformat,
\ 'errorformat': errorformat}) \ 'subtype': 'Style' })
" Split output into error and warning let trail_w = s:_float2str(g:syntastic_ruby_flog_threshold_warning) . ')'
let min = g:syntastic_ruby_flog_threshold_warning let trail_e = s:_float2str(g:syntastic_ruby_flog_threshold_error) . ')'
let max = g:syntastic_ruby_flog_threshold_error
for e in loclist for e in loclist
if e['valid'] ==# '0' let score = s:_str2float(e['text'])
continue
endif
let score = str2nr(e['text']) let e['text'] = 'Complexity is too high (' . s:_float2str(score) . '/'
" Discard scores too low if score < g:syntastic_ruby_flog_threshold_warning
if score < min let e['valid'] = 0
let e['valid'] = '0' elseif score < g:syntastic_ruby_flog_threshold_error
continue
endif
" Set as warning or error based on the thresholds
let e['text'] = 'Complexity is too high (' . score . '/'
if score > max
let e['type'] = 'E'
let e['text'] .= max . ')'
else
let e['type'] = 'W' let e['type'] = 'W'
let e['text'] .= min . ')' let e['text'] .= trail_w
else
let e['type'] = 'E'
let e['text'] .= trail_e
endif endif
endfor endfor
return loclist return loclist
endfunction endfunction " }}}1
" Utilities {{{1
function! s:_float2str_smart(val) " {{{2
return printf('%.1f', a:val)
endfunction " }}}2
function! s:_float2str_dumb(val) " {{{2
return a:val
endfunction " }}}2
if !exists('s:_str2float')
let s:_str2float = function(exists('*str2float') ? 'str2float' : 'str2nr')
endif
if !exists('s:_float2str')
let s:_float2str = function(has('float') ? 's:_float2str_smart' : 's:_float2str_dumb')
endif
" }}}1
call g:SyntasticRegistry.CreateAndRegisterChecker({ call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'ruby', \ 'filetype': 'ruby',