Skip to content

Conversation

yescallop
Copy link
Contributor

Currently, the non_snake_case and dead_code lints will not run within component functions because the component macro emits allow attributes for the two lints, which allows room for users to make mistakes. This PR fixes the problem by converting the function name to snake case before prefixing it with __ and dropping the allow attributes for the two lints from the macro.

I have run cargo check on the library and all examples and see no additional warnings. We can have the CI confirm this.

@yescallop yescallop force-pushed the fix-component-lints branch from f68c42b to 61c6c0b Compare November 6, 2024 00:16
@yescallop
Copy link
Contributor Author

The server_fns_axum example failed to build because there are multiple component and server functions with the same name but in different case (rkyv_example and RkyvExample, for example). I changed component and server macros to emit different prefixes (__leptos_component_ and __leptos_server_) to address the problem.

@yescallop yescallop force-pushed the fix-component-lints branch from 61c6c0b to b2efdc3 Compare November 6, 2024 17:05
@yescallop
Copy link
Contributor Author

I don't know why, but I might've run into a cargo fmt bug touching seemingly unrelated code. I thought it would be better not to include those formatting changes, but apparently the CI would not be happy with that! So I included the changes and force-pushed again. Hopefully everything is OK now.

@rakshith-ravi
Copy link
Collaborator

Oh, nevermind, I see what happened here. Perhaps we can have a #[allow(non_snake_case, dead_code)] in the declaration, and another #[warn(non_snake_case, dead_code)] in the body to bring back the lint instead of changing the name of the fn or struct?

Not sure if that would work, but worth a shot

@rakshith-ravi
Copy link
Collaborator

Hi @yescallop. Wanted to check in to see if you had time to check out my comments?

@yescallop
Copy link
Contributor Author

Hi @rakshith-ravi. I guess I get your point. Do you mean something like the following?

#[allow(non_snake_case)]
fn __Example() {
    #[warn(non_snake_case)]
    {
        // body wrapped, this will warn
        let A = ();
    }
}

But I notice that an inner attribute #![allow(non_snake_case)] on the module will not have an effect on the wrapped body, which is an adverse effect of this solution. What do you think?

@rakshith-ravi
Copy link
Collaborator

rakshith-ravi commented Apr 19, 2025

But I notice that an inner attribute #![allow(non_snake_case)] on the module will not have an effect on the wrapped body, which is an adverse effect of this solution. What do you think?

Oh my. Yeah I didn't think about that. Valid point indeed. It just seems very "hacky" to do a __leptos_component__{} 😅

Any other suggestion you have? If not, I guess this could do for now. We can always clean it up later if we think of a better solution

@gbj
Copy link
Collaborator

gbj commented Apr 23, 2025

My only feedback would be that the server_fn_macro crate is used by/can be used by other framework, so perhaps simply __server_... and __component_... rather than __leptos_server etc. would be a better naming convention. Otherwise looks good to me.

@rakshith-ravi
Copy link
Collaborator

Changes made @gbj

@benwis
Copy link
Contributor

benwis commented Aug 14, 2025

@rakshith-ravi Looks like it's been a bit since this was made. If you can resolve the commits I'll see about merging it

@yescallop
Copy link
Contributor Author

Conflicts resolved @benwis

@rakshith-ravi
Copy link
Collaborator

I've triggered the CI. Let's see if there's any issues

@benwis
Copy link
Contributor

benwis commented Aug 17, 2025

Thanks for the PR!

@benwis benwis merged commit 26ecbf4 into leptos-rs:main Aug 17, 2025
283 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants