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

Squiz/PostStatementComment: use a different error code for annotations #627

Merged

Conversation

rodrigoprimo
Copy link
Contributor

Description

As discussed in #560, this PR changes Squiz.Commenting.PostStatementComment to use a different error code when an annotation is found. This will allow ruleset maintainers to selectively exclude the flagging of trailing annotations from their ruleset. For example, for PHPCS itself, this will make it possible to use the // @codeCoverageIgnore annotation where needed.

An annotation is defined as any comment that starts with an optional space, followed by a @ and any character, as long as it is not a whitespace. For now, only // comments are supported as this is the only type of comment supported by this sniff.

This change only applies to PHP code as support for JS will be dropped soon, and JS doesn't seem to follow the same convention of annotations starting with @.

Suggested changelog entry

Squiz.Commenting.PostStatementComment: use a different error code for annotations

Related issues/external references

Fixes #560

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

This commit changes `Squiz.Commenting.PostStatementComment` to use a
different error code when an annotation is found. This will allow
ruleset maintainers to selectively exclude the flagging of trailing
annotations from their ruleset. For example, for PHPCS itself, this will
make it possible to use the `// @codeCoverageIgnore` annotation where
needed.

An annotation is defined as any comment that starts with an optional
space, followed by a `@` and any character, as long as it is not a
whitespace. For now, only `//` comments are supported as this is the only
type of comment supported by this sniff.

This change only applies to PHP code as support for JS will be dropped
soon, and JS doesn't seem to follow the same convention of annotations
starting with `@`.
@rodrigoprimo
Copy link
Contributor Author

Thanks for your review, @jrfnl! I pushed a new commit to implement the changes you suggested and replied to your comments. Could you please take another look?

@jrfnl jrfnl added this to the 3.11.0 milestone Oct 29, 2024
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodrigoprimo Thanks for the PR and fixing the regex (and updating the tests to match). Definitely better now.

Realized only when prepping for merge that the comments in the test case files could be made a little more descriptive. Left two suggestions in-line. Other than that all good.
If you like, I can fix up those comments when merging. Let me know.

Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
@rodrigoprimo rodrigoprimo force-pushed the post-statement-comment-annotation branch from 5c83003 to e28bf06 Compare October 29, 2024 12:12
@rodrigoprimo
Copy link
Contributor Author

@jrfnl, I went ahead and committed your suggestions. Thanks.

@jrfnl jrfnl merged commit 0d3cab5 into PHPCSStandards:master Oct 30, 2024
41 checks passed
@jrfnl jrfnl deleted the post-statement-comment-annotation branch October 30, 2024 03:54
jrfnl pushed a commit that referenced this pull request Oct 30, 2024
#627)

This commit changes `Squiz.Commenting.PostStatementComment` to use a
different error code when an annotation is found. This will allow
ruleset maintainers to selectively exclude the flagging of trailing
annotations from their ruleset. For example, for PHPCS itself, this will
make it possible to use the `// @codeCoverageIgnore` annotation where
needed.

An annotation is defined as any comment that starts with an optional
space, followed by a `@` and any character, as long as it is not a
whitespace. For now, only `//` comments are supported as this is the only
type of comment supported by this sniff.

This change only applies to PHP code as support for JS will be dropped
soon, and JS doesn't seem to follow the same convention of annotations
starting with `@`.
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.

Squiz.Commenting.PostStatementComment should allow trailing annotations from popular PHP tools
2 participants