Skip to content

Fix node end lines after trailing newlines - #1177

Open
ydah wants to merge 1 commit into
nikic:masterfrom
ydah:fix-node-end-line
Open

ydah wants to merge 1 commit into
nikic:masterfrom
ydah:fix-node-end-line

Conversation

@ydah

@ydah ydah commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

getAttributes() uses the following token's line as endLine. If the node's final token ends with a newline, this includes the next line:

$stmts = $parser->parse("<?php\necho 1 ?>\nfoo\n");
// Echo:       before 2-3, after 2-2
// InlineHTML: before 3-4, after 3-3

Subtract one when the final token ends with \n, matching the inclusive node range. This also corrects interpolated string parts and their heredoc diagnostic positions.

@nikic nikic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is working as intended. If the node includes a trailing newline, then it includes a trailing newline, and positions are reported accordingly.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants