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

PSR2.ControlStructures.SwitchDeclaration can remove comments on the same line as the case statement while fixing #3352

Closed
umherirrender opened this issue May 12, 2021 · 1 comment · Fixed by #3354

Comments

@umherirrender
Copy link

Describe the bug
Running PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE can remove comments which are on the same line as the case statement

Code sample

$test = 2;

switch ( $test ) {
	case 2: // comment followed by empty line

		echo "test 2";
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <rule ref="PSR2.ControlStructures.SwitchDeclaration" />
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcbf test.php ...
  3. The comment is gone.
$test = 2;

switch ( $test ) {
	case 2:
		echo "test 2";
}

Expected behavior
The remove of the empty line is correct, but the comment should stay from my point of view.

Versions (please complete the following information):

  • OS: Windows 10
  • PHP: 8.0
  • PHPCS: 3.6.0
  • Standard: -

Additional context
The fixer starts directly after the colon/scope opener to remove everything there, not at the end of the line

Seems an issue since the fix for #683, which ignores the comments, but does not adjust the fixer part.

@jrfnl
Copy link
Contributor

jrfnl commented May 13, 2021

@umherirrender Good catch! Thanks for reporting this. PR #3354 should fix this. Testing appreciated.

@gsherwood gsherwood added this to the 3.6.1 milestone May 23, 2021
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation May 23, 2021
@gsherwood gsherwood changed the title phpcbf fix for PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE can remove comments on the same line as the case statement PSR2.ControlStructures.SwitchDeclaration can remove comments on the same line as the case statement while fixing May 27, 2021
gsherwood added a commit that referenced this issue May 27, 2021
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging a pull request may close this issue.

3 participants