summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/filetype_is_file.txt
blob: ad14bd62c4de483b76e3d6d04f85a6120614996d (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
### What it does
Checks for `FileType::is_file()`.

### Why is this bad?
When people testing a file type with `FileType::is_file`
they are testing whether a path is something they can get bytes from. But
`is_file` doesn't cover special file types in unix-like systems, and doesn't cover
symlink in windows. Using `!FileType::is_dir()` is a better way to that intention.

### Example
```
let metadata = std::fs::metadata("foo.txt")?;
let filetype = metadata.file_type();

if filetype.is_file() {
    // read file
}
```

should be written as:

```
let metadata = std::fs::metadata("foo.txt")?;
let filetype = metadata.file_type();

if !filetype.is_dir() {
    // read file
}
```