Suppress mod doc comment with empty [doc] attribute (#2254)

This commit is contained in:
Casey Rodarmor 2024-07-15 09:27:48 -07:00 committed by GitHub
parent d5ebc9515e
commit ea26e451fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View File

@ -96,7 +96,7 @@ impl<'src> Analyzer<'src> {
let mut doc_attr: Option<&str> = None; let mut doc_attr: Option<&str> = None;
for attribute in attributes { for attribute in attributes {
if let Attribute::Doc(ref doc) = attribute { 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 { } else {
return Err(name.token.error(InvalidAttribute { return Err(name.token.error(InvalidAttribute {
item_kind: "Module", item_kind: "Module",

View File

@ -452,7 +452,7 @@ impl Subcommand {
signature_widths: &BTreeMap<&str, usize>, signature_widths: &BTreeMap<&str, usize>,
) { ) {
if let Some(doc) = doc { if let Some(doc) = doc {
if doc.lines().count() <= 1 { if !doc.is_empty() && doc.lines().count() <= 1 {
print!( print!(
"{:padding$}{} {}", "{:padding$}{} {}",
"", "",

View File

@ -787,3 +787,20 @@ fn bad_module_attribute_fails() {
.status(EXIT_FAILURE) .status(EXIT_FAILURE)
.run(); .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();
}