yew icon indicating copy to clipboard operation
yew copied to clipboard

Clippy erroron derive properties - results in snake_case struct names

Open spanishpear opened this issue 3 years ago • 4 comments

Problem

when using #[derive(Properties)] - the autogenerated structures e.g. AppPropsmyprop_name are not SnakeCase, leading to clippy errors

Steps To Reproduce Steps to reproduce the behavior:

  1. Create props for a function component, using #[derive(Properties)]
  2. See clippy errors with incorrect-ident-case

Expected behavior No clippy errors from macros

Screenshots image this is from my own project

Environment:

  • Yew version: v0.20
  • Rust version: 1.65.0

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later

spanishpear avatar Dec 11 '22 15:12 spanishpear

I can't seem to reproduce this. Do these lints also show up during the build or just in the editor? And if so, could you provide a reproducible example I can just run on the command line (editor setup will be hard to get into test cases).

WorldSEnder avatar Dec 11 '22 15:12 WorldSEnder

Looks like the same issue as https://github.com/yewstack/yew/issues/2006 - and is rust-analyzer specific (no errors with clippy/check)

I can only get it to sometimes pop up - but I'll note that cargo expand does show snake_case syntax when expanding the macro

    #[doc(hidden)]
    pub struct HasAppPropschild_with_thing<How>(::std::marker::PhantomData<How>);

with the following app.rs (modifying the starter template) cargo generate --git https://github.com/yewstack/yew-trunk-minimal-template

I'm not sure the compleixty of Vchild is needed, but it was the last time i could get it to show up reliably

use yew::prelude::*;
use yew::virtual_dom::VChild;

#[derive(Clone, PartialEq, Properties)]
pub struct AppProps {
    pub child_with_thing: VChild<TestChild>,
}

#[function_component(App)]
pub fn app() -> Html {
    html! {
        <main>
            <img class="logo" src="https://yew.rs/img/logo.png" alt="Yew logo" />
            <h1>{ "Hello World!" }</h1>
            <span class="subtitle">{ "from Yew with " }<i class="heart" /></span>
        </main>
    }
}

#[function_component(TestChild)]
pub fn render() -> Html {
    html! {
        <p>{"child"}</p>
    }
}

spanishpear avatar Dec 11 '22 17:12 spanishpear

I can only get it to sometimes pop up - but I'll note that cargo expand does show snake_case syntax when expanding the macro

Yep, it's quite to clear to me that the macro output results in these warnings and why. I'm trying to come up with a way to encode this in test cases, so this and similar warnings/errors don't show up in the future. So far, I haven't been able to come up with something that could be run with the CI.

In case you want to just fix the issue, have a look at the macro code, that'd be the place to start.

https://github.com/yewstack/yew/blob/698bd56e61ac20cdca98ac8a97e9f0ce63384c94/packages/yew-macro/src/derive_props/field.rs#L281-L283

There might be other similar names generated around that could get a similar treatment.

WorldSEnder avatar Dec 11 '22 20:12 WorldSEnder

You likely don't want to change the casing in the struct name. It's used for diagnostic information during the type checking process as proc macros don't have type information to generate the errors they need to so they generate code that fails to compile with a comprehensible error message as a workaround

ranile avatar Dec 11 '22 20:12 ranile