Skip to content

Attributes to #[server] function should be passed through to generated struct #4498

@aisuzuki

Description

@aisuzuki

Description

#[server] macro generates an argument struct from a server function's arguments. For this reason, developers have not way to control Clippy warnings even though the coding styles for the function's argument is correct.

As we already discussed in my PR's comments, attributes to a server function should be passed through to a generated struct.

Example

The code below will cause clippy::struct_field_names Clippy warning:

#[server]
pub async fn fetch_story(
    example1_suffix: String,
    example2_suffix: String,
    example3_suffix: String,
) -> Result<Option<api::Story>, ServerFnError> {

Execute cargo clippy

$ cargo +nightly clippy -- --deny clippy::struct_field_names
Image

Because the generated struct code has all suffixes:

-- snip --
        /**Serialized arguments for the [`fetch_story`] server function.

*/
        #[serde(crate = "leptos::server_fn::serde")]
        pub struct FetchStory {
            pub example1_suffix: String,
            pub example2_suffix: String,
            pub example3_suffix: String,
        }
        #[automatically_derived]
        impl ::core::fmt::Debug for FetchStory {
            #[inline]
-- snip --

And even though #[allow(clippy::struct_field_names)] attribute is added to the function, it isn't passed through to the generated struct:

#[server]
#[allow(clippy::struct_field_names)]   // add clippy directive
pub async fn fetch_story(
    example1_suffix: String,
    example2_suffix: String,
    example3_suffix: String,
) -> Result<Option<api::Story>, ServerFnError> {

Below the generated struct:

-- snip --
        /**Serialized arguments for the [`fetch_story`] server function.

*/
        #[serde(crate = "leptos::server_fn::serde")]
                                                      // <--- `#[allow(clippy::struct_field_names)]` should be here
        pub struct FetchStory {
            pub example1_suffix: String,
            pub example2_suffix: String,
            pub example3_suffix: String,
        }
        #[automatically_derived]
        impl ::core::fmt::Debug for FetchStory {
            #[inline]
-- snip --

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions