Navigation Menu

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

findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO #3303

Closed
rebeccahum opened this issue Apr 21, 2021 · 2 comments
Closed

findStartOfStatement() doesn't work with T_OPEN_TAG_WITH_ECHO #3303

rebeccahum opened this issue Apr 21, 2021 · 2 comments

Comments

@rebeccahum
Copy link

rebeccahum commented Apr 21, 2021

Describe the bug
When using findStartOfStatement() in conjunction with T_OPEN_TAG_WITH_ECHO, it skips ahead to code before it.

Code sample

$start_of_statement = $this->phpcsFile->findStartOfStatement( $stackPtr, T_COMMA );

To reproduce
Using the below sample with $stackPtr being esc_attr, I would expect $start_of_statement to return T_OPEN_TAG_WITH_ECHO:

<h1>Test</h1>

<?= '<h2>' , esc_attr( $test ) , '</h2>';

However, it returns T_INLINE_HTML from <h1>Test</h1>.

Expected behavior
I expect it to act similar to the below, where $start_of_statement returns T_ECHO:

<h1>Test</h1>

<?php echo '<h2>' , esc_attr( $test ) , '</h2>';

Versions:

  • OS: [e.g., Windows 10, MacOS 10.15]
  • PHP: 7.4.15
  • PHPCS: master
  • Standard: N/A

Additional context
Ran into it during Automattic/VIP-Coding-Standards#671.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Apr 21, 2021
@gsherwood gsherwood added this to the 3.6.1 milestone Apr 21, 2021
@gsherwood
Copy link
Member

Thanks for reporting this. The fix will be in 3.6.1.

PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Apr 21, 2021
@jrfnl
Copy link
Contributor

jrfnl commented Apr 22, 2021

FYI: inspired by this issue, I've done a review of all uses of T_OPEN_TAG in the repository to verify whether they are - or should be - accompanied by T_OPEN_TAG_WITH_ECHO. I've stayed away from updating sniffs which were typically applying proprietary rules, but still found some 12 sniffs which would benefit from an update for this.

PRs upcoming.

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

No branches or pull requests

3 participants