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

[3.x] Generic/LineLength: add ability to ignore long comment lines completely #1510

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jun 16, 2017

Adds the ability to set a $ignoreComments property to turn off all notifications about long comment lines.

As suggested & discussed on twitter: https://twitter.com/MrDanack/status/874631725036523520

I've chosen a property-based implementation so as not to break BC for people who may have turned off the warning for long lines (so they only receive the error when the absolute limit has been reached).
If this would be implemented using a different errorcode for comments, these people who now start to see warnings about comments lines where they previously would not.
This property based implementation prevents that.

The property defaults to false which maintains the original behaviour of the sniff.

  • Add property to the Customizable properties list in the wiki

Additionally, when adding the appropriate unit tests, I realized that the other custom properties for this sniff were not yet unit tested, so I've included a separate commit to fix that.

As the sniff uses the T_OPEN_TAG token and then walks through the whole file in one go, the properties need to be changed in the test file before the open tag is encountered.

In practice, this means that the unit tests for the changed properties need to be in separate files.

As the sniff uses the `T_OPEN_TAG` token and then walks through the whole file in one go, the properties need to be changed in the test file **_before_** the open tag is encountered.

In practice, this means that the unit tests for the changed properties need to be in separate files.
@jrfnl jrfnl force-pushed the feature/3.x-line-length-ignore-comments branch from 9200521 to ca96ed3 Compare June 17, 2017 01:56
@gsherwood gsherwood added this to the 3.1.0 milestone Jul 5, 2017
@gsherwood gsherwood merged commit ca96ed3 into squizlabs:master Aug 31, 2017
gsherwood added a commit that referenced this pull request Aug 31, 2017
@gsherwood
Copy link
Member

Thanks a lot for contributing this. Docs updated here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#genericfileslinelength

@jrfnl jrfnl deleted the feature/3.x-line-length-ignore-comments branch August 31, 2017 12:22
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 31, 2017

@gsherwood Thanks for merging this!

@gsherwood
Copy link
Member

This feature was added incorrectly. Instead of ignoring lines that only contain comments, using the new $ignoreComments property ends up ignoring all lines that end with comments, no matter how long the comment is.

Issue found when reviewing #2533

gsherwood added a commit that referenced this pull request Jul 31, 2019
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 31, 2019

Sorry about that. Clearly needed more test cases.

@gsherwood
Copy link
Member

I found the older code confusing in the sniff, so easy mistake to make. I missed it during the review as well - looked fine.

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

Successfully merging this pull request may close these issues.

2 participants