Skip to content

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 12, 2017

Sister-PR to #1599.


Use the correct error message and code

The "TabsUsed" error message and code were only set before the loop and not reset within the loop.
In practice this meant that as soon as the first non-indent error is encountered, the $error and $errorCode would be overruled and for any indent errors found after that, the wrong message and error code would be thrown.

Allow the sniff to fix tab indents for multi-line /* */ comments

This is the same as done in #1599 for the DisallowSpaceIndent sniff.

Metrics

I also noticed that the metrics were not in line with how they are being recorded in the other sniff as the improvements which were previously added there in #1404 were not yet applied here, quite apart from the metrics needing some love for the /* */ comment.

So I've fixed that too.

For in-depth details of the effect on the metrics of this fix, please see: https://gist.github.com/jrfnl/9a5824916969dc6cf27a24d750d78319

While the metrics for both sniffs are now better than they were before and more in line with each other, there is still a difference between them.

The indentation metrics created by the DisallowSpaceIndentSniff are probably best to use for the historic metrics overviews as - except for comments - the DisallowTabIndentSniff will report "mixed" when it encounters tab indents combined with precision spacing, while the DisallowSpaceIndentSniff can distinguish between the precision spacing and non-precision spacing and will adjust the metrics accordingly.

[Edit] By combining the improvements I'd already made with @gsherwood's improvements in bbe55a5 and 2aa0e09, the metrics should now be quite similar for both sniffs, though I haven't ran any checks to verify.

@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 12, 2017

As a side-note (not covered by this PR), I believe that the "nonIndentTab" part (i.e. tabs found for mid-line alignment or in comment texts) should not be covered by this sniff, as:

  1. It's an undocumented "feature" of the sniff, i.e. unexpected behaviour.
  2. It is not in line with the sister-sniff which does not do this.
  3. Indentation and mid-line alignment are two different things and projects/frameworks may have different rules for each.

For WPCS, I actually created a separate sniff to address "no tabs for mid-line alignment", while tabs are enforced for indentation (via the Generic.WhiteSpace.DisallowSpaceIndent sniff). I'd be happy to pull that sniff here if you're interested and would suggest - though probably in a major version as it is a BC break - removing that part from this sniff.

@jrfnl jrfnl force-pushed the feature/disallowtabindent-multi-line-comments branch 2 times, most recently from a649790 to 0936533 Compare October 17, 2017 01:34
@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 17, 2017

Rebased for merge conflicts & updated to allow for the changes made related to #1702

The "TabsUsed" error message and code were only set before the loop and not reset within the loop.

In practice this meant that as soon as the first non-indent error is encountered, the `$error` and `$errorCode` would be overruled and for any indent errors found after that, the wrong message and error code would be thrown.
@jrfnl jrfnl force-pushed the feature/disallowtabindent-multi-line-comments branch from 0936533 to 939b48a Compare November 22, 2017 05:22
@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 22, 2017

Rebased for merge conflicts & code style...

@gsherwood gsherwood added this to the 3.2.0 milestone Nov 27, 2017
@gsherwood gsherwood merged commit 939b48a into squizlabs:master Nov 27, 2017
gsherwood added a commit that referenced this pull request Nov 27, 2017
@gsherwood
Copy link
Member

Thanks for pointing me here, and thanks for the PR.

@jrfnl jrfnl deleted the feature/disallowtabindent-multi-line-comments branch November 27, 2017 03:15
@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 27, 2017

You're welcome & glad to help.

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

Successfully merging this pull request may close these issues.

2 participants