1 "============================================================================
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.
11 "============================================================================
12 if exists("loaded_php_syntax_checker")
15 let loaded_php_syntax_checker = 1
17 "bail if the user doesnt have php installed
22 "Support passing configuration directives to phpcs
23 if !exists("g:syntastic_phpcs_conf")
24 let g:syntastic_phpcs_conf = ""
27 if !exists("g:syntastic_phpcs_disable")
28 let g:syntastic_phpcs_disable = 0
31 function! 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]
37 function! SyntaxCheckers_php_GetLocList()
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 })
45 if empty(errors) && !g:syntastic_phpcs_disable && executable("phpcs")
46 let errors = errors + s:GetPHPCSErrors()
49 call SyntasticHighlightErrors(errors, function('SyntaxCheckers_php_Term'))
54 function! 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' })