PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » PHP » PHP_CodeSniffer » Bug #8886

Tabs counted as 1 whitespace

Details

Submitted2006-10-07 15:52 UTC
Fromroosmaa at gmail dot com
Assignedsquiz
StatusBogus
PackagePHP_CodeSniffer
PHP Version5.1.2
OSLinux
Roadmaps(Not assigned)

Comments

[2006-10-07 15:52 UTC] roosmaa at gmail dot com

Description:
------------
PHP_CodeSniffer counts tabs as one whitespace when it should count them as 4 whitespaces. At least that's how most IDE's and text editors handle tabs. And it is much saner to use tab for indention than spaces as with spaces you need to do 4x more work...

[2006-10-07 22:34 UTC] squiz at php dot net

You are correct. PHP_CodeSniffer just tokenises the file and allows the sniff to check things like indentation.

If you are using the PEAR coding standards (installed by default) then tabs are banned. Spaces must be used for indentation.

If you wish to use tabs instead of spaces, you would need to write your own sniff to check for the correct indentation. Also note that you cannot count all tabs as 4 spaces anyway as tabs will represent anywhere from 1 to 4 spaces depending on where the next tabstop is on a line.

[2006-10-08 06:53 UTC] roosmaa at gmail dot com

Why on earth would you ban tabs intentionally? I'd say using spaces instead of tabs is a bad coding practice, thus you are forcing users to write bad code by default.

And yes, I know I can create a new sniff, but why would I want to do that because of one bad design decision? And that's the reason I'm reporting this as a bug.

[2006-10-08 07:47 UTC] squiz at php dot net

I don't think you get the concept of PHP_CodeSniffer. This PEAR package provides a framework for you to test your own code. It is released with a coding standard already installed (the PEAR coding standard) because it is a PEAR package.

When you run PHP_CodeSniffer you are asking it to test your code against a coding standard. If you only have the default installed, then you are asking for it to check your code against the PEAR coding standard. PEAR clearly states that tabs are banned:
http://pear.php.net/manual/en/standards.php#standards.indenting

I don't make these rules up, so don't complain to me if you don't like them :)

If anyone wants to use PHP_CodeSniffer to enforce tab indentation rather than space indentation, they will need to write a new sniff to do so. Then, create their own custom coding standard and use PHP_CodeSniffer to enforce that. Let me be very clear on that: PHP_CodeSniffer can enforce multiple coding standards; you just need to install them and tell it which one to use.

So in summary, there is nothing wrong with PHP_CodeSniffer and it's core architecture does not stop you enforcing tab based indentation. What you have is a problem with the PEAR coding standard, which is enforced by PHP_CodeSniffer by default if you haven't installed any additional standards.