Skip to content

Commit baafe5b

Browse files
committed
Fix formatter inserting blank line between doc comment and attribute on TupleTypeDecl
`get_item_first_line` was missing the `TupleTypeDecl` case, causing it to use the item's own span line instead of the attribute line. This made `format-wado` add a blank line between `/// Doc` and `#[comp_feature(...)]` on every run, failing the CI integrity check. https://claude.ai/code/session_0181NuipeuMorkJgDi4dh3Dp
1 parent a2d73b2 commit baafe5b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

wado-compiler/src/unparse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,6 +2648,7 @@ fn get_item_first_line(item: &Item) -> usize {
26482648
.as_deref()
26492649
.and_then(|a| a.first().map(|a| a.span.line)),
26502650
Item::Trait(t) => first_attr_line(&t.attrs),
2651+
Item::TupleTypeDecl(d) => first_attr_line(&d.attrs),
26512652
_ => None,
26522653
};
26532654
attr_line.unwrap_or(item_line).min(item_line)

wado-compiler/tests/format.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,20 @@ fn test_format_deref_method_preserves_parens() {
884884
);
885885
}
886886

887+
#[test]
888+
fn test_format_doc_comment_before_attribute_no_extra_blank() {
889+
// Doc comment immediately before an attribute must not grow a blank line
890+
let source = "/// Doc\n#[comp_feature(\"tuple\")]\npub type [..T];\n";
891+
let formatted = wado_compiler::format(source).expect("format failed");
892+
assert!(
893+
!formatted.contains("/// Doc\n\n#["),
894+
"doc comment + attribute must not have a blank line between them: {}",
895+
formatted
896+
);
897+
let formatted2 = wado_compiler::format(&formatted).expect("format failed");
898+
assert_eq!(formatted, formatted2, "format should be idempotent");
899+
}
900+
887901
#[test]
888902
fn test_format_idempotent_all_fixtures() {
889903
let fixtures_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures");

0 commit comments

Comments
 (0)