Adding PHP_CodeSniffer with WordPress Standard - salcode/ironcode-vim GitHub Wiki
Install PHP_CodeSniffer
pear install PHP_CodeSniffer
Install WordPress coding standards
Install the code standards in wpcs
in your home directory.
git clone https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git ~/wpcs
Configure PHP_CodeSniffer to look for the WordPress Coding Standards in the correct directory
phpcs --config-set installed_paths ~/wpcs
Confirm PHP_CodeSniffer is setup properly with the WordPress Coding Standards
phpcs -i
The output should look something like,
The installed coding standards are MySource, PEAR, PHPCS, PSR1, PSR2, Squiz, Zend, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra and WordPress-VIP
You'll notice the WordPress coding standards included in the list.
Add the Syntastic Plugin
The Vim Syntastic Plugin is a syntax checking plugin. Out of the box, it will catch PHP errors like forgetting a semi-colon, forgetting to close braces, etc. See their Syntastic's Recommended settings, for getting started.
Get Syntastic to Use PHP_CodeSniffer
Here are the settings I added to my .vimrc
, in addition to Syntastic's Recommended settings.
" Syntastic settings for phpcs and WordPress coding standards
"
" Run base PHP checker first, then run phpcs with WordPress standard
" If phpcs does not exist or the WordPress standard does not exist,
" Syntastic skips them (failing gracefully)
let g:syntastic_php_checkers = ['php', 'phpcs']
let g:syntastic_php_phpcs_args = '--standard=WordPress'
" If phpcs.xml is found, it supercedes the standard set above
let g:syntastic_php_phpcs_standard_file = "phpcs.xml"
Where Do You Go From Here
Syntastic uses the Location List, which is very similiar to the Quickfix List. See :h quickfix
in Vim.
Thank You
Thanks to @dsawardekar for his work on WordPress.vim project, which helped me understand how to set this up.