Ramlev.dk

I'm living in Copenhagen with my wife and Dogs.

Drupal developer for a living.

text

Vim and drupal code validation

I have been using the Syntastic plugin for vim for a long time. Syntastic does what it have to, in php files it validates the file by in short terms do a

$ php -l FILENAME

And present the error(s) in the statusbar, and with a little marker at the line(s).

If you install the PHP_CodeSniffer via the pear installer, Syntastic automatic validates the code against the default code standards setup in php_codesniffer.

I found DrupalCS module by Ericduran which is a PHP code sniffer addon, and tests your active code on-the-fly when saving.

The DrupalCS and phpcs (php code sniffer) is integrated into the Syntastic plugin.

The installation of PHP Code Sniffer and Drupal CS is quite simple, and it’s nicely documented on the DrupalCS module page.

After installing it, you can test if the DrupalCodingStandard work by test if it’s loaded in your terminal

$ phpcs -i

If you want to test a file from your terminal, you can fire the command

phpcs --standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme FILENAME.module

The result will look something like this output

If you execute the phpcs without the Drupal specific validator

$ phpcs --extensions=php,module,inc,install,test,profile,theme FILENAME.module 

The result output is a bit more scary.

Vim configuration

The configuration for vim im using to get it working is.

let g:syntastic_enable_signs=1 " Enable markers on the line containing a problem.
let g:syntastic_auto_jump=0 " Dont jump to the first line with a problem
let g:syntastic_phpcs_conf='--standard=DrupalCodingStandard --extensions=php,module,inc,install,test,profile,theme' " Test php,module,inc,install ... files with the DrupalCodingStandard

The first days after using it on a daily basis, it was quite annoying, but it have made me more aware of how i code.

blog comments powered by Disqus
  1. layzie313 reblogged this from ramlev and added:
    PHP_CodeSniffer…
  2. ramlev posted this

Following