Skip to content

Commit

Permalink
Suppress mod doc comment with empty [doc] attribute (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jul 15, 2024
1 parent d5ebc95 commit ea26e45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'src> Analyzer<'src> {
let mut doc_attr: Option<&str> = None;
for attribute in attributes {
if let Attribute::Doc(ref doc) = attribute {
doc_attr = doc.as_ref().map(|s| s.cooked.as_ref());
doc_attr = Some(doc.as_ref().map(|s| s.cooked.as_ref()).unwrap_or_default());
} else {
return Err(name.token.error(InvalidAttribute {
item_kind: "Module",
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl Subcommand {
signature_widths: &BTreeMap<&str, usize>,
) {
if let Some(doc) = doc {
if doc.lines().count() <= 1 {
if !doc.is_empty() && doc.lines().count() <= 1 {
print!(
"{:padding$}{} {}",
"",
Expand Down
17 changes: 17 additions & 0 deletions tests/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,20 @@ fn bad_module_attribute_fails() {
.status(EXIT_FAILURE)
.run();
}

#[test]
fn empty_doc_attribute_on_module() {
Test::new()
.write("foo.just", "")
.justfile(
r#"
# Suppressed comment
[doc]
mod foo
"#,
)
.test_round_trip(false)
.arg("--list")
.stdout("Available recipes:\n foo ...\n")
.run();
}

0 comments on commit ea26e45

Please sign in to comment.