From ea26e451faa323d9889ef898ae587166f9cd87d9 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 15 Jul 2024 09:27:48 -0700 Subject: [PATCH] Suppress mod doc comment with empty `[doc]` attribute (#2254) --- src/analyzer.rs | 2 +- src/subcommand.rs | 2 +- tests/modules.rs | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/analyzer.rs b/src/analyzer.rs index b277b42..1f1cece 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -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", diff --git a/src/subcommand.rs b/src/subcommand.rs index 344667e..3444a25 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -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$}{} {}", "", diff --git a/tests/modules.rs b/tests/modules.rs index 14c3c01..97be8a1 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -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(); +}