-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Account for titlecase in casing lints #155469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,37 @@ | ||
| use super::{is_camel_case, to_camel_case}; | ||
| use super::{is_upper_camel_case, to_upper_camel_case}; | ||
|
|
||
| #[test] | ||
| fn camel_case() { | ||
| assert!(!is_camel_case("userData")); | ||
| assert_eq!(to_camel_case("userData"), "UserData"); | ||
| assert!(!is_upper_camel_case("userData")); | ||
| assert_eq!(to_upper_camel_case("userData"), "UserData"); | ||
|
|
||
| assert!(is_camel_case("X86_64")); | ||
| assert!(is_upper_camel_case("X86_64")); | ||
|
|
||
| assert!(!is_camel_case("X86__64")); | ||
| assert_eq!(to_camel_case("X86__64"), "X86_64"); | ||
| assert!(!is_upper_camel_case("X86__64")); | ||
| assert_eq!(to_upper_camel_case("X86__64"), "X86_64"); | ||
|
|
||
| assert!(!is_camel_case("Abc_123")); | ||
| assert_eq!(to_camel_case("Abc_123"), "Abc123"); | ||
| assert!(!is_upper_camel_case("Abc_123")); | ||
| assert_eq!(to_upper_camel_case("Abc_123"), "Abc123"); | ||
|
|
||
| assert!(!is_camel_case("A1_b2_c3")); | ||
| assert_eq!(to_camel_case("A1_b2_c3"), "A1B2C3"); | ||
| assert!(!is_upper_camel_case("A1_b2_c3")); | ||
| assert_eq!(to_upper_camel_case("A1_b2_c3"), "A1B2C3"); | ||
|
|
||
| assert!(!is_camel_case("ONE_TWO_THREE")); | ||
| assert_eq!(to_camel_case("ONE_TWO_THREE"), "OneTwoThree"); | ||
| assert!(!is_upper_camel_case("ONE_TWO_THREE")); | ||
| assert_eq!(to_upper_camel_case("ONE_TWO_THREE"), "OneTwoThree"); | ||
|
|
||
| // FIXME(@Jules-Bertholet): This test doesn't work due to what I believe | ||
| // is a Unicode spec bug - uppercase Georgian letters have | ||
| // incorrect titlecase mappings. | ||
| // I've reported it to Unicode. | ||
| // Georgian mtavruli is only used in all-caps | ||
| //assert!(!is_upper_camel_case("ᲫალაᲔრთობაშია")); | ||
| //assert_eq!(to_upper_camel_case("ᲫალაᲔრთობაშია"), "ძალა_ერთობაშია"); | ||
|
|
||
| assert!(!is_upper_camel_case("LJNJaaaDŽooo")); | ||
| assert_eq!(to_upper_camel_case("LJNJaaLjNJaDŽooo"), "LjnjaaLjNjaDžooo"); | ||
|
|
||
| // Final sigma | ||
| assert!(!is_upper_camel_case("ΦΙΛΟΣ_ΦΙΛΟΣ")); | ||
| assert_eq!(to_upper_camel_case("ΦΙΛΟΣ_ΦΙΛΟΣ"), "ΦιλοςΦιλος"); | ||
| assert!(is_upper_camel_case("ΦιλοσΦιλοσ")); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #![allow(dead_code)] | ||
| #![forbid(non_snake_case)] | ||
|
|
||
| // 2. non_snake_case | ||
|
|
||
|
|
||
| fn LJNJaaLjNJaDŽooo() {} | ||
| //~^ ERROR function `LJNJaaLjNJaDŽooo` should have a snake case name | ||
| //~| WARN identifier contains 5 non normalized (NFKC) characters | ||
|
|
||
| fn LjnjaaLjNjaDžooo() {} | ||
| //~^ ERROR function `LjnjaaLjNjaDžooo` should have a snake case name | ||
| //~| WARN identifier contains 5 non normalized (NFKC) characters | ||
|
|
||
| // test final sigma casing | ||
| fn ΦΙΛΟΣ_ΦΙΛΟΣ() {} | ||
| //~^ ERROR function `ΦΙΛΟΣ_ΦΙΛΟΣ` should have a snake case name | ||
|
|
||
| fn Σ() {} | ||
| //~^ ERROR function `Σ` should have a snake case name | ||
|
|
||
| fn ΦΙΛΟΣ_Σ() {} | ||
| //~^ ERROR function `ΦΙΛΟΣ_Σ` should have a snake case name | ||
|
|
||
| fn Σ_ΦΙΛΟΣ() {} | ||
| //~^ ERROR function `Σ_ΦΙΛΟΣ` should have a snake case name | ||
|
|
||
| // this is ok | ||
| fn φιλοσ_φιλοσ() {} | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| warning: identifier contains 5 non normalized (NFKC) characters: 'LJ', 'NJ', 'Lj', 'NJ', and 'DŽ' | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:7:4 | ||
| | | ||
| LL | fn LJNJaaLjNJaDŽooo() {} | ||
| | ^^^^^^^^^^^ | ||
| | | ||
| = note: these characters are included in the Not_NFKC Unicode general security profile | ||
| = note: `#[warn(uncommon_codepoints)]` on by default | ||
|
|
||
| warning: identifier contains 5 non normalized (NFKC) characters: 'Lj', 'nj', 'Lj', 'Nj', and 'Dž' | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:11:4 | ||
| | | ||
| LL | fn LjnjaaLjNjaDžooo() {} | ||
| | ^^^^^^^^^^^ | ||
| | | ||
| = note: these characters are included in the Not_NFKC Unicode general security profile | ||
|
|
||
| error: function `LJNJaaLjNJaDŽooo` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:7:4 | ||
| | | ||
| LL | fn LJNJaaLjNJaDŽooo() {} | ||
| | ^^^^^^^^^^^ help: convert the identifier to snake case: `ljnjaa_ljnja_džooo` | ||
| | | ||
| note: the lint level is defined here | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:2:11 | ||
| | | ||
| LL | #![forbid(non_snake_case)] | ||
| | ^^^^^^^^^^^^^^ | ||
|
|
||
| error: function `LjnjaaLjNjaDžooo` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:11:4 | ||
| | | ||
| LL | fn LjnjaaLjNjaDžooo() {} | ||
| | ^^^^^^^^^^^ help: convert the identifier to snake case: `ljnjaa_ljnja_džooo` | ||
|
|
||
| error: function `ΦΙΛΟΣ_ΦΙΛΟΣ` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:16:4 | ||
| | | ||
| LL | fn ΦΙΛΟΣ_ΦΙΛΟΣ() {} | ||
| | ^^^^^^^^^^^ help: convert the identifier to snake case: `φιλος_φιλος` | ||
|
|
||
| error: function `Σ` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:19:4 | ||
| | | ||
| LL | fn Σ() {} | ||
| | ^ help: convert the identifier to snake case: `σ` | ||
|
|
||
| error: function `ΦΙΛΟΣ_Σ` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:22:4 | ||
| | | ||
| LL | fn ΦΙΛΟΣ_Σ() {} | ||
| | ^^^^^^^ help: convert the identifier to snake case: `φιλος_σ` | ||
|
|
||
| error: function `Σ_ΦΙΛΟΣ` should have a snake case name | ||
| --> $DIR/lint-nonstandard-style-unicode-2.rs:25:4 | ||
| | | ||
| LL | fn Σ_ΦΙΛΟΣ() {} | ||
| | ^^^^^^^ help: convert the identifier to snake case: `σ_φιλος` | ||
|
|
||
| error: aborting due to 6 previous errors; 2 warnings emitted | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.