flake8.vim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "============================================================================
  2. "File: flake8.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Authors: Sylvain Soliman <Sylvain dot Soliman+git at gmail dot com>
  5. " kstep <me@kstep.me>
  6. "
  7. "============================================================================
  8. if exists('g:loaded_syntastic_python_flake8_checker')
  9. finish
  10. endif
  11. let g:loaded_syntastic_python_flake8_checker = 1
  12. let s:save_cpo = &cpo
  13. set cpo&vim
  14. function! SyntaxCheckers_python_flake8_GetHighlightRegex(item)
  15. return SyntaxCheckers_python_pyflakes_GetHighlightRegex(a:item)
  16. endfunction
  17. function! SyntaxCheckers_python_flake8_GetLocList() dict
  18. let makeprg = self.makeprgBuild({})
  19. let errorformat =
  20. \ '%E%f:%l: could not compile,%-Z%p^,' .
  21. \ '%A%f:%l:%c: %t%n %m,' .
  22. \ '%A%f:%l: %t%n %m,' .
  23. \ '%-G%.%#'
  24. let env = syntastic#util#isRunningWindows() ? {} : { 'TERM': 'dumb' }
  25. let loclist = SyntasticMake({
  26. \ 'makeprg': makeprg,
  27. \ 'errorformat': errorformat,
  28. \ 'env': env })
  29. for e in loclist
  30. " E*** and W*** are pep8 errors
  31. " F*** are PyFlakes codes
  32. " C*** are McCabe complexity messages
  33. " N*** are naming conventions from pep8-naming
  34. if has_key(e, 'nr')
  35. let e['text'] .= printf(' [%s%03d]', e['type'], e['nr'])
  36. " E901 are syntax errors
  37. " E902 are I/O errors
  38. if e['type'] ==? 'E' && e['nr'] !~# '\m^9'
  39. let e['subtype'] = 'Style'
  40. endif
  41. call remove(e, 'nr')
  42. endif
  43. if e['type'] =~? '\m^[CNW]'
  44. let e['subtype'] = 'Style'
  45. endif
  46. let e['type'] = e['type'] =~? '\m^[EFC]' ? 'E' : 'W'
  47. endfor
  48. return loclist
  49. endfunction
  50. runtime! syntax_checkers/python/pyflakes.vim
  51. call g:SyntasticRegistry.CreateAndRegisterChecker({
  52. \ 'filetype': 'python',
  53. \ 'name': 'flake8'})
  54. let &cpo = s:save_cpo
  55. unlet s:save_cpo
  56. " vim: set sw=4 sts=4 et fdm=marker: