Repository navigation
fix: measure a start tag with the text that stays on its line - #462
Merged
Merged
Conversation
The formatter puts a start tag on one line when it fits the 100-column
width. It measured the tag alone, plus the end tag of an empty element, so
a tag followed by text it cannot move, as in
`<span class="..." c-id="..." data-...="...">{{ label }}</span>`, was
kept on one line well past the width. The formatter now also counts
the text after `>` that stays on the tag's line whether or not the tag
wraps. That text runs to the end of the source line, or to the next start
tag, which the formatter measures separately. When wrapping could not make
the line fit, because even the line that starts with `>` would be too
long, a tag that fits by itself stays on one line.
With this repository's Ruff configuration, E501 reports 21 long lines on a
formatted copy, down from 36 with the previous formatter and 23 before
formatting, and a second format changes nothing.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 28, 2026
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.
What this fixes
The formatter puts a start tag on one line when it fits its 100-column width. It measured the tag alone, plus the end tag of an empty element. So it joined a tag onto one line even when text it cannot move followed on that line:
became one line of about 120 characters. A dry run of
citry formatover this repository added 13 lines that Ruff reports as E501. This blocks the repository-wide reformat.What changes
same_line_tailinsource.rs, used byfits_one_lineinprinter.rs). That text runs from>or/>to the end of the source line, or to the next start tag, which is measured on its own. It covers text, expressions, end tags and comments, so<div ...></div>and<span ...>{{ label }}</span>are measured as the lines they occupy.>at the tag's column. When even that line would be over the width, as with a long sentence after<p class="lead">, a tag that fits by itself stays on one line.docs/design/template_formatter.md, the M0 fit rule) describes the new rule. It also states the trade-off of stopping at the next start tag. When an outer tag fits and a later tag on the same line does not, the later tag wraps, so its attributes can be indented far to the right. Measuring through later tags would wrap the outer tag first, but it also wraps tags on lines the formatter cannot otherwise shorten. The existing corpus case<main><c-if cond="show">...is one such line.Not done here: counting the Python indent
The formatter measures a template in its own columns. A template inside a Python string sits 6 to 12 columns further right in the file. Counting that would need a new option on
format_template(), which is a change to the PyO3 surface, and that needs a plan first. With this fix, formatted templates in this repository stay within Ruff's 119-character limit: a template line is at most 100 columns plus the string's indent.Tests and checks
New corpus case
tags/wrap-with-same-line-text. It covers:{{ label }}</span>;>line of exactly 100 columns wraps, and one of 101 stays joined;<div ...></div>tail;/>tail;>, which stays one line and moves the child.Its expected output came from the formatter and is stable on a second format. On
main, the first two lines are joined past the width.Existing checks. No existing corpus case changed. The crate's tests and clippy pass. The Python formatter tests pass with an extension built from this branch:
citry_core,citryformat, and thecitry_lspformatting tests.On a copy of the repository's non-test paths, formatted with this branch:
main's formatter and 23 before formatting;Independent review. A reviewer fuzzed 3,600 random templates (nested inline and block tags, text, expressions, comments, CRLF). It found no new errors and no output that changes on a second format. It also read the 78 changed hunks in the repository copy. A second pass checked the guard's arithmetic at the boundary for
>and/>, and looked for output that alternates between two layouts on repeated formats; it found none. Its findings are folded in: the guard, the doc rewrite, the fixture boundaries and the wording. The design doc notes the guard's one limit: it checks only the>line, so a later line indented from that line moves right with it.🤖 Generated with Claude Code