diff --git a/Makefile b/Makefile index 186dfdc..ea54975 100644 --- a/Makefile +++ b/Makefile @@ -54,9 +54,9 @@ fmt: ## Format all code cargo fmt --all lint: ## Run clippy lints - cargo clippy --workspace --all-targets --all-features -- -D warnings + cargo clippy --workspace --all-targets --all-features -fix: ## Auto-fix linting issues +lint-fix: ## Auto-fix linting issues cargo clippy --workspace --all-targets --all-features --fix --allow-dirty --allow-staged cargo fmt --all diff --git a/waycast-config/src/lib.rs b/waycast-config/src/lib.rs index e103fca..04b21dd 100644 --- a/waycast-config/src/lib.rs +++ b/waycast-config/src/lib.rs @@ -4,7 +4,7 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use std::path::Path; use std::sync::OnceLock; -use std::{env, fs::File, path::PathBuf}; +use std::{env, path::PathBuf}; #[derive(Debug, Deserialize, Serialize)] pub struct WaycastConfig {} @@ -80,7 +80,7 @@ pub fn cache_path>(file: P) -> Option { } pub fn config_file() -> &'static Config { - CONFIG_SINGLETON.get_or_init(|| init()) + CONFIG_SINGLETON.get_or_init(init) } pub fn get(key: &str) -> Result { diff --git a/waycast-core/src/cache/mod.rs b/waycast-core/src/cache/mod.rs index d206463..02dee79 100644 --- a/waycast-core/src/cache/mod.rs +++ b/waycast-core/src/cache/mod.rs @@ -14,11 +14,11 @@ pub struct CacheTTL {} impl CacheTTL { pub fn hours(hours: u64) -> Option { - return Some(Duration::from_secs(hours * 60 * 60)); + Some(Duration::from_secs(hours * 60 * 60)) } pub fn minutes(minutes: u64) -> Option { - return Some(Duration::from_secs(minutes * 60)); + Some(Duration::from_secs(minutes * 60)) } } diff --git a/waycast-core/src/lib.rs b/waycast-core/src/lib.rs index 8400240..ee28fab 100644 --- a/waycast-core/src/lib.rs +++ b/waycast-core/src/lib.rs @@ -43,6 +43,12 @@ pub struct WaycastLauncher { current_results_by_id: HashMap, } +impl Default for WaycastLauncher { + fn default() -> Self { + Self::new() + } +} + impl WaycastLauncher { pub fn new() -> Self { WaycastLauncher { diff --git a/waycast-gtk/src/main.rs b/waycast-gtk/src/main.rs index b5fa06b..6b1bbcf 100644 --- a/waycast-gtk/src/main.rs +++ b/waycast-gtk/src/main.rs @@ -28,7 +28,7 @@ fn main() { } if let Some(path) = waycast_config::config_path("waycast.css") { - if let Err(_) = ui.apply_css(path) { + if ui.apply_css(path).is_err() { println!("No user css found"); } } diff --git a/waycast-gtk/src/ui/gtk/mod.rs b/waycast-gtk/src/ui/gtk/mod.rs index 47aa9da..095a13a 100644 --- a/waycast-gtk/src/ui/gtk/mod.rs +++ b/waycast-gtk/src/ui/gtk/mod.rs @@ -515,7 +515,7 @@ fn search_for_icon( for cat in &categories { let path = base .join(icon_theme.theme_name()) - .join(if (size != "scalable") { + .join(if size != "scalable" { format!("{}x{}", size, size) } else { size.to_string() @@ -534,7 +534,7 @@ fn search_for_icon( for cat in &categories { let path = base .join("hicolor") - .join(if (size != "scalable") { + .join(if size != "scalable" { format!("{}x{}", size, size) } else { size.to_string() diff --git a/waycast-plugins/src/main.rs b/waycast-plugins/src/main.rs index 2955633..e6e2251 100644 --- a/waycast-plugins/src/main.rs +++ b/waycast-plugins/src/main.rs @@ -1,7 +1,6 @@ -use std::{collections::BTreeMap, path::PathBuf}; -use tokei::{Config, LanguageType, Languages}; +use std::path::PathBuf; use waycast_plugins::projects::{ - framework_detector::{self, FrameworkDetector}, + framework_detector::FrameworkDetector, type_scanner::TypeScanner, }; @@ -16,8 +15,7 @@ pub fn main() { if let Ok(entries) = std::fs::read_dir(PathBuf::from("/home/javi/projects")) { for e in entries .into_iter() - .filter(|e| e.is_ok()) - .map(|e| e.unwrap()) + .flatten() .filter(|e| e.path().is_dir()) { let fw = framework_detector.detect(e.path().to_string_lossy().to_string().as_str()); diff --git a/waycast-plugins/src/projects/framework_detector.rs b/waycast-plugins/src/projects/framework_detector.rs index 63f003b..c8253e8 100644 --- a/waycast-plugins/src/projects/framework_detector.rs +++ b/waycast-plugins/src/projects/framework_detector.rs @@ -21,7 +21,7 @@ crate::frameworks! { files: ["Gemfile"], json_checks: [("package.json", "dependencies.rails"), ("package.json", "devDependencies.rails")], custom: |project_path: &str| { - use crate::projects::framework_macro::{has_file, read_json_config}; + use crate::projects::framework_macro::has_file; // Check for Gemfile with rails gem if let Ok(content) = std::fs::read_to_string(format!("{}/Gemfile", project_path)) { @@ -127,6 +127,12 @@ pub struct FrameworkDetector { heuristics: &'static [&'static dyn FrameworkHeuristics], } +impl Default for FrameworkDetector { + fn default() -> Self { + Self::new() + } +} + impl FrameworkDetector { pub fn new() -> FrameworkDetector { FrameworkDetector { diff --git a/waycast-plugins/src/projects/mod.rs b/waycast-plugins/src/projects/mod.rs index e859521..825ec78 100644 --- a/waycast-plugins/src/projects/mod.rs +++ b/waycast-plugins/src/projects/mod.rs @@ -12,7 +12,7 @@ use std::{ use std::sync::LazyLock; use tokio::sync::Mutex; use waycast_core::{ - cache::{Cache, CacheTTL}, + cache::CacheTTL, LaunchError, LauncherListItem, LauncherPlugin, }; use waycast_macros::{launcher_entry, plugin}; @@ -195,15 +195,9 @@ impl LauncherPlugin for ProjectsPlugin { pub fn new() -> ProjectsPlugin { let search_paths = - match waycast_config::get::>("plugins.projects.search_paths") { - Ok(paths) => paths, - Err(_) => HashSet::new(), - }; + waycast_config::get::>("plugins.projects.search_paths").unwrap_or_default(); - let skip_dirs = match waycast_config::get::>("plugins.projects.skip_dirs") { - Ok(paths) => paths, - Err(_) => HashSet::new(), - }; + let skip_dirs = waycast_config::get::>("plugins.projects.skip_dirs").unwrap_or_default(); let open_command = match waycast_config::get::("plugins.projects.open_command") { Ok(cmd) => cmd, diff --git a/waycast-plugins/src/projects/type_scanner.rs b/waycast-plugins/src/projects/type_scanner.rs index 3741f9e..6c228be 100644 --- a/waycast-plugins/src/projects/type_scanner.rs +++ b/waycast-plugins/src/projects/type_scanner.rs @@ -1,6 +1,6 @@ use std::path::Path; -use tokei::{Config, Language, LanguageType, Languages}; +use tokei::{Config, LanguageType, Languages}; pub struct ProjectLanguage { pub name: String, @@ -12,6 +12,12 @@ pub struct TypeScanner { ignore_langs: [LanguageType; 5], } +impl Default for TypeScanner { + fn default() -> Self { + Self::new() + } +} + impl TypeScanner { pub fn new() -> TypeScanner { TypeScanner { @@ -32,7 +38,7 @@ impl TypeScanner { let mut langs = Languages::new(); langs.get_statistics(&[path], &[], &self.tokei_config); - let total_code: usize = langs.iter().map(|(_, l)| l.code).sum(); + let total_code: usize = langs.values().map(|l| l.code).sum(); let mut rows: Vec = langs .iter() .map(|(lt, l)| {