wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Generated constants should be UPPER_SNAKE_CASE

Open g00nix opened this issue 3 years ago • 2 comments

Describe the Bug

Generated constants are not upper snake case and this triggers warnings from the rust-analyzer.

Steps to Reproduce

Save this code to a .rs file:

#[wasm_bindgen]
extern "C" {
    pub type Something;
}

Import the required mods and run the rust-analyzer.

Expected Behavior

No warnings should appear.

Actual Behavior

The following error appears:

Diagnostic { code: DiagnosticCode("incorrect-ident-case"), message: "Constant `__wbg_generated_const_Something` should have UPPER_SNAKE_CASE name, e.g. `__WBG_GENERATED_CONST_SOMETHING`", range: 732..747, severity: WeakWarning, unused: false, experimental: false, fixes: Some([Assist { id: AssistId("change_case", QuickFix), label: "Rename to __WBG_GENERATED_CONST_SOMETHING", group: None, target: 732..747, source_change: None }]) }

image

Additional Context

I've tried to disable the warning by using #[allow(non_snake_case,non_upper_case_globals)] but it does not do the trick. I've also tried to tweak the rust-analyzer to ignore this but I also failed.

g00nix avatar May 01 '22 00:05 g00nix

If you use #![allow(non_snake_case,non_upper_case_globals)] in the root of the crate, it silences the errors, although that turns it off in general. I believe that the #[automatically_derived] attribute doesn't work for clippy. Wasm-bindgen shoudl consider adding #[allow(non_snake_case, non_upper_case_globals)] to this generated function.

AnythingJoes avatar Jul 10 '22 01:07 AnythingJoes

Seeing the same thing.

Similar to: https://github.com/rustwasm/wasm-bindgen/issues/2774

Would be great to see a general fix for the clippy issues.

wilfredjonathanjames avatar Aug 08 '22 03:08 wilfredjonathanjames

I'm seeing the same issue. Can someone (a previous contributor) point me in the right direction to make a PR here?

eli-front avatar Nov 03 '22 05:11 eli-front

Can someone (a previous contributor) point me in the right direction to make a PR here?

The macro's code generation is all defined in https://github.com/rustwasm/wasm-bindgen/blob/main/crates/backend/src/codegen.rs, so you'd have to find and fix all the instances where non-upper-snake-case names are generated in that file.

Liamolucko avatar Nov 05 '22 22:11 Liamolucko

I made a PR. Can someone take a look?

eli-front avatar Nov 06 '22 21:11 eli-front