Friday, 30 November 2007

PHP_CodeSniffer 1.0.0RC3 released with tab support

I've just released the third release candidate of PHP_CodeSniffer. This release contains a few bug fixes, some changes to the Squiz coding standard, and a great new feature to provide support for tab-indented files.

In the past, my standard response to people asking for PHP_CodeSniffer to "support tabs" was to say that PHP_CodeSniffer doesn't do anything to stop you writing standards that use tabs, but the default sniffs that come with it don't support them. But that response also alludes to the fact that PHP_CodeSniffer doesn't do anything to help you if you happen to be using tabs. That has now changed.

PHP_CodeSniffer has a new command line argument --tab-width=4 that will replace tabs inside a file with the number of spaces specified (4 in this case). There is a bit of code checking that tabs are replaced with the correct number of spaces (tabs do not always equal exactly the tab width) so it is not just a straight string replacement. That means there is a bit of additional overhead when checking files, but I don't think it is noticeable.

The benefit of using this option is that you can use all the existing sniffs to check your code and they will not produce errors about tab indentation and alignment. By the time the code gets to them, all tabs have been replaced. This makes it easier to generate your own standard using existing sniffs, and makes it easier to write sniffs as you don't have to take both indentation methods into account.

Of course, you don't have to use this feature. You can still write your own sniffs that explicitly check for tab indentation and alignment.

You can view the full changelog, and download the release, on the package download page.