Skip to content

Commit 9492de5

Browse files
committed
[case_sensitive_file_extension_comparisons]: Don't trigger on digits-only extensions
1 parent 2c3213f commit 9492de5

3 files changed

+11
-0
lines changed

clippy_lints/src/methods/case_sensitive_file_extension_comparisons.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub(super) fn check<'tcx>(
3838
&& ext_str.starts_with('.')
3939
&& (ext_str.chars().skip(1).all(|c| c.is_uppercase() || c.is_ascii_digit())
4040
|| ext_str.chars().skip(1).all(|c| c.is_lowercase() || c.is_ascii_digit()))
41+
&& !ext_str.chars().skip(1).all(|c| c.is_ascii_digit())
4142
&& let recv_ty = cx.typeck_results().expr_ty(recv).peel_refs()
4243
&& (recv_ty.is_str() || is_type_lang_item(cx, recv_ty, LangItem::String))
4344
{

tests/ui/case_sensitive_file_extension_comparisons.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,9 @@ fn main() {
6363
let _ = String::new().ends_with("a.ext");
6464
let _ = "str".ends_with("a.extA");
6565
TestStruct {}.ends_with("a.ext");
66+
67+
// Shouldn't fail if the extension has no ascii letter
68+
let _ = String::new().ends_with(".123");
69+
let _ = "str".ends_with(".123");
70+
TestStruct {}.ends_with(".123");
6671
}

tests/ui/case_sensitive_file_extension_comparisons.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ fn main() {
5151
let _ = String::new().ends_with("a.ext");
5252
let _ = "str".ends_with("a.extA");
5353
TestStruct {}.ends_with("a.ext");
54+
55+
// Shouldn't fail if the extension has no ascii letter
56+
let _ = String::new().ends_with(".123");
57+
let _ = "str".ends_with(".123");
58+
TestStruct {}.ends_with(".123");
5459
}

0 commit comments

Comments
 (0)