Repository navigation
fix(format): keep #! and #+ lines that follow a directive - #2792
Merged
Merged
Conversation
The formatter recognized only two of the lexer's four line-comment kinds (COMMENT and PERCENT_COMMENT). A SHEBANG (#!) or EMACS_DIRECTIVE (#+) line was dropped as a directive's leading trivia (cutting off the comments after it too), as a same-line trailing comment, and inside a transaction body. Every comment emitter now calls the canonical convert::is_comment_kind. Closes #2776 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Covers the posting-body and directive-metadata emitters, which no test exercised, and fixes the emit_leading_comments doc and CHANGELOG wording. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
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 changed
rledger format(andformat_source/try_format_source) deleted#!and#+lines whenever they followed a directive. The formatter knew only two of the lexer's four line-comment kinds (COMMENTfor;andPERCENT_COMMENTfor%), so aSHEBANGorEMACS_DIRECTIVEtoken was dropped in these places:; commenton the next line was lost too;At the top of the file a different path already kept them, which is why the bug went unnoticed.
All six comment checks in
cst/format.rsnow call the canonicalconvert::is_comment_kind, in line with the canonical-function discipline in AGENTS.md.bean-formatkeeps these lines.How to test
cargo test -p rustledger-parser --test format_keeps_hash_bang_linesruns 5 tests. Each checks that formatting leaves the file byte-identical and that formatting twice gives the same result. With the format.rs change reverted, 4 of the 5 fail; the top-of-file case passes either way and is there to pin it.Parser, CLI and LSP test suites, clippy
-D warnings, rustdoc-Dwarningsandfmt --checkall pass locally. Parse output is unchanged, so no cache-version bump is needed.Closes #2776
🤖 Generated with Claude Code