mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Merge #6319
6319: Properly identify camel cased acronyms as UpperCamelCase r=popzxc a=ArifRoktim This closes #6305. Co-authored-by: Arif Roktim <arifrroktim@gmail.com>
This commit is contained in:
commit
31db677a94
2 changed files with 34 additions and 3 deletions
|
@ -708,11 +708,23 @@ fn foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incorrect_struct_name() {
|
fn incorrect_struct_names() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
struct non_camel_case_name {}
|
struct non_camel_case_name {}
|
||||||
// ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName`
|
// ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName`
|
||||||
|
|
||||||
|
struct SCREAMING_CASE {}
|
||||||
|
// ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase`
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_diagnostic_for_camel_cased_acronyms_in_struct_name() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
struct AABB {}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -728,11 +740,23 @@ struct SomeStruct { SomeField: u8 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn incorrect_enum_name() {
|
fn incorrect_enum_names() {
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
enum some_enum { Val(u8) }
|
enum some_enum { Val(u8) }
|
||||||
// ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum`
|
// ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum`
|
||||||
|
|
||||||
|
enum SOME_ENUM
|
||||||
|
// ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum`
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_diagnostic_for_camel_cased_acronyms_in_enum_name() {
|
||||||
|
check_diagnostics(
|
||||||
|
r#"
|
||||||
|
enum AABB {}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,13 @@ fn detect_case(ident: &str) -> DetectedCase {
|
||||||
|
|
||||||
if has_uppercase {
|
if has_uppercase {
|
||||||
if !has_lowercase {
|
if !has_lowercase {
|
||||||
DetectedCase::UpperSnakeCase
|
if has_underscore {
|
||||||
|
DetectedCase::UpperSnakeCase
|
||||||
|
} else {
|
||||||
|
// It has uppercase only and no underscores. Ex: "AABB"
|
||||||
|
// This is a camel cased acronym.
|
||||||
|
DetectedCase::UpperCamelCase
|
||||||
|
}
|
||||||
} else if !has_underscore {
|
} else if !has_underscore {
|
||||||
if first_lowercase {
|
if first_lowercase {
|
||||||
DetectedCase::LowerCamelCase
|
DetectedCase::LowerCamelCase
|
||||||
|
@ -180,6 +186,7 @@ mod tests {
|
||||||
check(to_camel_case, "Weird_Case", expect![["WeirdCase"]]);
|
check(to_camel_case, "Weird_Case", expect![["WeirdCase"]]);
|
||||||
check(to_camel_case, "name", expect![["Name"]]);
|
check(to_camel_case, "name", expect![["Name"]]);
|
||||||
check(to_camel_case, "A", expect![[""]]);
|
check(to_camel_case, "A", expect![[""]]);
|
||||||
|
check(to_camel_case, "AABB", expect![[""]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue