Search code examples
rustcamelcasingrust-analyzer

Automatically convert all the identifiers in appropriate case


So for example,

pub enum Format {
    Undefined,
    R4g4UnormPack8,
    R4g4b4a4UnormPack16,
    B4g4r4a4UnormPack16,
    R5g6b5UnormPack16,
    B5g6r5UnormPack16,

    R5G5B5A1_UNORM_PACK16,
    B5G5R5A1_UNORM_PACK16,
    A1R5G5B5_UNORM_PACK16,
    R8_UNORM,
    //...
    G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
    //...
}

The first 6 lines are converted by me using rust-analyzer code action for each line manually.

But as you can guess the list is very long and I'm searching for a way to do these all. Like when building it warns me to convert it.

warning: variant `G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16` should have an upper camel case name
   --> src/core.rs:388:5
    |
388 |     G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to upper camel case: `G10x6B10x6R10x6_3plane420Unorm3pack16`

And I also want to convert it. Is there a way to accomplish this? Any help is appreciated.


Solution

  • It is possible to fix it with rustfix but according to github issue, this lint is filtered out, it can be included via setting env var(ref).

    for Windows:

    set __CARGO_FIX_YOLO="yolo"
    cargo fix
    

    for Unix based:

    export __CARGO_FIX_YOLO="yolo"
    cargo fix
    

    Important :

    Please note that this will try to fix everything in your source, this may bring an unwanted side effects, you may want to check cargo fix ref or you can do some little hack by copying your structures to plain new project then re-add into your project after fixing.