summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt')
-rw-r--r--src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt b/src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt
new file mode 100644
index 000000000..8e6e18ed4
--- /dev/null
+++ b/src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt
@@ -0,0 +1,21 @@
+### What it does
+Checks for calls to `ends_with` with possible file extensions
+and suggests to use a case-insensitive approach instead.
+
+### Why is this bad?
+`ends_with` is case-sensitive and may not detect files with a valid extension.
+
+### Example
+```
+fn is_rust_file(filename: &str) -> bool {
+ filename.ends_with(".rs")
+}
+```
+Use instead:
+```
+fn is_rust_file(filename: &str) -> bool {
+ let filename = std::path::Path::new(filename);
+ filename.extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
+}
+``` \ No newline at end of file