From a8a5ef16a2fcbeec011459ce74a21bcd710a3379 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 6 Oct 2021 18:41:56 +0200 Subject: [PATCH] style(render): fix formatting --- espanso-render/src/extension/clipboard.rs | 4 +- espanso-render/src/extension/date.rs | 13 ++- espanso-render/src/extension/echo.rs | 12 ++- espanso-render/src/extension/mod.rs | 8 +- espanso-render/src/extension/random.rs | 17 +-- espanso-render/src/extension/script.rs | 120 +++++++++++----------- espanso-render/src/extension/shell.rs | 87 ++++++++-------- espanso-render/src/renderer/mod.rs | 30 ++++-- espanso-render/src/renderer/util.rs | 4 +- 9 files changed, 160 insertions(+), 135 deletions(-) diff --git a/espanso-render/src/extension/clipboard.rs b/espanso-render/src/extension/clipboard.rs index 07030c9..cf1e800 100644 --- a/espanso-render/src/extension/clipboard.rs +++ b/espanso-render/src/extension/clipboard.rs @@ -29,13 +29,13 @@ pub struct ClipboardExtension<'a> { } #[allow(clippy::new_without_default)] -impl <'a> ClipboardExtension<'a> { +impl<'a> ClipboardExtension<'a> { pub fn new(provider: &'a dyn ClipboardProvider) -> Self { Self { provider } } } -impl <'a> Extension for ClipboardExtension<'a> { +impl<'a> Extension for ClipboardExtension<'a> { fn name(&self) -> &str { "clipboard" } diff --git a/espanso-render/src/extension/date.rs b/espanso-render/src/extension/date.rs index f82b387..5cb0812 100644 --- a/espanso-render/src/extension/date.rs +++ b/espanso-render/src/extension/date.rs @@ -84,7 +84,9 @@ mod tests { let mut extension = DateExtension::new(); extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); - let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))].into_iter().collect::(); + let param = vec![("format".to_string(), Value::String("%H:%M:%S".to_string()))] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -100,10 +102,11 @@ mod tests { extension.fixed_date = Some(Local.ymd(2014, 7, 8).and_hms(9, 10, 11)); let param = vec![ - ("format".to_string(), Value::String("%H:%M:%S".to_string())), - ("offset".to_string(), Value::Number(Number::Integer(3600))), - ] - .into_iter().collect::(); + ("format".to_string(), Value::String("%H:%M:%S".to_string())), + ("offset".to_string(), Value::Number(Number::Integer(3600))), + ] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/echo.rs b/espanso-render/src/extension/echo.rs index edb1387..95361c9 100644 --- a/espanso-render/src/extension/echo.rs +++ b/espanso-render/src/extension/echo.rs @@ -21,7 +21,7 @@ use crate::{Extension, ExtensionOutput, ExtensionResult, Params, Value}; use thiserror::Error; pub struct EchoExtension { - alias: String + alias: String, } #[allow(clippy::new_without_default)] @@ -72,8 +72,9 @@ mod tests { fn echo_works_correctly() { let extension = EchoExtension::new(); - let param = - vec![("echo".to_string(), Value::String("test".to_string()))].into_iter().collect::(); + let param = vec![("echo".to_string(), Value::String("test".to_string()))] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -88,7 +89,10 @@ mod tests { let extension = EchoExtension::new(); let param = Params::new(); - assert!(matches!(extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_))); + assert!(matches!( + extension.calculate(&Default::default(), &Default::default(), ¶m), + ExtensionResult::Error(_) + )); } #[test] diff --git a/espanso-render/src/extension/mod.rs b/espanso-render/src/extension/mod.rs index c7294c5..35bae77 100644 --- a/espanso-render/src/extension/mod.rs +++ b/espanso-render/src/extension/mod.rs @@ -17,11 +17,11 @@ * along with espanso. If not, see . */ +pub mod clipboard; pub mod date; pub mod echo; pub mod form; -pub mod clipboard; -pub mod shell; -pub mod script; pub mod random; -mod util; \ No newline at end of file +pub mod script; +pub mod shell; +mod util; diff --git a/espanso-render/src/extension/random.rs b/espanso-render/src/extension/random.rs index a905156..bc954ae 100644 --- a/espanso-render/src/extension/random.rs +++ b/espanso-render/src/extension/random.rs @@ -77,14 +77,15 @@ mod tests { let extension = RandomExtension::new(); let param = vec![( - "choices".to_string(), - Value::Array(vec![ - Value::String("first".to_string()), - Value::String("second".to_string()), - Value::String("third".to_string()), - ]), - )] - .into_iter().collect::(); + "choices".to_string(), + Value::Array(vec![ + Value::String("first".to_string()), + Value::String("second".to_string()), + Value::String("third".to_string()), + ]), + )] + .into_iter() + .collect::(); assert!(matches!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/script.rs b/espanso-render/src/extension/script.rs index 3bd846c..a59c38b 100644 --- a/espanso-render/src/extension/script.rs +++ b/espanso-render/src/extension/script.rs @@ -192,13 +192,14 @@ mod tests { let extension = get_extension(); let param = vec![( - "args".to_string(), - Value::Array(vec![ - Value::String("echo".to_string()), - Value::String("hello world".to_string()), - ]), - )] - .into_iter().collect::(); + "args".to_string(), + Value::Array(vec![ + Value::String("echo".to_string()), + Value::String("hello world".to_string()), + ]), + )] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -214,16 +215,17 @@ mod tests { let extension = get_extension(); let param = vec![ - ( - "args".to_string(), - Value::Array(vec![ - Value::String("echo".to_string()), - Value::String("hello world".to_string()), - ]), - ), - ("trim".to_string(), Value::Bool(false)), - ] - .into_iter().collect::(); + ( + "args".to_string(), + Value::Array(vec![ + Value::String("echo".to_string()), + Value::String("hello world".to_string()), + ]), + ), + ("trim".to_string(), Value::Bool(false)), + ] + .into_iter() + .collect::(); if cfg!(target_os = "windows") { assert_eq!( extension @@ -248,17 +250,16 @@ mod tests { fn var_injection() { let extension = get_extension(); - let param = vec![ - ( - "args".to_string(), - Value::Array(vec![ - Value::String("sh".to_string()), - Value::String("-c".to_string()), - Value::String("echo $ESPANSO_VAR1".to_string()), - ]), - ), - ] - .into_iter().collect::(); + let param = vec![( + "args".to_string(), + Value::Array(vec![ + Value::String("sh".to_string()), + Value::String("-c".to_string()), + Value::String("echo $ESPANSO_VAR1".to_string()), + ]), + )] + .into_iter() + .collect::(); let mut scope = Scope::new(); scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); assert_eq!( @@ -274,15 +275,12 @@ mod tests { fn invalid_command() { let extension = get_extension(); - let param = vec![ - ( - "args".to_string(), - Value::Array(vec![ - Value::String("nonexistentcommand".to_string()), - ]), - ), - ] - .into_iter().collect::(); + let param = vec![( + "args".to_string(), + Value::Array(vec![Value::String("nonexistentcommand".to_string())]), + )] + .into_iter() + .collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -293,18 +291,17 @@ mod tests { #[cfg(not(target_os = "windows"))] fn exit_error() { let extension = get_extension(); - - let param = vec![ - ( - "args".to_string(), - Value::Array(vec![ - Value::String("sh".to_string()), - Value::String("-c".to_string()), - Value::String("exit 1".to_string()), - ]), - ), - ] - .into_iter().collect::(); + + let param = vec![( + "args".to_string(), + Value::Array(vec![ + Value::String("sh".to_string()), + Value::String("-c".to_string()), + Value::String("exit 1".to_string()), + ]), + )] + .into_iter() + .collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -315,19 +312,20 @@ mod tests { #[cfg(not(target_os = "windows"))] fn ignore_error() { let extension = get_extension(); - + let param = vec![ - ( - "args".to_string(), - Value::Array(vec![ - Value::String("sh".to_string()), - Value::String("-c".to_string()), - Value::String("exit 1".to_string()), - ]), - ), - ("ignore_error".to_string(), Value::Bool(true)), - ] - .into_iter().collect::(); + ( + "args".to_string(), + Value::Array(vec![ + Value::String("sh".to_string()), + Value::String("-c".to_string()), + Value::String("exit 1".to_string()), + ]), + ), + ("ignore_error".to_string(), Value::Bool(true)), + ] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/extension/shell.rs b/espanso-render/src/extension/shell.rs index 15a91a3..a385a5b 100644 --- a/espanso-render/src/extension/shell.rs +++ b/espanso-render/src/extension/shell.rs @@ -259,13 +259,14 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = vec![ - ( - "cmd".to_string(), - Value::String("echo \"hello world\"".to_string()), - ), - ("trim".to_string(), Value::Bool(false)), - ] - .into_iter().collect::(); + ( + "cmd".to_string(), + Value::String("echo \"hello world\"".to_string()), + ), + ("trim".to_string(), Value::Bool(false)), + ] + .into_iter() + .collect::(); if cfg!(target_os = "windows") { assert_eq!( extension @@ -290,11 +291,12 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = vec![( - "cmd".to_string(), - Value::String("echo \"hello world\"".to_string()), - )] - .into_iter().collect::(); - + "cmd".to_string(), + Value::String("echo \"hello world\"".to_string()), + )] + .into_iter() + .collect::(); + assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -310,10 +312,11 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = vec![( - "cmd".to_string(), - Value::String("echo \"hello world\" | cat".to_string()), - )] - .into_iter().collect::(); + "cmd".to_string(), + Value::String("echo \"hello world\" | cat".to_string()), + )] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) @@ -328,20 +331,22 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = if cfg!(not(target_os = "windows")) { - vec![( - "cmd".to_string(), - Value::String("echo $ESPANSO_VAR1".to_string()), - )] - .into_iter().collect::() + vec![( + "cmd".to_string(), + Value::String("echo $ESPANSO_VAR1".to_string()), + )] + .into_iter() + .collect::() } else { vec![ - ( - "cmd".to_string(), - Value::String("echo %ESPANSO_VAR1%".to_string()), - ), - ("shell".to_string(), Value::String("cmd".to_string())), - ] - .into_iter().collect::() + ( + "cmd".to_string(), + Value::String("echo %ESPANSO_VAR1%".to_string()), + ), + ("shell".to_string(), Value::String("cmd".to_string())), + ] + .into_iter() + .collect::() }; let mut scope = Scope::new(); scope.insert("var1", ExtensionOutput::Single("hello world".to_string())); @@ -358,12 +363,12 @@ mod tests { fn invalid_command() { let extension = ShellExtension::new(&PathBuf::new()); - let param = - vec![( - "cmd".to_string(), - Value::String("nonexistentcommand".to_string()), - )] - .into_iter().collect::(); + let param = vec![( + "cmd".to_string(), + Value::String("nonexistentcommand".to_string()), + )] + .into_iter() + .collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -375,8 +380,9 @@ mod tests { fn exit_error() { let extension = ShellExtension::new(&PathBuf::new()); - let param = - vec![("cmd".to_string(), Value::String("exit 1".to_string()))].into_iter().collect::(); + let param = vec![("cmd".to_string(), Value::String("exit 1".to_string()))] + .into_iter() + .collect::(); assert!(matches!( extension.calculate(&Default::default(), &Default::default(), ¶m), ExtensionResult::Error(_) @@ -389,10 +395,11 @@ mod tests { let extension = ShellExtension::new(&PathBuf::new()); let param = vec![ - ("cmd".to_string(), Value::String("exit 1".to_string())), - ("ignore_error".to_string(), Value::Bool(true)), - ] - .into_iter().collect::(); + ("cmd".to_string(), Value::String("exit 1".to_string())), + ("ignore_error".to_string(), Value::Bool(true)), + ] + .into_iter() + .collect::(); assert_eq!( extension .calculate(&Default::default(), &Default::default(), ¶m) diff --git a/espanso-render/src/renderer/mod.rs b/espanso-render/src/renderer/mod.rs index 3cea2b6..917d921 100644 --- a/espanso-render/src/renderer/mod.rs +++ b/espanso-render/src/renderer/mod.rs @@ -287,9 +287,9 @@ mod tests { } // If the "read" param is present, echo the value of the corresponding result in the scope if let Some(Value::String(string)) = params.get("read") { - if let Some(ExtensionOutput::Single(value)) = scope.get(string.as_str()) { - return ExtensionResult::Success(ExtensionOutput::Single(value.to_string())); - } + if let Some(ExtensionOutput::Single(value)) = scope.get(string.as_str()) { + return ExtensionResult::Success(ExtensionOutput::Single(value.to_string())); + } } if params.get("abort").is_some() { return ExtensionResult::Aborted; @@ -321,7 +321,9 @@ mod tests { .map(|(name, value)| Variable { name: (*name).to_string(), var_type: "mock".to_string(), - params: vec![("echo".to_string(), Value::String((*value).to_string()))].into_iter().collect::(), + params: vec![("echo".to_string(), Value::String((*value).to_string()))] + .into_iter() + .collect::(), }) .collect(); Template { @@ -430,7 +432,9 @@ mod tests { Variable { name: "local".to_string(), var_type: "mock".to_string(), - params: vec![("echo".to_string(), Value::String("Bob".to_string()))].into_iter().collect::(), + params: vec![("echo".to_string(), Value::String("Bob".to_string()))] + .into_iter() + .collect::(), }, Variable { name: "var".to_string(), @@ -466,7 +470,9 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "match".to_string(), - params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::(), + params: vec![("trigger".to_string(), Value::String("nested".to_string()))] + .into_iter() + .collect::(), }], ..Default::default() }; @@ -494,7 +500,9 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "match".to_string(), - params: vec![("trigger".to_string(), Value::String("nested".to_string()))].into_iter().collect::(), + params: vec![("trigger".to_string(), Value::String("nested".to_string()))] + .into_iter() + .collect::(), }], ..Default::default() }; @@ -516,7 +524,9 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "mock".to_string(), - params: vec![("abort".to_string(), Value::Null)].into_iter().collect::(), + params: vec![("abort".to_string(), Value::Null)] + .into_iter() + .collect::(), }], ..Default::default() }; @@ -532,7 +542,9 @@ mod tests { vars: vec![Variable { name: "var".to_string(), var_type: "mock".to_string(), - params: vec![("error".to_string(), Value::Null)].into_iter().collect::(), + params: vec![("error".to_string(), Value::Null)] + .into_iter() + .collect::(), }], ..Default::default() }; diff --git a/espanso-render/src/renderer/util.rs b/espanso-render/src/renderer/util.rs index c2c3f28..e053cf7 100644 --- a/espanso-render/src/renderer/util.rs +++ b/espanso-render/src/renderer/util.rs @@ -17,8 +17,8 @@ * along with espanso. If not, see . */ -use std::collections::HashSet; use super::VAR_REGEX; +use std::collections::HashSet; pub(crate) fn get_body_variable_names(body: &str) -> HashSet<&str> { let mut variables = HashSet::new(); @@ -49,4 +49,4 @@ mod tests { HashSet::from_iter(vec!["world", "greet"]), ); } -} \ No newline at end of file +}