Skip to content

Allow Numbers After Underscore in Camel Case Types #12986

Closed
@bvssvni

Description

@bvssvni

I get this lint on names like:

SVGVersion_1_1

Suggests allowing numbers after underscore by replacing

!ident.contains_char('_')

with

!contains_invalid_after_underscore(ident)

This function to be put within 'is_camel_case':

        // Allow trailing underscore or numeric after underscore.
        fn contains_invalid_after_underscore(ident: &str) -> bool {
            let mut last_was_underscore = false;
            for c in ident.chars() {
                if last_was_underscore && !"_0123456789".contains_char(c) {
                    return true;
                }
                last_was_underscore = c == '_';
            }
            false
        }

Edit: changed to better version suggested by huonw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions