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

Commenting/CodeCoverageIgnoreDeprecated: apply rule to OO docblocks too + small other improvements #329

Merged

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Nov 4, 2023

Commenting/CodeCoverageIgnoreDeprecated: minor test improvements

Add some more variation of method prefixes to the tests to safeguard the handling of those better.

Commenting/CodeCoverageIgnoreDeprecated: minor code simplifications

Remove two redundant conditions.

The first is not needed as it's not actually important what token type we encounter, the only thing important is that there is a known attribute opener to skip to.

The second is not needed as the findPrevious() call will always find something, if nothing else, it will find the docblock opener, so checking for false is unnecessary.

Commenting/CodeCoverageIgnoreDeprecated: check OO docblocks too

As things were, the Yoast.Commenting.CodeCoverageIgnoreDeprecated sniff only checked function docblocks to find a @deprecated tag and verify this was accompanied by a @codeCoverageIgnore tag.

However, if a complete class (or other OO structure) is deprecated, we can also safely ignore it for code coverage checking.

This updates the sniff to also check the docblocks of OO structures for @deprecated tags and verifies that, if those are found, they are accompanied by a @codeCoverageIgnore tag.

Two exceptions are made:

  • The rule does not apply to interfaces as those can't contain code, so code coverage is not relevant.
  • The rule does not apply to anonymous classes. Those are treated the same as closures/arrow functions: those are normally nested within another construct and code coverage should be based on the wrapping construct.

Includes tests.

Add some more variation of method prefixes to the tests to safeguard the handling of those better.
Remove two redundant conditions.

The first is not needed as it's not actually important what token type we encounter, the only thing important is that there is a known attribute opener to skip to.

The second is not needed as the `findPrevious()` call will always find something, if nothing else, it will find the docblock opener, so checking for `false` is unnecessary.
As things were, the `Yoast.Commenting.CodeCoverageIgnoreDeprecated` sniff only checked function docblocks to find a `@deprecated` tag and verify this was accompanied by a `@codeCoverageIgnore` tag.

However, if a complete class (or other OO structure) is deprecated, we can also safely ignore it for code coverage checking.

This updates the sniff to also check the docblocks of OO structures for `@deprecated` tags and verifies that, if those are found, they are accompanied by a `@codeCoverageIgnore` tag.

Two exceptions are made:
* The rule does not apply to interfaces as those can't contain code, so code coverage is not relevant.
* The rule does not apply to anonymous classes. Those are treated the same as closures/arrow functions: those are normally nested within another construct and code coverage should be based on the wrapping construct.

Includes tests.
@coveralls
Copy link

Coverage Status

coverage: 97.159% (+0.01%) from 97.146%
when pulling 66ee5cb on JRF/yoastcs-codecoverageignoredeprecated-various-improvements
into 06cf5d2 on develop.

@jrfnl jrfnl merged commit ae39773 into develop Nov 4, 2023
26 checks passed
@jrfnl jrfnl deleted the JRF/yoastcs-codecoverageignoredeprecated-various-improvements branch November 4, 2023 01:18
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.

None yet

2 participants