Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use the first line of struct field doc as MRO doc comment #485

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions martian-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@

Err(Error::new(
span,
format!(
"{}. You are trying to use it on {} trait implementation.",
ATTR_NOT_ON_TRAIT_IMPL_ERROR, last_ident
),

Check warning on line 330 in martian-derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy_check

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> martian-derive/src/lib.rs:327:9 | 327 | / format!( 328 | | "{}. You are trying to use it on {} trait implementation.", 329 | | ATTR_NOT_ON_TRAIT_IMPL_ERROR, last_ident 330 | | ), | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args = note: requested on the command line with `-W clippy::uninlined-format-args`
))
}

Expand Down Expand Up @@ -518,11 +518,15 @@
}

mro_type = Some(val.value())
} else if attr.path().is_ident("doc") {
} else if attr.path().is_ident("doc") && doc_comment.is_none() {
if let Meta::NameValue(meta) = &attr.meta {
if let Expr::Lit(elit) = &meta.value {
if let Lit::Str(lstr) = &elit.lit {
doc_comment = Some(lstr.value());
let val = lstr.value();
let trimmed = val.trim();
if !trimmed.is_empty() {
doc_comment = Some(trimmed.to_string());
}
}
}
}
Expand All @@ -547,10 +551,10 @@
if blacklist.contains(name.as_str()) {
return syn::Error::new(
field.ident.unwrap().span(),
format!(
"Field name {} is not allowed here since it is a martian keyword",
name
),

Check warning on line 557 in martian-derive/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy_check

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> martian-derive/src/lib.rs:554:17 | 554 | / format!( 555 | | "Field name {} is not allowed here since it is a martian keyword", 556 | | name 557 | | ), | |_________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
)
.to_compile_error()
.into();
Expand All @@ -568,7 +572,7 @@

let doc_comment_code = match doc_comment {
Some(t) => {
quote![Some(#t.trim_start().to_string())]
quote![Some(#t.to_string())]
}
None => quote![None],
};
Expand Down
2 changes: 1 addition & 1 deletion martian-derive/tests/mro/test_struct.mro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SampleDef(

struct Config(
SampleDef[] sample_def "The sample definition",
path reference_path "even more info about reference path" "the_reference_path",
path reference_path "The reference path" "the_reference_path",
int force_cells "The number of cells to force the pipeline to call",
json primers "The primer definitions as a JSON file" "renamed_primers_json.json",
)
Expand Down
Loading