Skip to content

Commit

Permalink
Add the ability to use project specific phpcs standard
Browse files Browse the repository at this point in the history
  • Loading branch information
sudar committed Oct 9, 2015
1 parent 99988b2 commit 8d22d8e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
7 changes: 6 additions & 1 deletion syntax_checkers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,10 @@ Add the following lines to your `~/.vimrc` file or better add them to `~/.vim/ft

```
let g:syntastic_wordpress_checkers = ['phpcs']
let g:syntastic_wordpress_phpcs_args = "--report=csv --standard=WordPress"
let g:syntastic_wordpress_phpcs_standard = "WordPress-Core" "Default standard
"Standard file name. This should be at the root of the project.
"If not found then the default standard is used
let g:syntastic_wordpress_phpcs_standard_file = "phpcs.xml"
```

The above configuration will use `WordPress-Core` as the default standard. If it finds a `phpcs.xml` file in any of the parent directories of the file that is currently being edited, then the standards from the `phpcs.xml` will be used.
43 changes: 39 additions & 4 deletions syntax_checkers/wordpress/phpcs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,48 @@ if exists("g:loaded_syntastic_wordpress_phpcs_checker")
endif
let g:loaded_syntastic_wordpress_phpcs_checker = 1

" Use PHP's phpcs checker
runtime! syntax_checkers/php/phpcs.vim
let s:save_cpo = &cpo
set cpo&vim

function! SyntaxCheckers_wordpress_phpcs_GetLocList() dict
if exists("g:syntastic_wordpress_phpcs_args")
" if args is defined, then just use it
let args_before = ''
endif

if exists("g:syntastic_wordpress_phpcs_standard")
" if a standard is set then use it
let args_before = '--standard=' . g:syntastic_wordpress_phpcs_standard
endif

if exists("g:syntastic_wordpress_phpcs_standard_file")
" search upwards from the current file's directory
let standard_file = findfile(g:syntastic_wordpress_phpcs_standard_file, '.;')
if filereadable(standard_file)
let args_before = '--standard=' . standard_file
endif
endif

let makeprg = self.makeprgBuild({
\ 'args_before': args_before,
\ 'args_after': '--report=csv' })

let errorformat =
\ '%-GFile\,Line\,Column\,Type\,Message\,Source\,Severity%.%#,'.
\ '"%f"\,%l\,%c\,%t%*[a-zA-Z]\,"%m"\,%*[a-zA-Z0-9_.-]\,%*[0-9]%.%#'

return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'subtype': 'Style' })
endfunction

call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'wordpress',
\ 'name': 'phpcs',
\ 'redirect': 'php/phpcs'})
\ 'name': 'phpcs' })

let &cpo = s:save_cpo
unlet s:save_cpo

" Register the new filetype
if exists('g:syntastic_extra_filetypes')
Expand Down

0 comments on commit 8d22d8e

Please sign in to comment.