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/EmptyPHPStatement: inconsistent behavior when fixing superfluous semicolon #728

Open
4 tasks done
rodrigoprimo opened this issue Nov 25, 2024 · 1 comment
Open
4 tasks done

Comments

@rodrigoprimo
Copy link
Contributor

rodrigoprimo commented Nov 25, 2024

Describe the bug

While working on #699, I noticed an inconsistency in how the Generic.CodeAnalysis.EmptyPHPStatement sniff fixes superfluous semicolons placed right after a PHP open tag when the PHP ini directive short_open_tag is enabled.

If a normal open tag is used, the superfluous semicolon is removed, and a space is left between the open tag and the rest of the code. If a shot open tag is used, no space is left between the open tag and the rest of the code. I'm inclined to think the sniff should behave the same for both types of open tags.

This is probably not a high-priority issue as the resulting code is not a parse error, and short open tags are not very popular.

Related to #593

Code sample

<?php ; my_function(); ?>

<? ; my_function(); ?>

To reproduce

Steps to reproduce the behavior:

  1. Ensure that the short_open_tag ini directive is enabled.
  2. Create a file called test.php with the code sample above.
  3. Run phpcbf --standard=Generic --sniffs=Generic.CodeAnalysis.EmptyPHPStatement test.php
  4. See that the resulting test.php file contains the following. Note there is no space between <? and my_function();.
<?php my_function(); ?>

<?my_function(); ?>

Expected behavior

I expect the sniff to preserve the space between <? and my_function();.

Versions (please complete the following information)

Operating System Ubuntu 24.04
PHP version 8.3
PHP_CodeSniffer version master
Standard Generic
Install type git clone

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@jrfnl
Copy link
Member

jrfnl commented Nov 25, 2024

Leaving a single space after a short open tag makes sense to me and a PR to add special handling for short open tags would be welcome.
Though as you already said: low priority as it's not a parse error and AFAICS not a cause for fixer conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants