scalastyle.vim 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "============================================================================
  2. "File: scalastyle.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: LCD 47 <lcd047 at gmail 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_scala_scalastyle_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_scala_scalastyle_checker = 1
  16. if !exists('g:syntastic_scala_scalastyle_jar')
  17. let g:syntastic_scala_scalastyle_jar = 'scalastyle-batch_2.10.jar'
  18. endif
  19. if !exists('g:syntastic_scala_scalastyle_config_file')
  20. let g:syntastic_scala_scalastyle_config_file = 'scalastyle_config.xml'
  21. endif
  22. let s:save_cpo = &cpo
  23. set cpo&vim
  24. function! SyntaxCheckers_scala_scalastyle_IsAvailable() dict
  25. if !executable(self.getExec())
  26. return 0
  27. endif
  28. let jar = expand(g:syntastic_scala_scalastyle_jar, 1)
  29. let conf_file = expand(g:syntastic_scala_scalastyle_config_file, 1)
  30. call self.log('filereadable(' . string(jar) . ') = ' . filereadable(jar) . ', ' .
  31. \ 'filereadable(' . string(conf_file) . ') = ' . filereadable(conf_file))
  32. return filereadable(jar) && filereadable(conf_file)
  33. endfunction
  34. function! SyntaxCheckers_scala_scalastyle_GetLocList() dict
  35. let makeprg = self.makeprgBuild({
  36. \ 'exe_after': ['-jar', expand(g:syntastic_scala_scalastyle_jar, 1)],
  37. \ 'args_before': ['-c', expand(g:syntastic_scala_scalastyle_config_file, 1)] })
  38. let errorformat =
  39. \ '%trror file=%f message=%m line=%l column=%c,' .
  40. \ '%trror file=%f message=%m line=%l,' .
  41. \ '%tarning file=%f message=%m line=%l column=%c,' .
  42. \ '%tarning file=%f message=%m line=%l'
  43. let loclist = SyntasticMake({
  44. \ 'makeprg': makeprg,
  45. \ 'errorformat': errorformat,
  46. \ 'subtype': 'Style',
  47. \ 'returns': [0, 1] })
  48. for e in loclist
  49. if has_key(e, 'col')
  50. let e['col'] += 1
  51. endif
  52. endfor
  53. return loclist
  54. endfunction
  55. call g:SyntasticRegistry.CreateAndRegisterChecker({
  56. \ 'filetype': 'scala',
  57. \ 'name': 'scalastyle',
  58. \ 'exec': 'java'})
  59. let &cpo = s:save_cpo
  60. unlet s:save_cpo
  61. " vim: set sw=4 sts=4 et fdm=marker: