Skip to content

Commit

Permalink
test(sol-macro): add a test for missing_docs (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Jan 4, 2025
1 parent 17b0d1c commit 4a8a53a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
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]
fn do_stuff() {
let mut set = alloy_core::primitives::map::HashSet::<MyStruct>::default();
Expand Down

0 comments on commit 4a8a53a

Please sign in to comment.