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

Rust-analyzer marks structs with snake-case warning #42

Open
FredrikNoren opened this issue Dec 18, 2023 · 7 comments
Open

Rust-analyzer marks structs with snake-case warning #42

FredrikNoren opened this issue Dec 18, 2023 · 7 comments

Comments

@FredrikNoren
Copy link

I'm getting the following warning on all structs that have Tsify:

Function `__wbg_instanceof_JsType_24d65669860e1289` should have snake_case name, e.g. `__wbg_instanceof_js_type_24d65669860e1289`
@rouzwelt
Copy link

yup I get this too, would be good if we get a solution for this

@zomem
Copy link

zomem commented Jan 3, 2024

有一个办法,在文件第一行加上下面的代码,就可以不显示警告了。

#![allow(non_snake_case)]

@rouzwelt
Copy link

rouzwelt commented Jan 5, 2024

有一个办法,在文件第一行加上下面的代码,就可以不显示警告了。

#![allow(non_snake_case)]

this not a good approach and is overall discouraged by the community to change compiler settings

the solution is that the maintainers fix the underlying cause

@nappa85
Copy link

nappa85 commented Jan 8, 2024

Last code update has been 8 months ago, there are PR stuck since July, is this crate dead?

@Pistonight
Copy link

This seems like a rust-analyzer issue. The ___wbg_instanceof is from wasm-bindgen for JsCast and the surrounding block has #[automatically_derived] which should suppress this kind of warnings

@Pistonight
Copy link

This might be a workaround:

#[allow(non_snake_case)]
mod tsify_derive {
    use super::*;
    #[derive(Tsify, Serialize, Deserialize)]
    #[tsify(into_wasm_abi, from_wasm_abi)]
    pub struct MyStruct {
        ...
    }
}
pub use tsify_derive::MyStruct;

Or make a proc macro that does this for you (I just typed it ad-hoc so there might be a few errors, but the idea is there)

use quote::quote;
use proc_macro2::{Ident, Span};
use syn::parse_macro_input;

#[proc_macro_attr]
pub fn suppress_derive_case_warnings(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let parsed = parse_macro_input!(input as DeriveInput);
    let name = &parsed.ident;
    let vis = &parsed.vis;

    let mod_name = Ident::new(&format!("__tsify_mod_{}", name), Span::call_site());

    let expanded = quote! {
        #[allow(non_snake_case)]
        #[automatically_derived]
        mod #mod_name {
            use super::*;
			
            #parsed
        }
        #vis use #mod_name::#name;
    };
	
    expanded.into()
}

Then use it like this

#[suppress_derive_case_warnings]
#[derive(Tsify, Serialize, Deserialize)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct MyStruct {
    ...
}

@Sharpiro
Copy link

Sharpiro commented May 1, 2024

I am only getting this error with rust-analyzer using VS Code, the error itself is not coming from my Rust installation.

I was able to suppress the error with the VS Code setting:

"rust-analyzer.diagnostics.disabled": ["non_snake_case"]

Also needed to restart the rust-analyzer language server.

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

No branches or pull requests

6 participants