Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found #3195

Closed
luketw opened this issue Jan 10, 2021 · 1 comment
Milestone

Comments

@luketw
Copy link
Member

luketw commented Jan 10, 2021

Hi,

I have a standard that uses Generic.WhiteSpace.ScopeIndent with tabIndent set to true. When running it on a certain piece of code, I got the following message:

"Line indented incorrectly; expected 4 tabs, found 4"

The sniff itself was correct, as the applicable code had been indented with 4 tabs, but also one stray space after, thus causing the error - but the message by itself doesn't really make sense as it reads that it satisfied the sniff.

The code in the sniff in question is https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php#L972 - where if it's tab-indented, the amount of the indent is floor()'d to the nearest tab width (usually 4) to print in the message. This seems to make sense if only tabs are being used, but if someone accidentally adds a space to a line, the floor() values for both expected and actual indent will round down to the same amount.

Not the biggest bug. I guess it could be changed to say "found 4 tabs and 1 space" or something but I'm not really sure whether it'd be worth doing over other things, but just wanted to flag it.

@gsherwood gsherwood added this to the 3.6.0 milestone Apr 8, 2021
@gsherwood gsherwood changed the title Confusing message for Generic.WhiteSpace.ScopeIndent (with tabIndent on) when combination of tabs and spaces found Generic.WhiteSpace.ScopeIndent confusing message when combination of tabs and spaces found Apr 8, 2021
gsherwood added a commit that referenced this issue Apr 8, 2021
gsherwood added a commit that referenced this issue Apr 8, 2021
@gsherwood
Copy link
Member

Thanks for reporting this - it was a confusing message.

Now, the message can come out in one of the following formats:

Line indented incorrectly; expected 1 tabs, found 3 spaces
Line indented incorrectly; expected 1 tabs, found 1 tabs and 1 spaces
Line indented incorrectly; expected 1 tabs, found 2

This will be released in version 3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants