From 9fe36adf20964a7dce69d17045abe8beb94d24d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Tue, 12 Mar 2024 18:45:53 +0100 Subject: [PATCH] clippy --- src/render.rs | 18 +++++++++--------- src/scan.rs | 27 +++++++++++---------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/render.rs b/src/render.rs index 7f818da..d8a5db5 100644 --- a/src/render.rs +++ b/src/render.rs @@ -12,14 +12,14 @@ impl Entry { let location = format!("{}:{}", self.location.file.to_string_lossy(), self.location.line); - if self.text.len() > 0 { + if ! self.text.is_empty() { write_ansi(&mut stdout, Color::Blue, self.text.as_str(), true); write_ansi(&mut stdout, Color::Ansi256(243), format!(" ({})", location).as_str(), false); } else { - write_ansi(&mut stdout, Color::Cyan, &location.as_str(), true); + write_ansi(&mut stdout, Color::Cyan, location.as_str(), true); } - write!(&mut stdout, "\n").unwrap(); + writeln!(&mut stdout).unwrap(); } } @@ -81,7 +81,7 @@ pub fn render_entries(entries: Vec) { // todo0 -> 0 // todo00 -> -1 // Therefore: 'todo0' + priority.abs() * '0' - str.push_str(String::from_utf8(vec![b'0'; priority.abs() as usize]).unwrap().as_str()); + str.push_str(String::from_utf8(vec![b'0'; priority.unsigned_abs()]).unwrap().as_str()); str }, @@ -90,13 +90,13 @@ pub fn render_entries(entries: Vec) { }; write_ansi(&mut stdout, Color::Red, format!("## {}", &priority_notation).as_str(), true); - write!(stdout, "\n").unwrap(); + writeln!(stdout).unwrap(); for item in priority_entries.get(priority).unwrap() { item.render(); } - println!(""); + println!(); } let mut category_keys = category_entries.keys().collect::>(); @@ -104,17 +104,17 @@ pub fn render_entries(entries: Vec) { for category in category_keys { write_ansi(&mut stdout, Color::Green, format!("## {}", &category).as_str(), true); - write!(stdout, "\n").unwrap(); + writeln!(stdout).unwrap(); for item in category_entries.get(category).unwrap() { item.render(); } - println!(""); + println!(); } write_ansi(&mut stdout, Color::White, "## Other", true); - write!(stdout, "\n").unwrap(); + writeln!(stdout).unwrap(); generic_entries.sort_by(|a, b| a.text.partial_cmp(&b.text).unwrap()); diff --git a/src/scan.rs b/src/scan.rs index b251b6b..c4991a2 100644 --- a/src/scan.rs +++ b/src/scan.rs @@ -79,25 +79,25 @@ fn parse_priority(word: &str) -> Option { let priority_substr = lowercase_word.split("todo").nth(1).unwrap(); if priority_substr.len() == 1 { - return Some(priority_substr.to_string().parse::().unwrap()); + Some(priority_substr.to_string().parse::().unwrap()) } else if priority_substr.chars().all(|ch| ch == '0') { // todo0: 1 - 1 = 0 // todo00: 1 - 2 = -1 - return Some(1 - priority_substr.len() as isize); + Some(1 - priority_substr.len() as isize) } else { - return None; // invalid syntax like todo11 + None // invalid syntax like todo11 } } /// Remove closing tags, comments, and whitespace fn clean_line<'a>(line: &'a str, delimiter_word: &str) -> &'a str { - return line.split_once(delimiter_word).unwrap().1 + line.split_once(delimiter_word).unwrap().1 .trim() .trim_end_matches("*/") .trim_end_matches("-->") .trim_end_matches("--}}") .trim_end_matches("/>") - .trim(); + .trim() } pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) { @@ -114,7 +114,7 @@ pub fn add_excludes_from_gitignore(base_dir: &PathBuf, excludes: &mut Vec) { } pub fn scan_file(path: &Path, entries: &mut Vec) -> io::Result<()> { - match std::fs::read_to_string(path) { - Ok(str) => scan_string(str, path.to_path_buf(), entries), - Err(_) => (), - }; + if let Ok(str) = std::fs::read_to_string(path) { + scan_string(str, path.to_path_buf(), entries); + } Ok(()) } @@ -237,7 +236,7 @@ pub fn scan_dir(dir: &Path, entries: &mut Vec, excludes: &mut Vec) -> io::Result<()> let section = line.split_once("# ").unwrap().1; let cleaned_section = section.to_lowercase().trim_end_matches(':').trim().to_string(); - if cleaned_section == "todo" || cleaned_section == "todos" { - in_todo_section = true; - } else { - in_todo_section = false; - } + in_todo_section = cleaned_section == "todo" || cleaned_section == "todos"; continue; }