- Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Hi there,
I have just upgrade from CodeSniffer 1.x to 2.x and have come across what appears to be a bug in the way tabs are expanded. As far as I can see, this has existed since 2.0 and still exists in the latest 2.8 version. I have not tested on 3.x.
Consider the following (invalid, but illustrative) line in a file:
123 56
(the gap in the middle is a tab character, i.e. 123\t56
)
Expected result (assuming a tab-width of 4 characters):
- Translated content: " " (single space character)
- Reported line length = 6
Actual result:
- Translated content: " " (5 space characters)
- Reported line length = 10
As far as I can see, the problem is in the calculation of $firstTabSize
in Files.php
on line 1542.
Instead of:
$firstTabSize = ($tabWidth - ($currColumn % $tabWidth) + 1);
it should be
$firstTabSize = ($tabWidth - (($currColumn - 1) % $tabWidth));
The reason I spotted this was because I suddenly started getting errors from Generic.Files.LineLength.MaxExceeded
which I wasn't getting prior to the upgrade.
I am surprised no-one else has spotted this issue - I know this code path is only travelled for white-space composed entirely of tabs, but I wouldn't expect that to be particularly uncommon.