Skip to content

Commit d01e0d4

Browse files
committed
fix: trim extra newline before frontmatter closing separator (#192)
When updating frontmatter metadata (e.g., via `adrs status`), the yaml_block included a trailing newline that doubled up with the leading newline of the closing `---` separator, producing a blank line. Trim trailing newlines from the yaml block before reconstruction.
1 parent ee59aac commit d01e0d4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

crates/adrs-core/src/repository.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ impl Repository {
482482
yaml_block
483483
};
484484

485+
let yaml_block = yaml_block.trim_end_matches('\n');
485486
Ok(format!("---\n{}{}", yaml_block, after_yaml))
486487
}
487488

@@ -1706,6 +1707,38 @@ Decision.
17061707
assert!(result.contains("links:"));
17071708
assert!(result.contains("target: 1"));
17081709
assert!(result.contains("kind: amends"));
1710+
// No extra blank line before closing ---
1711+
assert!(
1712+
!result.contains("\n\n---"),
1713+
"Should not have extra blank line before closing ---: {:?}",
1714+
result
1715+
);
1716+
}
1717+
1718+
#[test]
1719+
fn test_set_status_no_extra_newline_before_separator() {
1720+
let temp = TempDir::new().unwrap();
1721+
let repo = Repository::init(temp.path(), None, true).unwrap();
1722+
1723+
let content = "---\nnumber: 2\ntitle: Test\ndate: 2026-01-15\nstatus: proposed\n---\n\n## Context\n\nContext.\n";
1724+
let adr_path = repo.adr_path().join("0002-test.md");
1725+
fs::write(&adr_path, content).unwrap();
1726+
1727+
repo.set_status(2, AdrStatus::Accepted, None).unwrap();
1728+
1729+
let result = fs::read_to_string(&adr_path).unwrap();
1730+
assert!(result.contains("status: accepted"));
1731+
// Frontmatter should close cleanly without extra blank line (#192)
1732+
assert!(
1733+
result.contains("\n---\n"),
1734+
"Should have clean closing separator: {:?}",
1735+
result
1736+
);
1737+
assert!(
1738+
!result.contains("\n\n---"),
1739+
"Should not have extra blank line before closing ---: {:?}",
1740+
result
1741+
);
17091742
}
17101743

17111744
#[test]

0 commit comments

Comments
 (0)