From 8f11bf6cc6ae4581ebe0b7b869582861a843ef3c Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Tue, 5 Oct 2021 22:05:22 +0200 Subject: [PATCH] fix(core): fix warnings --- espanso/src/cli/daemon/mod.rs | 8 ++++---- espanso/src/cli/daemon/troubleshoot.rs | 8 ++++---- espanso/src/cli/daemon/watcher.rs | 18 ++++++------------ espanso/src/cli/launcher/mod.rs | 19 ++++++++----------- espanso/src/cli/launcher/util.rs | 18 +++++++----------- espanso/src/cli/log.rs | 6 ++---- espanso/src/cli/migrate.rs | 13 +++++-------- espanso/src/cli/modulo/mod.rs | 2 +- espanso/src/cli/modulo/welcome.rs | 4 ++-- espanso/src/cli/package/update.rs | 2 +- espanso/src/cli/workaround/mod.rs | 3 ++- espanso/src/cli/worker/builtin/search.rs | 1 - espanso/src/cli/worker/config.rs | 7 +++---- .../dispatch/executor/clipboard_injector.rs | 2 +- .../src/cli/worker/engine/funnel/detect.rs | 2 +- .../engine/process/middleware/match_select.rs | 2 +- .../process/middleware/matcher/convert.rs | 4 ++-- .../middleware/render/extension/form.rs | 4 ++-- .../engine/process/middleware/render/mod.rs | 4 +--- espanso/src/cli/worker/ipc.rs | 1 + espanso/src/cli/worker/match_cache.rs | 6 +++--- espanso/src/cli/worker/mod.rs | 10 +++++----- espanso/src/cli/worker/secure_input.rs | 7 ++++--- espanso/src/config.rs | 6 +++--- espanso/src/exit_code.rs | 3 +++ espanso/src/gui/modulo/form.rs | 6 +++--- espanso/src/gui/modulo/search.rs | 10 +++++----- espanso/src/icon.rs | 4 ++-- espanso/src/lock.rs | 9 ++++----- espanso/src/logging/mod.rs | 8 +++----- espanso/src/main.rs | 8 ++++---- .../patches/win/onenote_for_windows_10.rs | 2 +- espanso/src/patch/patches/win/vscode_win.rs | 2 +- espanso/src/path/win.rs | 2 +- espanso/src/preferences/default.rs | 7 +++---- 35 files changed, 99 insertions(+), 119 deletions(-) diff --git a/espanso/src/cli/daemon/mod.rs b/espanso/src/cli/daemon/mod.rs index a3499d5..5eed349 100644 --- a/espanso/src/cli/daemon/mod.rs +++ b/espanso/src/cli/daemon/mod.rs @@ -95,7 +95,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 { .expect("unable to initialize config watcher thread"); let (_keyboard_layout_watcher_notify, keyboard_layout_watcher_signal) = unbounded::<()>(); - keyboard_layout_watcher::initialize_and_spawn(_keyboard_layout_watcher_notify.clone()) + keyboard_layout_watcher::initialize_and_spawn(_keyboard_layout_watcher_notify) .expect("unable to initialize keyboard layout watcher thread"); let config_store = @@ -198,7 +198,7 @@ fn daemon_main(args: CliModuleArgs) -> i32 { } fn terminate_worker_if_already_running(runtime_dir: &Path) { - let lock_file = acquire_worker_lock(&runtime_dir); + let lock_file = acquire_worker_lock(runtime_dir); if lock_file.is_some() { return; } @@ -252,7 +252,7 @@ fn spawn_worker( ]; if let Some(start_reason) = &start_reason { args.push("--start-reason"); - args.push(&start_reason); + args.push(start_reason); } command.args(&args); command.with_paths_overrides(paths_overrides); @@ -313,7 +313,7 @@ fn restart_worker( if !has_timed_out { spawn_worker( - &paths_overrides, + paths_overrides, exit_notify, start_reason, ); diff --git a/espanso/src/cli/daemon/troubleshoot.rs b/espanso/src/cli/daemon/troubleshoot.rs index 12b132c..55415d7 100644 --- a/espanso/src/cli/daemon/troubleshoot.rs +++ b/espanso/src/cli/daemon/troubleshoot.rs @@ -78,7 +78,7 @@ pub fn load_config_or_troubleshoot(paths: &Paths, paths_overrides: &PathsOverrid match crate::load_config(&paths.config, &paths.packages) { Ok(load_result) => { if load_result.non_fatal_errors.is_empty() { - return LoadResult::Correct(load_result); + LoadResult::Correct(load_result) } else { let mut troubleshoot_handle = None; @@ -96,13 +96,13 @@ pub fn load_config_or_troubleshoot(paths: &Paths, paths_overrides: &PathsOverrid } } - return LoadResult::Warning(load_result, troubleshoot_handle); + LoadResult::Warning(load_result, troubleshoot_handle) } } Err(_) => { - return LoadResult::Fatal( + LoadResult::Fatal( launch_troubleshoot(paths_overrides).expect("unable to launch troubleshoot GUI"), - ); + ) } } } diff --git a/espanso/src/cli/daemon/watcher.rs b/espanso/src/cli/daemon/watcher.rs index c6181fa..5b039e3 100644 --- a/espanso/src/cli/daemon/watcher.rs +++ b/espanso/src/cli/daemon/watcher.rs @@ -78,11 +78,9 @@ fn watcher_main(config_dir: &Path, watcher_notify: &Sender<()>) { if ["yml", "yaml"].iter().any(|ext| ext == &extension) { // Only load non-hidden yml files !is_file_hidden(&path) - } else if extension == "" { - // No extension, probably a folder - true - } else { - false + } else { + // If there is no extension, it's probably a folder + extension.is_empty() } } else { false @@ -112,9 +110,9 @@ fn is_file_hidden(path: &Path) -> bool { .file_name() .unwrap_or_default() .to_string_lossy() - .starts_with("."); + .starts_with('.'); - return starts_with_dot || has_hidden_attribute(path); + starts_with_dot || has_hidden_attribute(path) } #[cfg(windows)] @@ -126,11 +124,7 @@ fn has_hidden_attribute(path: &Path) -> bool { } let attributes = metadata.unwrap().file_attributes(); - if (attributes & 0x2) > 0 { - true - } else { - false - } + (attributes & 0x2) > 0 } #[cfg(not(windows))] diff --git a/espanso/src/cli/launcher/mod.rs b/espanso/src/cli/launcher/mod.rs index 6b3a892..4c9d63b 100644 --- a/espanso/src/cli/launcher/mod.rs +++ b/espanso/src/cli/launcher/mod.rs @@ -46,7 +46,7 @@ pub fn new() -> CliModule { #[cfg(feature = "modulo")] fn launcher_main(args: CliModuleArgs) -> i32 { - use espanso_modulo::wizard::{DetectedOS, MigrationResult, WizardHandlers, WizardOptions}; + use espanso_modulo::wizard::{MigrationResult, WizardHandlers, WizardOptions}; let paths = args.paths.expect("missing paths in launcher main"); // TODO: should we create a non-gui wizard? We can also use it for the non-modulo versions of espanso @@ -84,8 +84,8 @@ fn launcher_main(args: CliModuleArgs) -> i32 { Box::new(move || match util::migrate_configuration(&paths_clone) { Ok(_) => MigrationResult::Success, Err(error) => match error.downcast_ref::() { - Some(MigrationError::DirtyError) => MigrationResult::DirtyFailure, - Some(MigrationError::CleanError) => MigrationResult::CleanFailure, + Some(MigrationError::Dirty) => MigrationResult::DirtyFailure, + Some(MigrationError::Clean) => MigrationResult::CleanFailure, _ => MigrationResult::UnknownFailure, }, }); @@ -94,12 +94,10 @@ fn launcher_main(args: CliModuleArgs) -> i32 { if cfg!(not(target_os = "linux")) && !preferences.has_completed_wizard() { if cfg!(target_os = "macos") { !crate::path::is_espanso_in_path() + } else if paths.is_portable_mode { + false } else { - if paths.is_portable_mode { - false - } else { - !crate::path::is_espanso_in_path() - } + !crate::path::is_espanso_in_path() } } else { false @@ -118,14 +116,13 @@ fn launcher_main(args: CliModuleArgs) -> i32 { false }; let is_accessibility_enabled_handler = - Box::new(move || accessibility::is_accessibility_enabled()); + Box::new(accessibility::is_accessibility_enabled); let enable_accessibility_handler = Box::new(move || { accessibility::prompt_enable_accessibility(); }); - let preferences_clone = preferences.clone(); let on_completed_handler = Box::new(move || { - preferences_clone.set_completed_wizard(true); + preferences.set_completed_wizard(true); }); // Only show the wizard if a panel should be displayed diff --git a/espanso/src/cli/launcher/util.rs b/espanso/src/cli/launcher/util.rs index 9eb867d..4e04093 100644 --- a/espanso/src/cli/launcher/util.rs +++ b/espanso/src/cli/launcher/util.rs @@ -27,11 +27,7 @@ use crate::{exit_code::{MIGRATE_CLEAN_FAILURE, MIGRATE_DIRTY_FAILURE}, lock::acq pub fn is_legacy_version_running(runtime_path: &Path) -> bool { let legacy_lock_file = acquire_legacy_lock(runtime_path); - if legacy_lock_file.is_none() { - true - } else { - false - } + legacy_lock_file.is_none() } pub fn migrate_configuration(paths: &Paths) -> Result<()> { @@ -58,9 +54,9 @@ pub fn migrate_configuration(paths: &Paths) -> Result<()> { Ok(()) } else { match result.code() { - Some(code) if code == MIGRATE_CLEAN_FAILURE => Err(MigrationError::CleanError.into()), - Some(code) if code == MIGRATE_DIRTY_FAILURE=> Err(MigrationError::DirtyError.into()), - _ => Err(MigrationError::UnexpectedError.into()) + Some(code) if code == MIGRATE_CLEAN_FAILURE => Err(MigrationError::Clean.into()), + Some(code) if code == MIGRATE_DIRTY_FAILURE=> Err(MigrationError::Dirty.into()), + _ => Err(MigrationError::Unexpected.into()) } } } @@ -68,13 +64,13 @@ pub fn migrate_configuration(paths: &Paths) -> Result<()> { #[derive(Error, Debug)] pub enum MigrationError { #[error("clean error")] - CleanError, + Clean, #[error("dirty error")] - DirtyError, + Dirty, #[error("unexpected error")] - UnexpectedError, + Unexpected, } pub fn add_espanso_to_path() -> Result<()> { diff --git a/espanso/src/cli/log.rs b/espanso/src/cli/log.rs index ea47489..d900b83 100644 --- a/espanso/src/cli/log.rs +++ b/espanso/src/cli/log.rs @@ -43,10 +43,8 @@ fn log_main(args: CliModuleArgs) -> i32 { let log_file = File::open(log_file); if let Ok(log_file) = log_file { let reader = BufReader::new(log_file); - for line in reader.lines() { - if let Ok(line) = line { - println!("{}", line); - } + for line in reader.lines().flatten() { + println!("{}", line); } } else { eprintln!("Error reading log file"); diff --git a/espanso/src/cli/migrate.rs b/espanso/src/cli/migrate.rs index 4f631e4..c13e538 100644 --- a/espanso/src/cli/migrate.rs +++ b/espanso/src/cli/migrate.rs @@ -67,7 +67,7 @@ fn migrate_main(args: CliModuleArgs) -> i32 { println!("\n{}\n", "Welcome to espanso v2!".bold()); println!("This migration tool will help you to smoothly transition to the new espanso v2 configuration format."); - println!(""); + println!(); println!( "1. Firstly, espanso will {} your current configuration, located in:\n", "backup".green().bold() @@ -80,7 +80,7 @@ fn migrate_main(args: CliModuleArgs) -> i32 { "convert".bold().green() ); println!(" the current content of the config directory."); - println!(""); + println!(); info!( "backing up the configuration directory: '{}'", @@ -91,15 +91,12 @@ fn migrate_main(args: CliModuleArgs) -> i32 { target_backup_dir.to_string_lossy() ); - if !cli_args.is_present("noconfirm") { - if !Confirm::new() + if !cli_args.is_present("noconfirm") && !Confirm::new() .with_prompt("Do you want to proceed?") .default(true) .interact() - .expect("unable to read choice") - { - return MIGRATE_USER_ABORTED; - } + .expect("unable to read choice") { + return MIGRATE_USER_ABORTED; } println!("Backing up your configuration..."); diff --git a/espanso/src/cli/modulo/mod.rs b/espanso/src/cli/modulo/mod.rs index 9ee9fde..928a0a1 100644 --- a/espanso/src/cli/modulo/mod.rs +++ b/espanso/src/cli/modulo/mod.rs @@ -57,7 +57,7 @@ fn modulo_main(args: CliModuleArgs) -> i32 { return welcome::welcome_main(matches, &paths, &icon_paths); } - if let Some(_) = cli_args.subcommand_matches("troubleshoot") { + if cli_args.subcommand_matches("troubleshoot").is_some() { return troubleshoot::troubleshoot_main(&paths, &icon_paths); } diff --git a/espanso/src/cli/modulo/welcome.rs b/espanso/src/cli/modulo/welcome.rs index c8cb678..846193f 100644 --- a/espanso/src/cli/modulo/welcome.rs +++ b/espanso/src/cli/modulo/welcome.rs @@ -22,8 +22,8 @@ use crate::icon::IconPaths; use espanso_modulo::welcome::*; use espanso_path::Paths; -pub fn welcome_main(matches: &ArgMatches, paths: &Paths, icon_paths: &IconPaths) -> i32 { - let dont_show_again_handler = Box::new(move |dont_show: bool| { +pub fn welcome_main(matches: &ArgMatches, _: &Paths, icon_paths: &IconPaths) -> i32 { + let dont_show_again_handler = Box::new(move |_dont_show: bool| { //preferences.set_should_display_welcome(!dont_show); // TODO: this should probably be deleted if not used? }); diff --git a/espanso/src/cli/package/update.rs b/espanso/src/cli/package/update.rs index ef0ee7f..7646dac 100644 --- a/espanso/src/cli/package/update.rs +++ b/espanso/src/cli/package/update.rs @@ -55,7 +55,7 @@ pub fn update_package(paths: &Paths, matches: &ArgMatches) -> Result i32 { if cli_args.subcommand_matches("secure-input").is_some() { #[cfg(target_os = "macos")] { + use crate::exit_code::WORKAROUND_FAILURE; if let Err(err) = secure_input::run_secure_input_workaround() { error_eprintln!("secure-input workaround reported error: {}", err); return WORKAROUND_FAILURE; diff --git a/espanso/src/cli/worker/builtin/search.rs b/espanso/src/cli/worker/builtin/search.rs index d482101..1bf0756 100644 --- a/espanso/src/cli/worker/builtin/search.rs +++ b/espanso/src/cli/worker/builtin/search.rs @@ -33,6 +33,5 @@ pub fn create_match_trigger_search_bar( triggers: trigger.map(|trigger| vec![trigger]).unwrap_or_default(), hotkey, action: |_| EventType::ShowSearchBar, - ..Default::default() } } diff --git a/espanso/src/cli/worker/config.rs b/espanso/src/cli/worker/config.rs index 5371d7c..450fd89 100644 --- a/espanso/src/cli/worker/config.rs +++ b/espanso/src/cli/worker/config.rs @@ -56,7 +56,7 @@ impl<'a> ConfigManager<'a> { pub fn active_context(&self) -> (Arc, MatchSet) { let config = self.active(); let match_paths = config.match_paths(); - (config.clone(), self.match_store.query(&match_paths)) + (config.clone(), self.match_store.query(match_paths)) } pub fn default(&self) -> Arc { @@ -86,9 +86,8 @@ impl<'a> espanso_engine::process::MatchFilter for ConfigManager<'a> { .collect(); let builtin_matches: Vec = matches_ids - .into_iter() - .filter(|id| is_builtin_match(**id)) - .map(|id| *id) + .iter() + .filter(|id| is_builtin_match(**id)).copied() .collect(); let mut output = active_user_defined_matches; diff --git a/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs b/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs index d01094a..5207f4a 100644 --- a/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs +++ b/espanso/src/cli/worker/engine/dispatch/executor/clipboard_injector.rs @@ -197,7 +197,7 @@ impl<'a> Drop for ClipboardRestoreGuard<'a> { } fn parse_combination(combination: &str) -> Option> { - let tokens = combination.split("+"); + let tokens = combination.split('+'); let mut keys: Vec = Vec::new(); for token in tokens { keys.push(Key::parse(token)?); diff --git a/espanso/src/cli/worker/engine/funnel/detect.rs b/espanso/src/cli/worker/engine/funnel/detect.rs index 3c7deba..ddd2e50 100644 --- a/espanso/src/cli/worker/engine/funnel/detect.rs +++ b/espanso/src/cli/worker/engine/funnel/detect.rs @@ -50,7 +50,7 @@ impl<'a> funnel::Source<'a> for DetectSource { status: convert_to_engine_status(keyboard_event.status), variant: keyboard_event .variant - .map(|variant| convert_to_engine_variant(variant)), + .map(convert_to_engine_variant), }), }, InputEvent::Mouse(mouse_event) => Event { diff --git a/espanso/src/cli/worker/engine/process/middleware/match_select.rs b/espanso/src/cli/worker/engine/process/middleware/match_select.rs index 96c2507..c6e816a 100644 --- a/espanso/src/cli/worker/engine/process/middleware/match_select.rs +++ b/espanso/src/cli/worker/engine/process/middleware/match_select.rs @@ -51,7 +51,7 @@ impl<'a> MatchSelectorAdapter<'a> { impl<'a> MatchSelector for MatchSelectorAdapter<'a> { fn select(&self, matches_ids: &[i32], is_search: bool) -> Option { - let matches = self.match_provider.get_matches(&matches_ids); + let matches = self.match_provider.get_matches(matches_ids); let search_items: Vec = matches .into_iter() .map(|m| { diff --git a/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs b/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs index 3652e13..7b4e4ee 100644 --- a/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs +++ b/espanso/src/cli/worker/engine/process/middleware/matcher/convert.rs @@ -64,7 +64,7 @@ impl<'a> MatchConverter<'a> { for trigger in cause.triggers.iter() { matches.push(RollingMatch::from_string( m.id, - &trigger, + trigger, &StringMatchOptions { case_insensitive: cause.propagate_case, left_word: cause.left_word, @@ -80,7 +80,7 @@ impl<'a> MatchConverter<'a> { for trigger in m.triggers.iter() { matches.push(RollingMatch::from_string( m.id, - &trigger, + trigger, &StringMatchOptions::default(), )) } diff --git a/espanso/src/cli/worker/engine/process/middleware/render/extension/form.rs b/espanso/src/cli/worker/engine/process/middleware/render/extension/form.rs index c161919..dd9fbe7 100644 --- a/espanso/src/cli/worker/engine/process/middleware/render/extension/form.rs +++ b/espanso/src/cli/worker/engine/process/middleware/render/extension/form.rs @@ -78,7 +78,7 @@ fn convert_fields(fields: &Params) -> HashMap { .and_then(|val| val.as_array()) .map(|arr| { arr - .into_iter() + .iter() .flat_map(|choice| choice.as_string()) .cloned() .collect() @@ -95,7 +95,7 @@ fn convert_fields(fields: &Params) -> HashMap { .and_then(|val| val.as_array()) .map(|arr| { arr - .into_iter() + .iter() .flat_map(|choice| choice.as_string()) .cloned() .collect() diff --git a/espanso/src/cli/worker/engine/process/middleware/render/mod.rs b/espanso/src/cli/worker/engine/process/middleware/render/mod.rs index 0a5e793..68fcd3d 100644 --- a/espanso/src/cli/worker/engine/process/middleware/render/mod.rs +++ b/espanso/src/cli/worker/engine/process/middleware/render/mod.rs @@ -86,9 +86,7 @@ fn generate_global_vars_map(config_provider: &dyn ConfigProvider) -> HashMap) - EventHandlerResponse::NoResponse } + #[allow(unreachable_patterns)] unexpected_event => { warn!( "received unexpected event in worker ipc handler: {:?}", diff --git a/espanso/src/cli/worker/match_cache.rs b/espanso/src/cli/worker/match_cache.rs index cef198c..29e37ae 100644 --- a/espanso/src/cli/worker/match_cache.rs +++ b/espanso/src/cli/worker/match_cache.rs @@ -55,7 +55,7 @@ impl<'a> super::engine::process::middleware::render::MatchProvider<'a> for Match } fn get(&self, id: i32) -> Option<&'a Match> { - self.cache.get(&id).map(|m| *m) + self.cache.get(&id).copied() } } @@ -104,11 +104,11 @@ impl<'a> CombinedMatchCache<'a> { } pub fn get(&self, match_id: i32) -> Option> { - if let Some(user_match) = self.user_match_cache.cache.get(&match_id).map(|m| *m) { + if let Some(user_match) = self.user_match_cache.cache.get(&match_id).copied() { return Some(MatchVariant::User(user_match)); } - if let Some(builtin_match) = self.builtin_match_cache.get(&match_id).map(|m| *m) { + if let Some(builtin_match) = self.builtin_match_cache.get(&match_id).copied() { return Some(MatchVariant::Builtin(builtin_match)); } diff --git a/espanso/src/cli/worker/mod.rs b/espanso/src/cli/worker/mod.rs index 57978ed..473b5f8 100644 --- a/espanso/src/cli/worker/mod.rs +++ b/espanso/src/cli/worker/mod.rs @@ -138,7 +138,7 @@ fn worker_main(args: CliModuleArgs) -> i32 { // This is needed to avoid "dangling" worker processes // if the daemon crashes or is forcefully terminated. if cli_args.is_present("monitor-daemon") { - daemon_monitor::initialize_and_spawn(&paths.runtime, engine_exit_notify.clone()) + daemon_monitor::initialize_and_spawn(&paths.runtime, engine_exit_notify) .expect("unable to initialize daemon monitor thread"); } @@ -159,20 +159,20 @@ fn worker_main(args: CliModuleArgs) -> i32 { Ok(mode) => match mode { ExitMode::Exit => { info!("exiting worker process..."); - return WORKER_SUCCESS; + WORKER_SUCCESS } ExitMode::ExitAllProcesses => { info!("exiting worker process and daemon..."); - return WORKER_EXIT_ALL_PROCESSES; + WORKER_EXIT_ALL_PROCESSES } ExitMode::RestartWorker => { info!("exiting worker (to be restarted)"); - return WORKER_RESTART; + WORKER_RESTART } }, Err(err) => { error!("unable to read engine exit mode: {:?}", err); - return WORKER_GENERAL_ERROR; + WORKER_GENERAL_ERROR } } } diff --git a/espanso/src/cli/worker/secure_input.rs b/espanso/src/cli/worker/secure_input.rs index 13aeaf3..3288a41 100644 --- a/espanso/src/cli/worker/secure_input.rs +++ b/espanso/src/cli/worker/secure_input.rs @@ -17,12 +17,10 @@ * along with espanso. If not, see . */ -use std::time::Duration; - use anyhow::Result; use crossbeam::channel::Sender; -use log::{error, info}; +#[allow(dead_code)] pub enum SecureInputEvent { Disabled, Enabled { app_name: String, app_path: String }, @@ -36,6 +34,9 @@ pub fn initialize_and_spawn(_secure_input_send: Sender) -> Res #[cfg(target_os = "macos")] pub fn initialize_and_spawn(secure_input_sender: Sender) -> Result<()> { + use log::{error, info}; + use std::time::Duration; + std::thread::Builder::new() .name("secure-input-monitor".to_string()) .spawn(move || { diff --git a/espanso/src/config.rs b/espanso/src/config.rs index 1ade53a..d091b42 100644 --- a/espanso/src/config.rs +++ b/espanso/src/config.rs @@ -79,8 +79,8 @@ pub struct ConfigLoadResult { } pub fn load_config(config_path: &Path, packages_path: &Path) -> Result { - if espanso_config::is_legacy_config(&config_path) { - let (config_store, match_store) = espanso_config::load_legacy(&config_path, &packages_path) + if espanso_config::is_legacy_config(config_path) { + let (config_store, match_store) = espanso_config::load_legacy(config_path, packages_path) .context("unable to load legacy config")?; Ok(ConfigLoadResult { @@ -92,7 +92,7 @@ pub fn load_config(config_path: &Path, packages_path: &Path) -> Result FormUI for ModuloFormUI<'a> { match json { Ok(json) => { if json.is_empty() { - return Ok(None); + Ok(None) } else { - return Ok(Some(json)); + Ok(Some(json)) } } Err(error) => { - return Err(error.into()); + Err(error.into()) } } } diff --git a/espanso/src/gui/modulo/search.rs b/espanso/src/gui/modulo/search.rs index 053089d..02a5405 100644 --- a/espanso/src/gui/modulo/search.rs +++ b/espanso/src/gui/modulo/search.rs @@ -42,7 +42,7 @@ impl<'a> SearchUI for ModuloSearchUI<'a> { let modulo_config = ModuloSearchConfig { title: "espanso", hint, - items: convert_items(&items), + items: convert_items(items), }; let json_config = serde_json::to_string(&modulo_config)?; @@ -53,13 +53,13 @@ impl<'a> SearchUI for ModuloSearchUI<'a> { match json { Ok(json) => { if let Some(Value::String(selected_id)) = json.get("selected") { - return Ok(Some(selected_id.clone())); + Ok(Some(selected_id.clone())) } else { - return Ok(None); + Ok(None) } } Err(error) => { - return Err(error.into()); + Err(error.into()) } } } @@ -81,7 +81,7 @@ struct ModuloSearchItemConfig<'a> { } // TODO: test -fn convert_items<'a>(items: &'a [SearchItem]) -> Vec> { +fn convert_items(items: &[SearchItem]) -> Vec { items.iter().map(|item| ModuloSearchItemConfig { id: &item.id, label: &item.label, diff --git a/espanso/src/icon.rs b/espanso/src/icon.rs index 172bd38..dd8d63f 100644 --- a/espanso/src/icon.rs +++ b/espanso/src/icon.rs @@ -113,10 +113,10 @@ fn extract_icon(data: &[u8], target_file: &Path) -> Result { "skipping extraction for '{:?}', as it's already present", target_file ); - Ok(target_file.to_owned()) } else { std::fs::write(target_file, data)?; info!("extracted icon to: {:?}", target_file); - Ok(target_file.to_owned()) } + + Ok(target_file.to_owned()) } diff --git a/espanso/src/lock.rs b/espanso/src/lock.rs index b901e48..2076ae4 100644 --- a/espanso/src/lock.rs +++ b/espanso/src/lock.rs @@ -29,6 +29,7 @@ pub struct Lock { } impl Lock { + #[allow(dead_code)] pub fn release(self) -> Result<()> { self.lock_file.unlock()?; Ok(()) @@ -41,10 +42,8 @@ impl Lock { .write(true) .create(true) .open(&lock_file_path) - .expect(&format!( - "unable to create reference to lock file: {:?}", - lock_file_path - )); + .unwrap_or_else(|_| panic!("unable to create reference to lock file: {:?}", + lock_file_path)); if lock_file.try_lock_exclusive().is_ok() { Some(Lock { lock_file }) @@ -59,7 +58,7 @@ impl Drop for Lock { self .lock_file .unlock() - .expect(&format!("unable to unlock lock_file: {:?}", self.lock_file)); + .unwrap_or_else(|_| panic!("unable to unlock lock_file: {:?}", self.lock_file)); } } diff --git a/espanso/src/logging/mod.rs b/espanso/src/logging/mod.rs index 826334a..f4859af 100644 --- a/espanso/src/logging/mod.rs +++ b/espanso/src/logging/mod.rs @@ -48,10 +48,8 @@ impl FileProxy { pub fn set_output_file(&self, path: &Path, read_only: bool, create_new: bool) -> Result<()> { // Remove previous log, if present - if create_new && !read_only { - if path.is_file() { - std::fs::remove_file(path)?; - } + if create_new && !read_only && path.is_file() { + std::fs::remove_file(path)?; } let mut log_file = OpenOptions::new() @@ -64,7 +62,7 @@ impl FileProxy { // Transfer the log content that has been buffered into the file if let Output::Memory(buffered) = &mut (*lock) { - log_file.write_all(&buffered)?; + log_file.write_all(buffered)?; buffered.clear(); } *lock = Output::File(log_file); diff --git a/espanso/src/main.rs b/espanso/src/main.rs index 437ab6b..0772c55 100644 --- a/espanso/src/main.rs +++ b/espanso/src/main.rs @@ -434,7 +434,7 @@ fn main() { let mut handler = if let Some(alias) = alias { CLI_HANDLERS .iter() - .find(|cli| &cli.subcommand == &alias.forward_into) + .find(|cli| cli.subcommand == alias.forward_into) } else { CLI_HANDLERS .iter() @@ -480,7 +480,7 @@ fn main() { if !handler.disable_logs_terminal_output { outputs.insert( 0, - TermLogger::new(log_level, config.clone(), TerminalMode::Mixed), + TermLogger::new(log_level, config, TerminalMode::Mixed), ); } @@ -580,7 +580,7 @@ fn get_path_override(matches: &ArgMatches, argument: &str, env_var: &str) -> Opt if let Some(path) = matches.value_of(argument) { let path = PathBuf::from(path.trim()); if path.is_dir() { - return Some(path); + Some(path) } else { error_eprintln!("{} argument was specified, but it doesn't point to a valid directory. Make sure to create it first.", argument); std::process::exit(1); @@ -588,7 +588,7 @@ fn get_path_override(matches: &ArgMatches, argument: &str, env_var: &str) -> Opt } else if let Ok(path) = std::env::var(env_var) { let path = PathBuf::from(path.trim()); if path.is_dir() { - return Some(path); + Some(path) } else { error_eprintln!("{} env variable was specified, but it doesn't point to a valid directory. Make sure to create it first.", env_var); std::process::exit(1); diff --git a/espanso/src/patch/patches/win/onenote_for_windows_10.rs b/espanso/src/patch/patches/win/onenote_for_windows_10.rs index b437d67..478c28a 100644 --- a/espanso/src/patch/patches/win/onenote_for_windows_10.rs +++ b/espanso/src/patch/patches/win/onenote_for_windows_10.rs @@ -24,7 +24,7 @@ use crate::patch::PatchDefinition; pub fn patch() -> PatchDefinition { PatchDefinition { - name: module_path!().split(":").last().unwrap_or("unknown"), + name: module_path!().split(':').last().unwrap_or("unknown"), is_enabled: || cfg!(target_os = "windows"), should_patch: |app| app.title.unwrap_or_default().contains("OneNote"), apply: |base, name| { diff --git a/espanso/src/patch/patches/win/vscode_win.rs b/espanso/src/patch/patches/win/vscode_win.rs index df0ed7d..da1a009 100644 --- a/espanso/src/patch/patches/win/vscode_win.rs +++ b/espanso/src/patch/patches/win/vscode_win.rs @@ -26,7 +26,7 @@ use crate::patch::PatchDefinition; pub fn patch() -> PatchDefinition { PatchDefinition { - name: module_path!().split(":").last().unwrap_or("unknown"), + name: module_path!().split(':').last().unwrap_or("unknown"), is_enabled: || cfg!(target_os = "windows"), should_patch: |app| app.exec.unwrap_or_default().contains("Code.exe"), apply: |base, name| { diff --git a/espanso/src/path/win.rs b/espanso/src/path/win.rs index 0119d74..c042e79 100644 --- a/espanso/src/path/win.rs +++ b/espanso/src/path/win.rs @@ -61,7 +61,7 @@ fn read_user_path_value() -> Result { fn read_paths() -> Vec { let path_value = read_user_path_value().unwrap_or_default(); - let paths = path_value.split(";"); + let paths = path_value.split(';'); paths.map(String::from).collect() } diff --git a/espanso/src/preferences/default.rs b/espanso/src/preferences/default.rs index 1708e67..5218c8d 100644 --- a/espanso/src/preferences/default.rs +++ b/espanso/src/preferences/default.rs @@ -40,18 +40,17 @@ impl DefaultPreferences { } fn get(&self, key: &str) -> Option { - let value = self + self .kvs .get(key) - .expect(&format!("unable to read preference for key {}", key)); - value + .unwrap_or_else(|_| panic!("unable to read preference for key {}", key)) } fn set(&self, key: &str, value: T) { self .kvs .set(key, value) - .expect(&format!("unable to write preference for key {}", key)) + .unwrap_or_else(|_| panic!("unable to write preference for key {}", key)) } }