Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lint(dirs): collapse unnecessarily nested ifs

Ref:
```
Checking statix v0.5.8 (/build/source/bin)
error: this `if` statement can be collapsed
--> bin/src/dirs.rs:50:17
|
50 | / if dir.is_dir() {
51 | | if let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) {
52 | | let mut found = false;
53 | | for entry in fs::read_dir(&dir).ok()? {
... |
70 | | }
| |_________________^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
= note: `-D clippy::collapsible-if` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::collapsible_if)]`
help: collapse nested if block
|
50 ~ if dir.is_dir()
51 ~ && let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) {
52 | let mut found = false;
...
68 | }
69 ~ }
|

error: could not compile `statix` (lib) due to 1 previous error
```

authored by

x10an14 and committed by
Shahar "Dawn" Or
43681f0d 78223ab3

+18 -19
+18 -19
bin/src/dirs.rs
··· 47 47 fn next(&mut self) -> Option<Self::Item> { 48 48 self.files.pop().or_else(|| { 49 49 while let Some(dir) = self.dirs.pop() { 50 - if dir.is_dir() { 51 - if let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) { 52 - let mut found = false; 53 - for entry in fs::read_dir(&dir).ok()? { 54 - let entry = entry.ok()?; 55 - let path = entry.path(); 56 - if path.is_dir() { 57 - self.dirs.push(path); 58 - } else if path.is_file() { 59 - if let Match::None | Match::Whitelist(_) = 60 - self.ignore.matched(&path, false) 61 - { 62 - found = true; 63 - self.files.push(path); 64 - } 65 - } 50 + if dir.is_dir() 51 + && let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) 52 + { 53 + let mut found = false; 54 + for entry in fs::read_dir(&dir).ok()? { 55 + let entry = entry.ok()?; 56 + let path = entry.path(); 57 + if path.is_dir() { 58 + self.dirs.push(path); 59 + } else if path.is_file() 60 + && let Match::None | Match::Whitelist(_) = 61 + self.ignore.matched(&path, false) 62 + { 63 + found = true; 64 + self.files.push(path); 66 65 } 67 - if found { 68 - break; 69 - } 66 + } 67 + if found { 68 + break; 70 69 } 71 70 } 72 71 }