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

test(sol-macro): add a test for missing_docs #845

Merged
merged 1 commit into from
Jan 4, 2025
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
5 changes: 4 additions & 1 deletion crates/sol-macro-expander/src/expand/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,10 @@ impl CallLikeExpander<'_> {
let mut tokens = quote! {
#(#attrs)*
pub enum #name {
#(#variants(#types),)*
#(
#[allow(missing_docs)]
#variants(#types),
)*
}

#[automatically_derived]
Expand Down
12 changes: 7 additions & 5 deletions crates/sol-macro-expander/src/expand/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, event: &ItemEvent) -> Result<TokenStream>
#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields, clippy::style)]
#[derive(Clone)]
pub struct #name {
#(
#[allow(missing_docs)]
pub #fields,
)*
#( #fields, )*
}

#[allow(non_camel_case_types, non_snake_case, clippy::pub_underscore_fields, clippy::style)]
Expand Down Expand Up @@ -259,5 +256,10 @@ fn expand_event_topic_field(
} else {
cx.expand_rust_type(&param.ty)
};
quote!(#name: #ty)
let attrs = &param.attrs;
quote! {
#(#attrs)*
#[allow(missing_docs)]
pub #name: #ty
}
}
1 change: 1 addition & 0 deletions crates/sol-macro-expander/src/expand/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ fn expand_fields<'a, P>(
let attrs = &var.attrs;
quote! {
#(#attrs)*
#[allow(missing_docs)]
pub #name: #ty
}
})
Expand Down
64 changes: 64 additions & 0 deletions tests/core-sol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,70 @@ sol! {
}
}

/// Docs
#[deny(missing_docs)]
pub mod no_missing_docs {
alloy_core::sol! {
#[allow(missing_docs)]
contract Allowed {
uint256 public number;

struct MyStruct {
uint256 a;
bool b;
}

function setNumber(uint256 newNumber) public {
number = newNumber;
}

function increment() public {
number++;
}

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

error Transfer2(address from, address to, uint256 value);
error Approval2(address owner, address spender, uint256 value);
}

/// Docs
contract NotAllowed {
/// Docs
uint256 public number;

/// Docs
struct MyStruct {
/// Docs
uint256 a;
/// Docs
bool b;
}

/// Docs
function setNumber(uint256 newNumber) public {
number = newNumber;
}

/// Docs
function increment() public {
number++;
}

/// Docs
event Transfer(address indexed from, address indexed to, uint256 value);
/// Docs
event Approval(address indexed owner, address indexed spender, uint256 value);

/// Docs
error Transfer2(address from, address to, uint256 value);
/// Docs
error Approval2(address owner, address spender, uint256 value);
}
}
}

#[test]
#[cfg_attr(miri, ignore = "foldhash queries time (orlp/foldhash#4)")]
fn do_stuff() {
Expand Down
Loading