-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Avoid D403
if first char cannot be uppercased
#4283
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,15 @@ pub fn capitalized(checker: &mut Checker, docstring: &Docstring) { | |
if first_char.is_uppercase() { | ||
return; | ||
}; | ||
if first_char | ||
.to_uppercase() | ||
.next() | ||
.map_or(false, |uppercase_first_char| { | ||
uppercase_first_char == first_char | ||
}) | ||
{ | ||
return; | ||
} | ||
Comment on lines
+62
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I wonder if we should change the check above to Edit: |
||
|
||
let capitalized_word = first_char.to_uppercase().to_string() + first_word_chars.as_str(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know why
to_uppercase
returns an iterator? When would it have 0, or more than 1 element?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Unicode.
The problem is that there's absolutely no guarantee that converting the case of a single code point will result in a single code point. For example, "ß" uppercases to "SS".
We avoid checking further if it's not an ASCII alphabet whose code is just a few lines above this, but I think you already updated the code :)