From cbe2592e5f025862b96af398d1ead3d0a5de8551 Mon Sep 17 00:00:00 2001 From: Shanith K K Date: Thu, 28 Dec 2023 11:09:09 +0530 Subject: [PATCH] fix: clippy warnings --- .../composer-v2/echo-library/src/common/composer.rs | 2 +- .../echo-library/src/common/parse_module.rs | 12 ++++++------ workflow/composer-v2/src/commands/create.rs | 6 +++--- workflow/composer-v2/src/errors/io.rs | 6 +++++- workflow/composer-v2/src/types/context.rs | 2 +- workflow/composer-v2/src/types/echo.rs | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/workflow/composer-v2/echo-library/src/common/composer.rs b/workflow/composer-v2/echo-library/src/common/composer.rs index def8e718..e7f7c66a 100644 --- a/workflow/composer-v2/echo-library/src/common/composer.rs +++ b/workflow/composer-v2/echo-library/src/common/composer.rs @@ -256,7 +256,7 @@ impl Composer { let wasm_path = format!( "{}/boilerplate/target/wasm32-wasi/release/boilerplate.wasm", - temp_dir.display().to_string() + temp_dir.display() ); fs::create_dir_all(out_path.join("output"))?; diff --git a/workflow/composer-v2/echo-library/src/common/parse_module.rs b/workflow/composer-v2/echo-library/src/common/parse_module.rs index 924ac767..f23cd57a 100644 --- a/workflow/composer-v2/echo-library/src/common/parse_module.rs +++ b/workflow/composer-v2/echo-library/src/common/parse_module.rs @@ -356,11 +356,11 @@ fn get_impl_execute_trait_code(workflow: &Workflow) -> String { fn get_add_nodes_code(flow: &Vec) -> String { let mut add_nodes_code = String::new(); - for i in 0..flow.len() { + for i in flow { add_nodes_code.push_str(&format!( "let {}_index = workflow.add_node(Box::new({}));\n", - flow[i].to_case(Case::Snake), - flow[i].to_case(Case::Snake) + i.to_case(Case::Snake), + i.to_case(Case::Snake) )); } @@ -574,11 +574,11 @@ pub fn add_polkadot_openwhisk(workflow: &Workflow) -> String { let mut toml_dependencies = String::new(); if kinds.contains("openwhisk") { - toml_dependencies = format!("{}", get_openwhisk()); + toml_dependencies = get_openwhisk(); } if kinds.contains("polkadot") { - toml_dependencies = format!("{}", get_polkadot()); + toml_dependencies = get_polkadot(); } if kinds.contains("openwhisk") && kinds.contains("polkadot") { @@ -616,7 +616,7 @@ pub fn get_struct_stake_ledger(workflow: &Workflow) -> String { let mut toml_dependencies = String::new(); if kinds.contains("polkadot") { - toml_dependencies = format!("{}", staking_ledger()); + toml_dependencies = staking_ledger(); } toml_dependencies diff --git a/workflow/composer-v2/src/commands/create.rs b/workflow/composer-v2/src/commands/create.rs index c9980881..e00ba2ff 100644 --- a/workflow/composer-v2/src/commands/create.rs +++ b/workflow/composer-v2/src/commands/create.rs @@ -12,9 +12,9 @@ pub struct Create { impl Create { pub fn execute(self) -> result::Result<()> { - let current = std::env::current_dir().map_err(|error| io_error(error))?; + let current = std::env::current_dir().map_err(io_error)?; let package = current.join(&self.package_name); - fs::create_dir_all(&package).map_err(|error| io_error(error))?; + fs::create_dir_all(&package).map_err(io_error)?; let temp_path = package.join("main.echo"); let content = format!( @@ -39,6 +39,6 @@ workflows( self.package_name ); - fs::write(&temp_path, content.as_bytes()).map_err(|error| io_error(error)) + fs::write(&temp_path, content.as_bytes()).map_err(io_error) } } diff --git a/workflow/composer-v2/src/errors/io.rs b/workflow/composer-v2/src/errors/io.rs index 19663f65..f9f7965c 100644 --- a/workflow/composer-v2/src/errors/io.rs +++ b/workflow/composer-v2/src/errors/io.rs @@ -55,6 +55,10 @@ impl From for IOError { impl Display for IOError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self) + match self { + IOError::PathNotFound => write!(f, "PathNotFound"), + IOError::Anyhow(error) => write!(f, "ErrorInComposer: {}", error), + IOError::Other(error) => write!(f, "Error: {}", error), + } } } diff --git a/workflow/composer-v2/src/types/context.rs b/workflow/composer-v2/src/types/context.rs index e8f6c9a2..fc7df0d9 100644 --- a/workflow/composer-v2/src/types/context.rs +++ b/workflow/composer-v2/src/types/context.rs @@ -20,7 +20,7 @@ impl Default for Context { build_directory: None, output_directory: None, source_files: None, - parser: Box::new(Composer::default()), + parser: Box::::default(), quiet: false, } } diff --git a/workflow/composer-v2/src/types/echo.rs b/workflow/composer-v2/src/types/echo.rs index 792bc6f2..4618178a 100644 --- a/workflow/composer-v2/src/types/echo.rs +++ b/workflow/composer-v2/src/types/echo.rs @@ -21,7 +21,7 @@ impl Parser for Composer { output_directory: &OutputDirectory, quiet: bool, ) -> result::Result<()> { - self.build_directory(&build_directory.path, &output_directory.base(), quiet) + self.build_directory(&build_directory.path, output_directory.base(), quiet) .map_err(|error| Box::new(IOError::Anyhow(error)) as Box)?; Ok(()) }