]>
Commit | Line | Data |
---|---|---|
f2b60f7d FG |
1 | ### What it does |
2 | Checks for calls to `ends_with` with possible file extensions | |
3 | and suggests to use a case-insensitive approach instead. | |
4 | ||
5 | ### Why is this bad? | |
6 | `ends_with` is case-sensitive and may not detect files with a valid extension. | |
7 | ||
8 | ### Example | |
9 | ``` | |
10 | fn is_rust_file(filename: &str) -> bool { | |
11 | filename.ends_with(".rs") | |
12 | } | |
13 | ``` | |
14 | Use instead: | |
15 | ``` | |
16 | fn is_rust_file(filename: &str) -> bool { | |
17 | let filename = std::path::Path::new(filename); | |
18 | filename.extension() | |
19 | .map_or(false, |ext| ext.eq_ignore_ascii_case("rs")) | |
20 | } | |
21 | ``` |