File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed
crates/hir_ty/src/diagnostics Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -708,11 +708,23 @@ fn foo() {
708708 }
709709
710710 #[ test]
711- fn incorrect_struct_name ( ) {
711+ fn incorrect_struct_names ( ) {
712712 check_diagnostics (
713713 r#"
714714struct non_camel_case_name {}
715715 // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName`
716+
717+ struct SCREAMING_CASE {}
718+ // ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase`
719+ "# ,
720+ ) ;
721+ }
722+
723+ #[ test]
724+ fn no_diagnostic_for_camel_cased_acronyms_in_struct_name ( ) {
725+ check_diagnostics (
726+ r#"
727+ struct AABB {}
716728"# ,
717729 ) ;
718730 }
@@ -728,11 +740,23 @@ struct SomeStruct { SomeField: u8 }
728740 }
729741
730742 #[ test]
731- fn incorrect_enum_name ( ) {
743+ fn incorrect_enum_names ( ) {
732744 check_diagnostics (
733745 r#"
734746enum some_enum { Val(u8) }
735747 // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum`
748+
749+ enum SOME_ENUM
750+ // ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum`
751+ "# ,
752+ ) ;
753+ }
754+
755+ #[ test]
756+ fn no_diagnostic_for_camel_cased_acronyms_in_enum_name ( ) {
757+ check_diagnostics (
758+ r#"
759+ enum AABB {}
736760"# ,
737761 ) ;
738762 }
Original file line number Diff line number Diff line change @@ -29,7 +29,13 @@ fn detect_case(ident: &str) -> DetectedCase {
2929
3030 if has_uppercase {
3131 if !has_lowercase {
32- DetectedCase :: UpperSnakeCase
32+ if has_underscore {
33+ DetectedCase :: UpperSnakeCase
34+ } else {
35+ // It has uppercase only and no underscores. Ex: "AABB"
36+ // This is a camel cased acronym.
37+ DetectedCase :: UpperCamelCase
38+ }
3339 } else if !has_underscore {
3440 if first_lowercase {
3541 DetectedCase :: LowerCamelCase
@@ -180,6 +186,7 @@ mod tests {
180186 check ( to_camel_case, "Weird_Case" , expect ! [ [ "WeirdCase" ] ] ) ;
181187 check ( to_camel_case, "name" , expect ! [ [ "Name" ] ] ) ;
182188 check ( to_camel_case, "A" , expect ! [ [ "" ] ] ) ;
189+ check ( to_camel_case, "AABB" , expect ! [ [ "" ] ] ) ;
183190 }
184191
185192 #[ test]
You can’t perform that action at this time.
0 commit comments