]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/syntax_checkers/php.vim
Update the stuff
[rbdr/dotfiles] / vim / syntax_checkers / php.vim
... / ...
CommitLineData
1"============================================================================
2"File: php.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"============================================================================
12if exists("loaded_php_syntax_checker")
13 finish
14endif
15let loaded_php_syntax_checker = 1
16
17"bail if the user doesnt have php installed
18if !executable("php")
19 finish
20endif
21
22"Support passing configuration directives to phpcs
23if !exists("g:syntastic_phpcs_conf")
24 let g:syntastic_phpcs_conf = ""
25endif
26
27if !exists("g:syntastic_phpcs_disable")
28 let g:syntastic_phpcs_disable = 0
29endif
30
31function! SyntaxCheckers_php_Term(item)
32 let unexpected = matchstr(a:item['text'], "unexpected '[^']\\+'")
33 if len(unexpected) < 1 | return '' | end
34 return '\V'.split(unexpected, "'")[1]
35endfunction
36
37function! SyntaxCheckers_php_GetLocList()
38
39 let errors = []
40
41 let makeprg = "php -l ".shellescape(expand('%'))
42 let errorformat='%-GNo syntax errors detected in%.%#,PHP Parse error: %#syntax %trror\, %m in %f on line %l,PHP Fatal %trror: %m in %f on line %l,%-GErrors parsing %.%#,%-G\s%#,Parse error: %#syntax %trror\, %m in %f on line %l,Fatal %trror: %m in %f on line %l'
43 let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
44
45 if empty(errors) && !g:syntastic_phpcs_disable && executable("phpcs")
46 let errors = errors + s:GetPHPCSErrors()
47 endif
48
49 call SyntasticHighlightErrors(errors, function('SyntaxCheckers_php_Term'))
50
51 return errors
52endfunction
53
54function! s:GetPHPCSErrors()
55 let makeprg = "phpcs " . g:syntastic_phpcs_conf . " --report=csv ".shellescape(expand('%'))
56 let errorformat = '%-GFile\,Line\,Column\,Type\,Message\,Source\,Severity,"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]'
57 return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'subtype': 'Style' })
58endfunction