Skip to content

Fix formatter increment @line only on write#16762

Open
straight-shoota wants to merge 3 commits intocrystal-lang:masterfrom
straight-shoota:fix/formatter-increment_lines
Open

Fix formatter increment @line only on write#16762
straight-shoota wants to merge 3 commits intocrystal-lang:masterfrom
straight-shoota:fix/formatter-increment_lines

Conversation

@straight-shoota
Copy link
Copy Markdown
Member

The formatter should never increment lines based on token locations from the lexer.
We can't assume that the output will have similar line breaks as the input. The formatter's job involves adding and removing line breaks to produce a well-formatted result.
With this patch, @line increments in sync with writing to @output. This functionality is limited to #write and #write_line methods. Also the tracking of no_rstrip_lines happens in #write for convenience, and to ensure correct line numbers.

Resolves #16755
Depends on #16761

@straight-shoota straight-shoota self-assigned this Mar 19, 2026
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter labels Mar 19, 2026
@straight-shoota straight-shoota marked this pull request as draft March 19, 2026 20:42
@straight-shoota straight-shoota force-pushed the fix/formatter-increment_lines branch from b6882e8 to d0f714f Compare March 26, 2026 09:36
@straight-shoota straight-shoota marked this pull request as ready for review March 26, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter counts lines from lexer tokens

2 participants