Fix ambiguity with CamelCase diagnostic messages

This commit is contained in:
Matthew Wilding 2024-09-29 16:35:37 +08:00
parent 546339a7be
commit 60219d0b11
No known key found for this signature in database
GPG key ID: D600998BF2EF83B9
4 changed files with 21 additions and 21 deletions

View file

@ -58,7 +58,7 @@ impl fmt::Display for CaseType {
let repr = match self { let repr = match self {
CaseType::LowerSnakeCase => "snake_case", CaseType::LowerSnakeCase => "snake_case",
CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE", CaseType::UpperSnakeCase => "UPPER_SNAKE_CASE",
CaseType::UpperCamelCase => "CamelCase", CaseType::UpperCamelCase => "UpperCamelCase",
}; };
repr.fmt(f) repr.fmt(f)

View file

@ -111,7 +111,7 @@ mod tests {
check(to_lower_snake_case, "lower_snake_case", expect![[""]]); check(to_lower_snake_case, "lower_snake_case", expect![[""]]);
check(to_lower_snake_case, "UPPER_SNAKE_CASE", expect![["upper_snake_case"]]); check(to_lower_snake_case, "UPPER_SNAKE_CASE", expect![["upper_snake_case"]]);
check(to_lower_snake_case, "Weird_Case", expect![["weird_case"]]); check(to_lower_snake_case, "Weird_Case", expect![["weird_case"]]);
check(to_lower_snake_case, "CamelCase", expect![["camel_case"]]); check(to_lower_snake_case, "UpperCamelCase", expect![["upper_camel_case"]]);
check(to_lower_snake_case, "lowerCamelCase", expect![["lower_camel_case"]]); check(to_lower_snake_case, "lowerCamelCase", expect![["lower_camel_case"]]);
check(to_lower_snake_case, "a", expect![[""]]); check(to_lower_snake_case, "a", expect![[""]]);
check(to_lower_snake_case, "abc", expect![[""]]); check(to_lower_snake_case, "abc", expect![[""]]);
@ -121,8 +121,8 @@ mod tests {
#[test] #[test]
fn test_to_camel_case() { fn test_to_camel_case() {
check(to_camel_case, "CamelCase", expect![[""]]); check(to_camel_case, "UpperCamelCase", expect![[""]]);
check(to_camel_case, "CamelCase_", expect![[""]]); check(to_camel_case, "UpperCamelCase_", expect![[""]]);
check(to_camel_case, "_CamelCase", expect![[""]]); check(to_camel_case, "_CamelCase", expect![[""]]);
check(to_camel_case, "lowerCamelCase", expect![["LowerCamelCase"]]); check(to_camel_case, "lowerCamelCase", expect![["LowerCamelCase"]]);
check(to_camel_case, "lower_snake_case", expect![["LowerSnakeCase"]]); check(to_camel_case, "lower_snake_case", expect![["LowerSnakeCase"]]);
@ -143,7 +143,7 @@ mod tests {
check(to_upper_snake_case, "UPPER_SNAKE_CASE", expect![[""]]); check(to_upper_snake_case, "UPPER_SNAKE_CASE", expect![[""]]);
check(to_upper_snake_case, "lower_snake_case", expect![["LOWER_SNAKE_CASE"]]); check(to_upper_snake_case, "lower_snake_case", expect![["LOWER_SNAKE_CASE"]]);
check(to_upper_snake_case, "Weird_Case", expect![["WEIRD_CASE"]]); check(to_upper_snake_case, "Weird_Case", expect![["WEIRD_CASE"]]);
check(to_upper_snake_case, "CamelCase", expect![["CAMEL_CASE"]]); check(to_upper_snake_case, "UpperCamelCase", expect![["UPPER_CAMEL_CASE"]]);
check(to_upper_snake_case, "lowerCamelCase", expect![["LOWER_CAMEL_CASE"]]); check(to_upper_snake_case, "lowerCamelCase", expect![["LOWER_CAMEL_CASE"]]);
check(to_upper_snake_case, "A", expect![[""]]); check(to_upper_snake_case, "A", expect![[""]]);
check(to_upper_snake_case, "ABC", expect![[""]]); check(to_upper_snake_case, "ABC", expect![[""]]);

View file

@ -614,7 +614,7 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
(Some(_), None) => Ordering::Greater, (Some(_), None) => Ordering::Greater,
(None, Some(_)) => Ordering::Less, (None, Some(_)) => Ordering::Less,
(Some(a_name), Some(b_name)) => { (Some(a_name), Some(b_name)) => {
// snake_case < CamelCase < UPPER_SNAKE_CASE // snake_case < UpperCamelCase < UPPER_SNAKE_CASE
let a_text = a_name.as_str().trim_start_matches("r#"); let a_text = a_name.as_str().trim_start_matches("r#");
let b_text = b_name.as_str().trim_start_matches("r#"); let b_text = b_name.as_str().trim_start_matches("r#");
if a_text.starts_with(char::is_lowercase) if a_text.starts_with(char::is_lowercase)

View file

@ -229,10 +229,10 @@ fn foo() {
check_diagnostics( check_diagnostics(
r#" r#"
struct non_camel_case_name {} struct non_camel_case_name {}
// ^^^^^^^^^^^^^^^^^^^ 💡 warn: Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName` // ^^^^^^^^^^^^^^^^^^^ 💡 warn: Structure `non_camel_case_name` should have UpperCamelCase name, e.g. `NonCamelCaseName`
struct SCREAMING_CASE {} struct SCREAMING_CASE {}
// ^^^^^^^^^^^^^^ 💡 warn: Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase` // ^^^^^^^^^^^^^^ 💡 warn: Structure `SCREAMING_CASE` should have UpperCamelCase name, e.g. `ScreamingCase`
"#, "#,
); );
} }
@ -261,10 +261,10 @@ struct SomeStruct { SomeField: u8 }
check_diagnostics( check_diagnostics(
r#" r#"
enum some_enum { Val(u8) } enum some_enum { Val(u8) }
// ^^^^^^^^^ 💡 warn: Enum `some_enum` should have CamelCase name, e.g. `SomeEnum` // ^^^^^^^^^ 💡 warn: Enum `some_enum` should have UpperCamelCase name, e.g. `SomeEnum`
enum SOME_ENUM {} enum SOME_ENUM {}
// ^^^^^^^^^ 💡 warn: Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum` // ^^^^^^^^^ 💡 warn: Enum `SOME_ENUM` should have UpperCamelCase name, e.g. `SomeEnum`
"#, "#,
); );
} }
@ -283,7 +283,7 @@ enum AABB {}
check_diagnostics( check_diagnostics(
r#" r#"
enum SomeEnum { SOME_VARIANT(u8) } enum SomeEnum { SOME_VARIANT(u8) }
// ^^^^^^^^^^^^ 💡 warn: Variant `SOME_VARIANT` should have CamelCase name, e.g. `SomeVariant` // ^^^^^^^^^^^^ 💡 warn: Variant `SOME_VARIANT` should have UpperCamelCase name, e.g. `SomeVariant`
"#, "#,
); );
} }
@ -313,7 +313,7 @@ static some_weird_const: u8 = 10;
check_diagnostics( check_diagnostics(
r#" r#"
struct someStruct; struct someStruct;
// ^^^^^^^^^^ 💡 warn: Structure `someStruct` should have CamelCase name, e.g. `SomeStruct` // ^^^^^^^^^^ 💡 warn: Structure `someStruct` should have UpperCamelCase name, e.g. `SomeStruct`
impl someStruct { impl someStruct {
fn SomeFunc(&self) { fn SomeFunc(&self) {
@ -530,11 +530,11 @@ extern {
check_diagnostics( check_diagnostics(
r#" r#"
trait BAD_TRAIT { trait BAD_TRAIT {
// ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait` // ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have UpperCamelCase name, e.g. `BadTrait`
const bad_const: u8; const bad_const: u8;
// ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST` // ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST`
type BAD_TYPE; type BAD_TYPE;
// ^^^^^^^^ 💡 warn: Type alias `BAD_TYPE` should have CamelCase name, e.g. `BadType` // ^^^^^^^^ 💡 warn: Type alias `BAD_TYPE` should have UpperCamelCase name, e.g. `BadType`
fn BAD_FUNCTION(); fn BAD_FUNCTION();
// ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function` // ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
fn BadFunction(); fn BadFunction();
@ -552,11 +552,11 @@ trait BAD_TRAIT {
check_diagnostics_with_disabled( check_diagnostics_with_disabled(
r#" r#"
trait BAD_TRAIT { trait BAD_TRAIT {
// ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait` // ^^^^^^^^^ 💡 warn: Trait `BAD_TRAIT` should have UpperCamelCase name, e.g. `BadTrait`
const bad_const: u8; const bad_const: u8;
// ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST` // ^^^^^^^^^ 💡 warn: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST`
type BAD_TYPE; type BAD_TYPE;
// ^^^^^^^^ 💡 warn: Type alias `BAD_TYPE` should have CamelCase name, e.g. `BadType` // ^^^^^^^^ 💡 warn: Type alias `BAD_TYPE` should have UpperCamelCase name, e.g. `BadType`
fn BAD_FUNCTION(BAD_PARAM: u8); fn BAD_FUNCTION(BAD_PARAM: u8);
// ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function` // ^^^^^^^^^^^^ 💡 warn: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
// ^^^^^^^^^ 💡 warn: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param` // ^^^^^^^^^ 💡 warn: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param`
@ -664,7 +664,7 @@ mod CheckNonstandardStyle {
mod CheckBadStyle { mod CheckBadStyle {
//^^^^^^^^^^^^^ 💡 error: Module `CheckBadStyle` should have snake_case name, e.g. `check_bad_style` //^^^^^^^^^^^^^ 💡 error: Module `CheckBadStyle` should have snake_case name, e.g. `check_bad_style`
struct fooo; struct fooo;
//^^^^ 💡 error: Structure `fooo` should have CamelCase name, e.g. `Fooo` //^^^^ 💡 error: Structure `fooo` should have UpperCamelCase name, e.g. `Fooo`
} }
mod F { mod F {
@ -676,7 +676,7 @@ mod F {
#[deny(non_snake_case, non_camel_case_types)] #[deny(non_snake_case, non_camel_case_types)]
pub struct some_type { pub struct some_type {
//^^^^^^^^^ 💡 error: Structure `some_type` should have CamelCase name, e.g. `SomeType` //^^^^^^^^^ 💡 error: Structure `some_type` should have UpperCamelCase name, e.g. `SomeType`
SOME_FIELD: u8, SOME_FIELD: u8,
//^^^^^^^^^^ 💡 error: Field `SOME_FIELD` should have snake_case name, e.g. `some_field` //^^^^^^^^^^ 💡 error: Field `SOME_FIELD` should have snake_case name, e.g. `some_field`
SomeField: u16, SomeField: u16,
@ -693,11 +693,11 @@ pub static SomeStatic: u8 = 10;
#[deny(non_snake_case, non_camel_case_types, non_upper_case_globals)] #[deny(non_snake_case, non_camel_case_types, non_upper_case_globals)]
trait BAD_TRAIT { trait BAD_TRAIT {
// ^^^^^^^^^ 💡 error: Trait `BAD_TRAIT` should have CamelCase name, e.g. `BadTrait` // ^^^^^^^^^ 💡 error: Trait `BAD_TRAIT` should have UpperCamelCase name, e.g. `BadTrait`
const bad_const: u8; const bad_const: u8;
// ^^^^^^^^^ 💡 error: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST` // ^^^^^^^^^ 💡 error: Constant `bad_const` should have UPPER_SNAKE_CASE name, e.g. `BAD_CONST`
type BAD_TYPE; type BAD_TYPE;
// ^^^^^^^^ 💡 error: Type alias `BAD_TYPE` should have CamelCase name, e.g. `BadType` // ^^^^^^^^ 💡 error: Type alias `BAD_TYPE` should have UpperCamelCase name, e.g. `BadType`
fn BAD_FUNCTION(BAD_PARAM: u8); fn BAD_FUNCTION(BAD_PARAM: u8);
// ^^^^^^^^^^^^ 💡 error: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function` // ^^^^^^^^^^^^ 💡 error: Function `BAD_FUNCTION` should have snake_case name, e.g. `bad_function`
// ^^^^^^^^^ 💡 error: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param` // ^^^^^^^^^ 💡 error: Parameter `BAD_PARAM` should have snake_case name, e.g. `bad_param`
@ -952,7 +952,7 @@ fn foo() {
let FOO; let FOO;
#[allow(non_snake_case)] #[allow(non_snake_case)]
struct qux; struct qux;
// ^^^ 💡 warn: Structure `qux` should have CamelCase name, e.g. `Qux` // ^^^ 💡 warn: Structure `qux` should have UpperCamelCase name, e.g. `Qux`
fn BAZ() { fn BAZ() {
// ^^^ 💡 error: Function `BAZ` should have snake_case name, e.g. `baz` // ^^^ 💡 error: Function `BAZ` should have snake_case name, e.g. `baz`