`open A`, a blank line, `\t; plain`, `open B` formatted the comment to
column 0. beancount reads the indented line as `syntax error, unexpected
INDENT` and the column-0 one as an ordinary comment, so formatting
silently removed an error bean-check reports. The top-level walk keeps
such a comment's indent before the first directive (format.rs, the stated
policy); `emit_leading_comments`, which writes the comments in the gap
before every later directive, dropped it. It now keeps the blanks that
start a comment's line, as bean-format does.
Pinned by an IDEMPOTENCE_MATRIX entry, a format_compat fixture
(`indented_comment_in_leading_gap`, identical to bean-format's output),
and a test that beancount's own errors over the text (the reference
oracle) are the same before and after formatting. P5 says so.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
rledger formatkeeps the indent of an indented comment in the gap before a directive, as bean-format does and as the formatter already did for one before the first directive (format.rs, the top-level walk: "An indented comment line here … keeps its indent"). P5's text says so.Before / after
open A, a blank line,\t; plain,open B(review reproi13a):\t; plainsyntax error, unexpected INDENT\t; plain(unchanged); plainat column 0\t; plain(unchanged)i13a–i13d(comment after a blank line, at the end of the file, after two blank lines, after a column-0 comment) now format byte-identically to bean-format.How
emit_leading_comments, which writes the comments of the leading region of every directive after the first, ignored aWHITESPACEtoken; it now keeps the blanks that start a comment's line and writes them before the comment. Nothing else in the leading region changes (blank lines, trailing whitespace on a blank line, comments at column 0).rledger still reads such a line as a comment, on purpose (P5): this changes only what the formatter writes.
Proof
format_roundtrip_properties::test_format_source_keeps_an_indented_comment_in_a_leading_gap_indented: the fixture formats to itself, and beancount's own errors over the text (the error oracle's reference,__beancount_reference_errors) are on lines 3 and 9 before and after formatting (line 5 sits inside beancount's recovery from line 3; bean-check 3.2.3 agrees).IDEMPOTENCE_MATRIXentryindented_comment_in_leading_gap, andformat_compatfixturecases/indented_comment_in_leading_gap(input = expected = bean-format's output).rledger formaton 1,221 files (compat corpus, every tracked ledger, profiling workloads), release builds oforigin/main1f4b9dc and this branch: byte-identical output and exit status (none of them holds such a comment).scripts/format-idempotence.shandscripts/format-preserves-comments.shon the compat corpus: 676 checked, 0 non-idempotent, 0 diagnostics changed, 0 comment lines dropped.parse_error_lines --jsonl,semantic_snapshot, 45,182 inputs): byte-identical, as expected for a formatter-only change; so no parity run moves and no cache bump.cargo test -p rustledger-parser -p rustledger-loader -p rustledger-lsp --all-features: 2,221 passed, 0 failed. Clippy-D warnings: clean.Merge note
The line-start
\rPR (#3162) also editsemit_leading_comments(aCR_BLANKread like whitespace there): a small textual conflict for whichever lands second.🤖 Generated with Claude Code