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

Generic/OpeningFunctionBraceKernighanRitchie: fix error position #3871

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 9, 2023

Description

The SpaceBeforeBrace error code is about the space before the scope opener, but was being thrown on the parenthesis closer preceding it, which could be confusing when there is a type declaration between the two.

Fixed now.

I haven't added a test as no meaningful test can be added as the error "column" is not part of the test logic.

To see the issue run the following command over the below code snippet:

phpcs test.php --standard=Generic --sniffs=Generic.Functions.OpeningFunctionBraceKernighanRitchie --report=code
function foo( $param_a, $param_b ): Type       {}
//                       The space here   ^   was originally flagged on the close parens, not the open brace.

Suggested changelog entry

N/A

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

The `SpaceBeforeBrace` error code is about the space before the scope opener, but was being thrown on the parenthesis closer preceding it, which could be confusing when there is a type declaration between the two.

Fixed now.

I haven't added a test as no meaningful test can be added as the error "column" is not part of the test logic.
@jrfnl jrfnl added this to the 3.8.0 milestone Aug 9, 2023
@jrfnl jrfnl force-pushed the feature/generic-openingfunctionbracekernighanritchie-fix-error-position branch from 2ec42b2 to 02adef0 Compare August 9, 2023 21:49
@jrfnl jrfnl removed this from the 3.8.0 milestone Aug 9, 2023
Copy link
Contributor

@fredden fredden left a comment

Choose a reason for hiding this comment

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

It took me a little longer to test this proposed change as the sniff skips over this section of code for empty functions. Adding a statement to the example test.php file provided allowed me to test properly. I have now verified both the claim and the fix.

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 2, 2023

Closing as replaced by PHPCSStandards/PHP_CodeSniffer#82

@jrfnl jrfnl closed this Dec 2, 2023
@jrfnl jrfnl deleted the feature/generic-openingfunctionbracekernighanritchie-fix-error-position branch December 2, 2023 02:34
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