Skip to content

Squiz/ClassDeclaration: allow for function attributes #825

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 16, 2025

Description

The Squiz.Classes.ClassDeclaration sniff checks the number of blank lines after a class closing brace to be exactly one blank line.

To prevent conflicts with other sniffs checking blank lines before function declarations, it bows out when the next thing after the class declaration is a function declaration and defers to the function declaration sniff to handle the "blank lines before function" check. See squizlabs/PHP_CodeSniffer#2033 for historic context.

However, the above "bowing out" breaks when a function after a class has PHP 8.0+ attributes attached to it and the sniff would still throw the NewlinesAfterCloseBrace error.

Fixed now.

Includes tests.

Note: the new "errors" caused by the new tests are for the MultipleClasses code, which is unrelated to this fix and valid.

Suggested changelog entry

Squiz.Classes.ClassDeclaration: correctly bow out from checking the "lines after class" when the next thing is a function with attribute(s).

Related issues/external references

Related to #152

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Sorry, something went wrong.

@jrfnl jrfnl added this to the 3.12.0 milestone Feb 16, 2025
@jrfnl jrfnl requested a review from fredden February 16, 2025 00:32
@jrfnl jrfnl force-pushed the feature/squiz-classdeclaration-php-80-attributes branch from 16047ce to debbff4 Compare February 16, 2025 13:55
@jrfnl
Copy link
Member Author

jrfnl commented Feb 16, 2025

Force push was to fix a minor typo in the test case file.

@jrfnl jrfnl removed this from the 3.12.0 milestone Mar 3, 2025
@jrfnl jrfnl added this to the 3.12.0 milestone Mar 14, 2025
@jrfnl
Copy link
Member Author

jrfnl commented Mar 14, 2025

Thanks for reviewing this @fredden !

I will rebase the PR (without changes) to get a passing build & merge once CI finishes.

The `Squiz.Classes.ClassDeclaration` sniff checks the number of blank lines _after_ a class closing brace to be exactly one blank line.

To prevent conflicts with other sniffs checking blank lines before function declarations, it bows out when the next thing after the class declaration is a function declaration and defers to the function declaration sniff to handle the "blank lines before function" check.
See squizlabs/PHP_CodeSniffer 2033 for historic context.

However, the above "bowing out" breaks when a function after a class has PHP 8.0+ attributes attached to it and the sniff would still the `NewlinesAfterCloseBrace` error.

Fixed now.

Includes tests.

Note: the new "errors" caused by the new tests are for the `MultipleClasses` code, which is unrelated to this fix and valid.
@jrfnl jrfnl force-pushed the feature/squiz-classdeclaration-php-80-attributes branch from debbff4 to ff62a6e Compare March 14, 2025 01:11
@jrfnl jrfnl merged commit b07cf82 into master Mar 14, 2025
59 checks passed
@jrfnl jrfnl deleted the feature/squiz-classdeclaration-php-80-attributes branch March 14, 2025 02:25
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