Skip to content

Commit 9fe36ad

Browse files
committed
clippy
1 parent b4a74cb commit 9fe36ad

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/render.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ impl Entry {
1212

1313
let location = format!("{}:{}", self.location.file.to_string_lossy(), self.location.line);
1414

15-
if self.text.len() > 0 {
15+
if ! self.text.is_empty() {
1616
write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true);
1717
write_ansi(&mut stdout, Color::Ansi256(243), format!(" ({})", location).as_str(), false);
1818
} else {
19-
write_ansi(&mut stdout, Color::Cyan, &location.as_str(), true);
19+
write_ansi(&mut stdout, Color::Cyan, location.as_str(), true);
2020
}
2121

22-
write!(&mut stdout, "\n").unwrap();
22+
writeln!(&mut stdout).unwrap();
2323
}
2424
}
2525

@@ -81,7 +81,7 @@ pub fn render_entries(entries: Vec<Entry>) {
8181
// todo0 -> 0
8282
// todo00 -> -1
8383
// Therefore: 'todo0' + priority.abs() * '0'
84-
str.push_str(String::from_utf8(vec![b'0'; priority.abs() as usize]).unwrap().as_str());
84+
str.push_str(String::from_utf8(vec![b'0'; priority.unsigned_abs()]).unwrap().as_str());
8585

8686
str
8787
},
@@ -90,31 +90,31 @@ pub fn render_entries(entries: Vec<Entry>) {
9090
};
9191

9292
write_ansi(&mut stdout, Color::Red, format!("## {}", &priority_notation).as_str(), true);
93-
write!(stdout, "\n").unwrap();
93+
writeln!(stdout).unwrap();
9494

9595
for item in priority_entries.get(priority).unwrap() {
9696
item.render();
9797
}
9898

99-
println!("");
99+
println!();
100100
}
101101

102102
let mut category_keys = category_entries.keys().collect::<Vec<&String>>();
103103
category_keys.sort_by(|a, b| a.partial_cmp(b).unwrap());
104104

105105
for category in category_keys {
106106
write_ansi(&mut stdout, Color::Green, format!("## {}", &category).as_str(), true);
107-
write!(stdout, "\n").unwrap();
107+
writeln!(stdout).unwrap();
108108

109109
for item in category_entries.get(category).unwrap() {
110110
item.render();
111111
}
112112

113-
println!("");
113+
println!();
114114
}
115115

116116
write_ansi(&mut stdout, Color::White, "## Other", true);
117-
write!(stdout, "\n").unwrap();
117+
writeln!(stdout).unwrap();
118118

119119
generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap());
120120

src/scan.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,25 @@ fn parse_priority(word: &str) -> Option<isize> {
7979
let priority_substr = lowercase_word.split("todo").nth(1).unwrap();
8080

8181
if priority_substr.len() == 1 {
82-
return Some(priority_substr.to_string().parse::<isize>().unwrap());
82+
Some(priority_substr.to_string().parse::<isize>().unwrap())
8383
} else if priority_substr.chars().all(|ch| ch == '0') {
8484
// todo0: 1 - 1 = 0
8585
// todo00: 1 - 2 = -1
86-
return Some(1 - priority_substr.len() as isize);
86+
Some(1 - priority_substr.len() as isize)
8787
} else {
88-
return None; // invalid syntax like todo11
88+
None // invalid syntax like todo11
8989
}
9090
}
9191

9292
/// Remove closing tags, comments, and whitespace
9393
fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str {
94-
return line.split_once(delimiter_word).unwrap().1
94+
line.split_once(delimiter_word).unwrap().1
9595
.trim()
9696
.trim_end_matches("*/")
9797
.trim_end_matches("-->")
9898
.trim_end_matches("--}}")
9999
.trim_end_matches("/>")
100-
.trim();
100+
.trim()
101101
}
102102

103103
pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec<PathBuf>) {
@@ -114,7 +114,7 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec<PathBu
114114
}
115115

116116
if line.trim() == "*" {
117-
if let Ok(realpath) = canonicalize(&base_dir) {
117+
if let Ok(realpath) = canonicalize(base_dir) {
118118
excludes.push(realpath);
119119
}
120120

@@ -217,10 +217,9 @@ pub fn scan_string(str: String, filename: PathBuf, entries: &mut Vec<Entry>) {
217217
}
218218

219219
pub fn scan_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
220-
match std::fs::read_to_string(path) {
221-
Ok(str) => scan_string(str, path.to_path_buf(), entries),
222-
Err(_) => (),
223-
};
220+
if let Ok(str) = std::fs::read_to_string(path) {
221+
scan_string(str, path.to_path_buf(), entries);
222+
}
224223

225224
Ok(())
226225
}
@@ -237,7 +236,7 @@ pub fn scan_dir(dir: &Path, entries: &mut Vec<Entry>, excludes: &mut Vec<PathBuf
237236
// so the exclude would not affect anything inside the for loop. For that reason, we re-check if
238237
// `dir` hasn't become excluded after running `add_excludes_from_gitignore`.
239238
for exclude in &*excludes {
240-
if canonicalize(dir.to_path_buf()).unwrap() == *exclude {
239+
if canonicalize(dir).unwrap() == *exclude {
241240
return Ok(());
242241
}
243242
}
@@ -347,11 +346,7 @@ pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()>
347346
let section = line.split_once("# ").unwrap().1;
348347
let cleaned_section = section.to_lowercase().trim_end_matches(':').trim().to_string();
349348

350-
if cleaned_section == "todo" || cleaned_section == "todos" {
351-
in_todo_section = true;
352-
} else {
353-
in_todo_section = false;
354-
}
349+
in_todo_section = cleaned_section == "todo" || cleaned_section == "todos";
355350

356351
continue;
357352
}

0 commit comments

Comments
 (0)