phpmd.vim 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "============================================================================
  2. "File: phpmd.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_php_phpmd_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_php_phpmd_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_php_phpmd_GetHighlightRegex(item)
  19. let term = matchstr(a:item['text'], '\m\C^The \S\+ \w\+\(()\)\= \(has\|is not\|utilizes\)')
  20. if term !=# ''
  21. return '\V'.substitute(term, '\m\C^The \S\+ \(\w\+\)\(()\)\= .*', '\1', '')
  22. endif
  23. let term = matchstr(a:item['text'], '\m\C^Avoid \(variables with short\|excessively long variable\) names like \S\+\.')
  24. if term !=# ''
  25. return '\V'.substitute(term, '\m\C^Avoid \(variables with short\|excessively long variable\) names like \(\S\+\)\..*', '\2', '')
  26. endif
  27. let term = matchstr(a:item['text'], '\m\C^Avoid using short method names like \S\+::\S\+()\.')
  28. if term !=# ''
  29. return '\V'.substitute(term, '\m\C^Avoid using short method names like \S\+::\(\S\+\)()\..*', '\1', '')
  30. endif
  31. let term = matchstr(a:item['text'], '\m\C^\S\+ accesses the super-global variable ')
  32. if term !=# ''
  33. return '\V'.substitute(term, '\m\C accesses the super-global variable .*$', '', '')
  34. endif
  35. let term = matchstr(a:item['text'], '\m\C^Constant \S\+ should be defined in uppercase')
  36. if term !=# ''
  37. return '\V'.substitute(term, '\m\C^Constant \(\S\+\) should be defined in uppercase', '\1', '')
  38. endif
  39. let term = matchstr(a:item['text'], "\\m\\C^The '\\S\\+()' method which returns ")
  40. if term !=# ''
  41. return '\V'.substitute(term, "\\m\\C^The '\\(\\S\\+\\)()' method which returns.*", '\1', '')
  42. endif
  43. let term = matchstr(a:item['text'], '\m\C variable \S\+ should begin with ')
  44. if term !=# ''
  45. return '\V'.substitute(term, '\m\C.* variable \(\S\+\) should begin with .*', '\1', '')
  46. endif
  47. let term = matchstr(a:item['text'], "\\m\\C^Avoid unused \\(private fields\\|local variables\\|private methods\\|parameters\\) such as '\\S\\+'")
  48. if term !=# ''
  49. return '\V'.substitute(term, "\\m\\C^Avoid unused \\(private fields\\|local variables\\|private methods\\|parameters\\) such as '\\(\\S\\+\\)'.*", '\2', '')
  50. endif
  51. return ''
  52. endfunction
  53. function! SyntaxCheckers_php_phpmd_GetLocList() dict
  54. let makeprg = self.makeprgBuild({
  55. \ 'post_args_before': 'text',
  56. \ 'post_args': 'codesize,design,unusedcode,naming' })
  57. let errorformat = '%E%f:%l%\s%#%m'
  58. return SyntasticMake({
  59. \ 'makeprg': makeprg,
  60. \ 'errorformat': errorformat,
  61. \ 'subtype' : 'Style' })
  62. endfunction
  63. call g:SyntasticRegistry.CreateAndRegisterChecker({
  64. \ 'filetype': 'php',
  65. \ 'name': 'phpmd'})
  66. let &cpo = s:save_cpo
  67. unlet s:save_cpo
  68. " vim: set sw=4 sts=4 et fdm=marker: