Repository navigation
Description
What happens now
citry format keeps a start tag on one line when three things hold: the tag fits in 100 characters, no attribute already spans several lines, and, when the tag has two or more attributes, none of them is longer than 50 characters (half the width). Otherwise it puts each attribute on its own line. Template comments inside a tag count as attributes for this. The rule is in section 6.1 of docs/design/template_formatter.md and in crates/citry_template_formatter/src/printer.rs.
The house rule in CLAUDE.md and the component authoring guide asks for a different layout when a tag has more than two attributes, or one long attribute: each attribute goes on its own line, and the closing > sits on its own line at the tag's indent.
So the formatter undoes hand-written layout that follows the house rule:
<section
class="panel"
id="details"
aria-labelledby="details-title"
>
becomes
<section class="panel" id="details" aria-labelledby="details-title">
What to build
- Teach the formatter the house rule. A start tag with more than two attributes, or with one long attribute, gets one attribute per line. Every other tag keeps the rule above. Each tag has one correct layout, so formatting stays the same whatever the input looked like.
- Add two settings: the attribute count above which a tag is split (2 by default), and the column width. Today the formatter takes no layout settings at all (section 6, and the "Add configuration only from demonstrated use cases" item in section 16.2), so these would be the first. The design must say:
- which width the setting controls: the 100-character line width, the 50-character limit for one attribute, or both;
- where the settings are read from: CLI flags,
pyproject.toml, the VS Code extension settings; - what happens with a value out of range, such as a count of 0 or a negative width.
- Decide whether a template comment inside a tag counts toward the attribute count, as it counts as an attribute today.
- Update the design doc, the formatter's expected-output fixtures under
crates/citry_template_formatter/tests/fixtures/, and the Python, language server and VS Code extension tests to match.
Why it matters now
A dry run of citry format --check --embedded off over the repository's non-test paths, at 4ec0dd175, would change 694 files. It found 1730 groups of changes (a group is one block of changed lines in the diff). The largest kind, 572 groups, joins a tag's attributes onto one line. A rough count over the same diffs finds that about 6 in 10 of the joined tags have more than two attributes, so the house rule asks for those to stay split. The other kinds are listed below for scale:
| Kind | Groups |
|---|---|
| Attributes joined onto one line | 572 |
Self-closing /> becomes /> |
439 |
| Expression and attribute spacing | 201 |
| Blank line gains indentation | 163 |
| Blank lines removed | 125 |
| Attributes wrapped, or children moved to their own lines | 105 |
Space before > removed |
48 |
| Python expression changes | 38 |
| Re-indentation only | 10 |
The rows add up to 1701 of the 1730 groups; the other 29 did not fit any kind. The dry run came before #456 and #457 merged, and #456 removes most of the "Blank line gains indentation" row.
So two things wait for this issue: reformatting the repository with citry format, and adding citry format --check to the fast gate. Reformatting now would join those tags against the house rule, and then split them again once the rule lands. #141 (Citry UI template cleanup, which includes putting each attribute on its own line) does this layout by hand.
One more finding from that dry run, whitespace added between neighbouring tags that had none, is being fixed separately and is not blocked by this issue.
Activity