mri.vim 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "============================================================================
  2. "File: mri.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Martin Grenfell <martin.grenfell 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_ruby_mri_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_ruby_mri_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_ruby_mri_IsAvailable() dict
  19. if !exists('g:syntastic_ruby_mri_exec') && exists('g:syntastic_ruby_exec')
  20. let g:syntastic_ruby_mri_exec = g:syntastic_ruby_exec
  21. call self.log('g:syntastic_ruby_exec =', g:syntastic_ruby_exec)
  22. endif
  23. return executable(self.getExec())
  24. endfunction
  25. function! SyntaxCheckers_ruby_mri_GetHighlightRegex(i)
  26. if stridx(a:i['text'], 'assigned but unused variable') >= 0
  27. let term = split(a:i['text'], ' - ')[1]
  28. return '\V\<' . escape(term, '\') . '\>'
  29. endif
  30. return ''
  31. endfunction
  32. function! SyntaxCheckers_ruby_mri_GetLocList() dict
  33. let makeprg = self.makeprgBuild({
  34. \ 'args': '-w -T1',
  35. \ 'args_after': '-c' })
  36. "this is a hack to filter out a repeated useless warning in rspec files
  37. "containing lines like
  38. "
  39. " foo.should == 'bar'
  40. "
  41. "Which always generate the warning below. Note that ruby >= 1.9.3 includes
  42. "the word "possibly" in the warning
  43. let errorformat = '%-G%\m%.%#warning: %\%%(possibly %\)%\?useless use of == in void context,'
  44. " filter out lines starting with ...
  45. " long lines are truncated and wrapped in ... %p then returns the wrong
  46. " column offset
  47. let errorformat .= '%-G%\%.%\%.%\%.%.%#,'
  48. let errorformat .=
  49. \ '%-GSyntax OK,'.
  50. \ '%E%f:%l: syntax error\, %m,'.
  51. \ '%Z%p^,'.
  52. \ '%W%f:%l: warning: %m,'.
  53. \ '%Z%p^,'.
  54. \ '%W%f:%l: %m,'.
  55. \ '%-C%.%#'
  56. let env = syntastic#util#isRunningWindows() ? {} : { 'RUBYOPT': '' }
  57. return SyntasticMake({
  58. \ 'makeprg': makeprg,
  59. \ 'errorformat': errorformat,
  60. \ 'env': env })
  61. endfunction
  62. call g:SyntasticRegistry.CreateAndRegisterChecker({
  63. \ 'filetype': 'ruby',
  64. \ 'name': 'mri',
  65. \ 'exec': 'ruby'})
  66. let &cpo = s:save_cpo
  67. unlet s:save_cpo
  68. " vim: set sw=4 sts=4 et fdm=marker: