flog.vim 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "============================================================================
  2. "File: flog.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Tim Carry <tim at pixelastic dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_ruby_flog_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_ruby_flog_checker = 1
  16. if !exists('g:syntastic_ruby_flog_threshold_warning')
  17. let g:syntastic_ruby_flog_threshold_warning = 45
  18. endif
  19. if !exists('g:syntastic_ruby_flog_threshold_error')
  20. let g:syntastic_ruby_flog_threshold_error = 90
  21. endif
  22. if !exists('g:syntastic_ruby_flog_sort')
  23. let g:syntastic_ruby_flog_sort = 1
  24. endif
  25. let s:save_cpo = &cpo
  26. set cpo&vim
  27. function! SyntaxCheckers_ruby_flog_GetLocList() dict
  28. let makeprg = self.makeprgBuild({ 'args': '-a' })
  29. " Example output:
  30. " 93.25: MyClass::my_method my_file:42
  31. let errorformat = '%\m%\s%#%m: %.%# %f:%l'
  32. let loclist = SyntasticMake({
  33. \ 'makeprg': makeprg,
  34. \ 'errorformat': errorformat,
  35. \ 'subtype': 'Style' })
  36. let trail_w = syntastic#util#float2str(g:syntastic_ruby_flog_threshold_warning) . ')'
  37. let trail_e = syntastic#util#float2str(g:syntastic_ruby_flog_threshold_error) . ')'
  38. for e in loclist
  39. let score = syntastic#util#str2float(e['text'])
  40. let e['text'] = 'Complexity is too high (' . syntastic#util#float2str(score) . '/'
  41. if score < g:syntastic_ruby_flog_threshold_warning
  42. let e['valid'] = 0
  43. elseif score < g:syntastic_ruby_flog_threshold_error
  44. let e['type'] = 'W'
  45. let e['text'] .= trail_w
  46. else
  47. let e['type'] = 'E'
  48. let e['text'] .= trail_e
  49. endif
  50. endfor
  51. return loclist
  52. endfunction
  53. call g:SyntasticRegistry.CreateAndRegisterChecker({
  54. \ 'filetype': 'ruby',
  55. \ 'name': 'flog'})
  56. let &cpo = s:save_cpo
  57. unlet s:save_cpo
  58. " vim: set sw=4 sts=4 et fdm=marker: