summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/case_sensitive_file_extension_comparisons.txt
blob: 8e6e18ed4e23a94da0e12c6a38c3064871fcc723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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"))
}
```