about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/path_ends_with_ext.rs
blob: 00d7ede8ef936ff624ad812596f58429ba690d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#![warn(clippy::path_ends_with_ext)]
use std::path::Path;

macro_rules! arg {
    () => {
        ".md"
    };
}

fn test(path: &Path) {
    path.ends_with(".md");
    //~^ path_ends_with_ext

    // some "extensions" are allowed by default
    path.ends_with(".git");

    // most legitimate "dotfiles" are longer than 3 chars, so we allow them as well
    path.ends_with(".bashrc");

    // argument from expn shouldn't trigger
    path.ends_with(arg!());

    path.ends_with("..");
    path.ends_with("./a");
    path.ends_with(".");
    path.ends_with("");
}

// is_some_and was stabilized in 1.70, so suggest map_or(false, ..) if under that
#[clippy::msrv = "1.69"]
fn under_msv(path: &Path) -> bool {
    path.ends_with(".md")
    //~^ path_ends_with_ext
}

fn main() {}