Generic/ScopeIndent: fix false positive after inline HTML before an open tag - #1488
Open
aymericcucherousset wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Generic.WhiteSpace.ScopeIndentreported a false positive when a multi-line function call's opening line started with only whitespace before a<?=/<?phpopen tag (a common shape in template files), and an earlier, unrelated<?= ... ?>block appeared previously in the file.The cause: PHP_CodeSniffer's tokenizer splits multi-line inline HTML into one
T_INLINE_HTMLtoken per physical line, so leading indentation before an open tag is its ownT_INLINE_HTMLtoken, notT_WHITESPACE, which only applies inside PHP code.ScopeIndentSniff's closing-parenthesis handling picked up that whitespace-only token as the "first token on the line", then calledFile::findStartOfStatement()to find the real statement start. SinceT_INLINE_HTMLisn't a stop token for that walk, it crossed into a previous, disjoint short-echo block and anchored the indentation check on unrelated code, producing an incorrect expected indent.The fix skips a whitespace-only inline-HTML token so the sniff lands on the actual PHP open tag on that line, which
findStartOfStatement()already treats as a statement start, avoiding the backward walk entirely for this case. The check is scoped to whitespace-only content specifically, so lines that start with meaningful inline HTML/markup before the open tag (a separate, already-existing and intentionally lenient behavior elsewhere in this file) are unaffected.Suggested changelog entry
Fixed a
Generic.WhiteSpace.ScopeIndentfalse positive for multi-line statements that follow whitespace-only inline HTML before a PHP open tag (e.g. in template files).Related issues/external references
Fixes #1434
Types of changes
PR checklist