I presented a bit on how to setup Drupal Code Sniffer with Sublime Text 2 at our last CharDUG meet up. I wanted to follow-up in writing on how to set up this functionality since I didn't have slides prepared at the meet up.
A brief description from the Drupal Code Sniffer project page:
This project provides a coding standard for PHP_CodeSniffer, based on the Drupal Coding Standards. Drupal code sniffer is not a Drupal module, it does not require Drupal to run and it is independent of Drupal core versions.
The real win with Drupal Code Sniffer is that it doesn’t require Drupal to run to provide an instant code review. It will deinitely help you follow Drupal Coding Standards.
Drupal Code Sniffer was a separate project, but has since been moved into a sub folder of the Coder project (currently the 7.x-2.x-dev release). The direct association with the well established coder project is great news for the contiunation of the newer Drupal Code Sniffer project.
Once setup properly, Drupal Code Sniffer can be executed within a Sublime Text 2 by pressing “Command+B” (Mac). A clean list of any code standard violations will be displayed below the code window. Pressing “Esc” will clear the results when you are finished reviewing.
- Follow these instructions to get PHP_CodeSniffer and Drupal Code Sniffer setup
- Clone this github.com project into ~/Library/Application Support/Sublime Text 2/Packages/User
- Follow these instructions to completed the DrupalCodingStandrard build-system setup
At this point, you should be able to open Drupal related files and press Command+B to receive Drupal Code Sniffer feedback.
The above instructions should be easily adapted to work for Linux-based systems. Command keys and paths may vary.