diff options
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/src/display/markdown.rs | 32 | ||||
| -rw-r--r-- | utils/src/input/editor.rs | 14 | ||||
| -rw-r--r-- | utils/src/legacy/display.rs | 2 | ||||
| -rw-r--r-- | utils/src/legacy/env.rs | 5 | ||||
| -rw-r--r-- | utils/src/legacy/globber.rs | 21 | ||||
| -rw-r--r-- | utils/src/legacy/input.rs | 14 | ||||
| -rw-r--r-- | utils/src/legacy/logger.rs | 2 |
7 files changed, 38 insertions, 52 deletions
diff --git a/utils/src/display/markdown.rs b/utils/src/display/markdown.rs index c50085e..f2fef3b 100644 --- a/utils/src/display/markdown.rs +++ b/utils/src/display/markdown.rs @@ -147,7 +147,7 @@ pub fn markdown(text: impl AsRef<str>) -> String { line_result.push_str(&indent); line_result.push_str(&processed_line); } else { - line_result.push_str(" "); + line_result.push(' '); } if !line_result.is_empty() { @@ -218,8 +218,8 @@ fn process_line(line: &str) -> String { } // Check for color tag start [[color]] - if i + 1 < chars.len() && chars[i] == '[' && chars[i + 1] == '[' { - if let Some(end) = find_tag_end(&chars, i) { + if i + 1 < chars.len() && chars[i] == '[' && chars[i + 1] == '[' + && let Some(end) = find_tag_end(&chars, i) { let tag_content: String = chars[i + 2..end].iter().collect(); // Check if it's a closing tag [[/]] @@ -232,11 +232,10 @@ fn process_line(line: &str) -> String { i = end + 2; continue; } - } // Check for bold **text** - if i + 1 < chars.len() && chars[i] == '*' && chars[i + 1] == '*' { - if let Some(end) = find_matching(&chars, i + 2, "**") { + if i + 1 < chars.len() && chars[i] == '*' && chars[i + 1] == '*' + && let Some(end) = find_matching(&chars, i + 2, "**") { let bold_text: String = chars[i + 2..end].iter().collect(); let mut formatted_text = bold_text.bold().to_string(); apply_color_stack(&mut formatted_text, &color_stack); @@ -244,11 +243,10 @@ fn process_line(line: &str) -> String { i = end + 2; continue; } - } // Check for italic *text* - if chars[i] == '*' { - if let Some(end) = find_matching(&chars, i + 1, "*") { + if chars[i] == '*' + && let Some(end) = find_matching(&chars, i + 1, "*") { let italic_text: String = chars[i + 1..end].iter().collect(); let mut formatted_text = italic_text.italic().to_string(); apply_color_stack(&mut formatted_text, &color_stack); @@ -256,11 +254,10 @@ fn process_line(line: &str) -> String { i = end + 1; continue; } - } // Check for underline _text_ - if chars[i] == '_' { - if let Some(end) = find_matching(&chars, i + 1, "_") { + if chars[i] == '_' + && let Some(end) = find_matching(&chars, i + 1, "_") { let underline_text: String = chars[i + 1..end].iter().collect(); let mut formatted_text = format!("\x1b[4m{}\x1b[0m", underline_text); apply_color_stack(&mut formatted_text, &color_stack); @@ -268,11 +265,10 @@ fn process_line(line: &str) -> String { i = end + 1; continue; } - } // Check for angle-bracketed content <text> - if chars[i] == '<' { - if let Some(end) = find_matching(&chars, i + 1, ">") { + if chars[i] == '<' + && let Some(end) = find_matching(&chars, i + 1, ">") { // Include the angle brackets in the output let angle_text: String = chars[i..=end].iter().collect(); let mut formatted_text = angle_text.cyan().to_string(); @@ -281,11 +277,10 @@ fn process_line(line: &str) -> String { i = end + 1; continue; } - } // Check for inline code `text` - if chars[i] == '`' { - if let Some(end) = find_matching(&chars, i + 1, "`") { + if chars[i] == '`' + && let Some(end) = find_matching(&chars, i + 1, "`") { // Include the backticks in the output let code_text: String = chars[i..=end].iter().collect(); let mut formatted_text = code_text.green().to_string(); @@ -294,7 +289,6 @@ fn process_line(line: &str) -> String { i = end + 1; continue; } - } // Regular character let mut current_char = chars[i].to_string(); diff --git a/utils/src/input/editor.rs b/utils/src/input/editor.rs index aa3e1be..45867e5 100644 --- a/utils/src/input/editor.rs +++ b/utils/src/input/editor.rs @@ -30,10 +30,7 @@ pub async fn input_with_editor_cutsom( let status = Command::new(editor).arg(cache_path).status().await?; if !status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Editor exited with non-zero status", - )); + return Err(std::io::Error::other("Editor exited with non-zero status")); } // Read the modified content @@ -42,14 +39,7 @@ pub async fn input_with_editor_cutsom( // Remove comment lines and trim let processed_content: String = content .lines() - .filter_map(|line| { - let trimmed = line.trim(); - if trimmed.starts_with(comment_prefix) { - None - } else { - Some(line) - } - }) + .filter(|line| !line.trim().starts_with(comment_prefix)) .collect::<Vec<&str>>() .join("\n"); diff --git a/utils/src/legacy/display.rs b/utils/src/legacy/display.rs index fc94d90..57f4f5b 100644 --- a/utils/src/legacy/display.rs +++ b/utils/src/legacy/display.rs @@ -1,3 +1,5 @@ +#![allow(clippy::all)] + use colored::*; use just_enough_vcs::lib::data::sheet::SheetMappingMetadata; use std::{ diff --git a/utils/src/legacy/env.rs b/utils/src/legacy/env.rs index 1834cd3..b4ad089 100644 --- a/utils/src/legacy/env.rs +++ b/utils/src/legacy/env.rs @@ -67,10 +67,7 @@ pub fn auto_update_outdate() -> i64 { } match std::env::var("JV_OUTDATED_MINUTES") { - Ok(value) => match value.trim().parse::<i64>() { - Ok(num) => num, - Err(_) => -1, - }, + Ok(value) => value.trim().parse::<i64>().unwrap_or(-1), Err(_) => -1, } } diff --git a/utils/src/legacy/globber.rs b/utils/src/legacy/globber.rs index 4d722db..b6a3032 100644 --- a/utils/src/legacy/globber.rs +++ b/utils/src/legacy/globber.rs @@ -69,9 +69,7 @@ impl Globber { } }; - let pattern = if pattern.is_empty() { - "*".to_string() - } else if pattern == "." { + let pattern = if pattern.is_empty() || pattern == "." { "*".to_string() } else if pattern.ends_with(SPLIT_STR) { format!("{}*", pattern) @@ -182,7 +180,7 @@ impl<T: AsRef<str>> From<T> for Globber { } } -#[derive(Debug, Clone, Hash)] +#[derive(Debug, Clone)] pub enum GlobItem { File(String), Directory(String), @@ -207,6 +205,21 @@ impl std::fmt::Display for GlobItem { } } +impl std::hash::Hash for GlobItem { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + match self { + GlobItem::File(name) => { + state.write_u8(0); + name.hash(state); + } + GlobItem::Directory(name) => { + state.write_u8(1); + name.hash(state); + } + } + } +} + impl Eq for GlobItem {} pub mod constants { diff --git a/utils/src/legacy/input.rs b/utils/src/legacy/input.rs index 95d53cb..501ce69 100644 --- a/utils/src/legacy/input.rs +++ b/utils/src/legacy/input.rs @@ -89,10 +89,7 @@ pub async fn input_with_editor_cutsom( let status = Command::new(editor).arg(cache_path).status().await?; if !status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "Editor exited with non-zero status", - )); + return Err(std::io::Error::other("Editor exited with non-zero status")); } // Read the modified content @@ -101,14 +98,7 @@ pub async fn input_with_editor_cutsom( // Remove comment lines and trim let processed_content: String = content .lines() - .filter_map(|line| { - let trimmed = line.trim(); - if trimmed.starts_with(comment_prefix) { - None - } else { - Some(line) - } - }) + .filter(|line| !line.trim().starts_with(comment_prefix)) .collect::<Vec<&str>>() .join("\n"); diff --git a/utils/src/legacy/logger.rs b/utils/src/legacy/logger.rs index 1bc96c1..7c18d30 100644 --- a/utils/src/legacy/logger.rs +++ b/utils/src/legacy/logger.rs @@ -79,7 +79,7 @@ pub fn build_env_logger(log_path: impl AsRef<Path>, logger_level: LoggerLevel) { builder .format(log_format) - .filter(None, level.clone()) + .filter(None, level) .filter_module("just_enough_vcs", level) .target(combined_target) .init(); |
