From 2d9b28f8e44449cee1ace6f5415f553f6520cd6f Mon Sep 17 00:00:00 2001 From: kkawula <57270771+kkawula@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:57:07 +0100 Subject: [PATCH] Fix linting (#2836) Closes # ## Introduced changes - ## Checklist - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --- crates/cheatnet/src/forking/cache.rs | 2 +- crates/data-transformer/src/sierra_abi/complex_types.rs | 2 +- crates/forge-runner/src/coverage_api.rs | 2 +- crates/forge-runner/src/gas.rs | 2 +- crates/forge/tests/e2e/running.rs | 4 ++-- crates/scarb-api/src/version.rs | 2 +- crates/sncast/src/helpers/interactive.rs | 4 ++-- crates/sncast/src/starknet_commands/account/create.rs | 4 ++-- crates/sncast/src/starknet_commands/script/init.rs | 4 ++-- crates/sncast/tests/e2e/script/init.rs | 4 ++-- crates/snforge-scarb-plugin/src/attributes/fork.rs | 2 +- .../src/attributes/should_panic/expected.rs | 2 +- crates/snforge-scarb-plugin/src/config_statement.rs | 4 ++-- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/cheatnet/src/forking/cache.rs b/crates/cheatnet/src/forking/cache.rs index a2f17535bf..59eaa274cd 100644 --- a/crates/cheatnet/src/forking/cache.rs +++ b/crates/cheatnet/src/forking/cache.rs @@ -150,7 +150,7 @@ impl ForkCache { file.write_all(output.as_bytes()) .expect("Could not write cache to file"); - file.unlock().unwrap(); + fs2::FileExt::unlock(&file).unwrap(); } pub(crate) fn get_storage_at( diff --git a/crates/data-transformer/src/sierra_abi/complex_types.rs b/crates/data-transformer/src/sierra_abi/complex_types.rs index 1a2a48ab44..14542d6b58 100644 --- a/crates/data-transformer/src/sierra_abi/complex_types.rs +++ b/crates/data-transformer/src/sierra_abi/complex_types.rs @@ -233,7 +233,7 @@ impl SupportedCalldataKind for ExprStructCtorCall { { // TODO add message which arguments are invalid (Issue #2549) bail!( - r#"Arguments in constructor invocation for struct {} do not match struct arguments in ABI"#, + r"Arguments in constructor invocation for struct {} do not match struct arguments in ABI", expected_type ) } diff --git a/crates/forge-runner/src/coverage_api.rs b/crates/forge-runner/src/coverage_api.rs index 6c11e39fc7..7c48f0ece9 100644 --- a/crates/forge-runner/src/coverage_api.rs +++ b/crates/forge-runner/src/coverage_api.rs @@ -107,5 +107,5 @@ pub fn can_coverage_be_generated(scarb_metadata: &Metadata) -> Result<()> { fn contains_entry_with_value(table: &Table, key: &str, value: &str) -> bool { table .get(key) - .map_or(false, |entry| entry.to_string().trim() == value) + .is_some_and(|entry| entry.to_string().trim() == value) } diff --git a/crates/forge-runner/src/gas.rs b/crates/forge-runner/src/gas.rs index 99997d9c78..44b45d78a5 100644 --- a/crates/forge-runner/src/gas.rs +++ b/crates/forge-runner/src/gas.rs @@ -155,7 +155,7 @@ pub fn check_available_gas( arguments, gas_info, .. - } if available_gas.map_or(false, |available_gas| gas_info > available_gas as u128) => { + } if available_gas.is_some_and(|available_gas| gas_info > available_gas as u128) => { TestCaseSummary::Failed { name, msg: Some(format!( diff --git a/crates/forge/tests/e2e/running.rs b/crates/forge/tests/e2e/running.rs index 8e41cbeaf1..0b18c2553d 100644 --- a/crates/forge/tests/e2e/running.rs +++ b/crates/forge/tests/e2e/running.rs @@ -1122,11 +1122,11 @@ fn catch_runtime_errors() { assert_stdout_contains( output, formatdoc!( - r#" + r" [..]Compiling[..] [..]Finished[..] [PASS] simple_package_integrationtest::test::catch_no_such_file [..] - "# + " ), ); } diff --git a/crates/scarb-api/src/version.rs b/crates/scarb-api/src/version.rs index e91a0a5369..98fd330811 100644 --- a/crates/scarb-api/src/version.rs +++ b/crates/scarb-api/src/version.rs @@ -33,7 +33,7 @@ impl VersionCommand { fn extract_version(version_output: &str, tool: &str) -> Result { // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string let version_regex = Regex::new( - &format!(r#"{tool}?\s*((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)"#)) + &format!(r"{tool}?\s*((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)")) .context("Could not create version matching regex")?; let version_capture = version_regex diff --git a/crates/sncast/src/helpers/interactive.rs b/crates/sncast/src/helpers/interactive.rs index 051f6e6c2f..733387e53b 100644 --- a/crates/sncast/src/helpers/interactive.rs +++ b/crates/sncast/src/helpers/interactive.rs @@ -222,10 +222,10 @@ mod tests { #[test] fn test_create_table() { - let original = formatdoc! {r#" + let original = formatdoc! {r" [snfoundry] key = 2137 - "#}; + "}; let expected = formatdoc! { r#" diff --git a/crates/sncast/src/starknet_commands/account/create.rs b/crates/sncast/src/starknet_commands/account/create.rs index df7c2cd78c..08a158d906 100644 --- a/crates/sncast/src/starknet_commands/account/create.rs +++ b/crates/sncast/src/starknet_commands/account/create.rs @@ -212,8 +212,8 @@ where Ok((deployment.address(), get_deployment_fee(&deployment).await?)) } -async fn get_deployment_fee<'a, T>( - account_deployment: &AccountDeploymentV1<'a, T>, +async fn get_deployment_fee( + account_deployment: &AccountDeploymentV1<'_, T>, ) -> Result where T: AccountFactory + Sync, diff --git a/crates/sncast/src/starknet_commands/script/init.rs b/crates/sncast/src/starknet_commands/script/init.rs index 251bb9c8bd..5ab5dd8370 100644 --- a/crates/sncast/src/starknet_commands/script/init.rs +++ b/crates/sncast/src/starknet_commands/script/init.rs @@ -150,9 +150,9 @@ fn overwrite_lib_file(script_name: &str, script_root_dir: &Utf8PathBuf) -> Resul fs::write( lib_file_path, - formatdoc! {r#" + formatdoc! {r" mod {script_name}; - "#}, + "}, )?; Ok(()) diff --git a/crates/sncast/tests/e2e/script/init.rs b/crates/sncast/tests/e2e/script/init.rs index 704f11d9b5..669ce5ea8f 100644 --- a/crates/sncast/tests/e2e/script/init.rs +++ b/crates/sncast/tests/e2e/script/init.rs @@ -55,9 +55,9 @@ fn test_script_init_happy_case() { assert_eq!( lib_cairo_content, - formatdoc! {r#" + formatdoc! {r" mod {script_name}; - "#} + "} ); assert_eq!( main_file_content, diff --git a/crates/snforge-scarb-plugin/src/attributes/fork.rs b/crates/snforge-scarb-plugin/src/attributes/fork.rs index 691e929bc6..debcc8c4a0 100644 --- a/crates/snforge-scarb-plugin/src/attributes/fork.rs +++ b/crates/snforge-scarb-plugin/src/attributes/fork.rs @@ -78,7 +78,7 @@ fn from_file_args(db: &dyn SyntaxGroup, args: &Arguments) -> Result { let string = string.as_cairo_expression(); - format!(r#"snforge_std::_config_types::Expected::ByteArray({string})"#) + format!(r"snforge_std::_config_types::Expected::ByteArray({string})") } Self::Array(strings) => { let arr = strings.as_cairo_expression(); diff --git a/crates/snforge-scarb-plugin/src/config_statement.rs b/crates/snforge-scarb-plugin/src/config_statement.rs index 3fb2b16d3b..ce705ed9b9 100644 --- a/crates/snforge-scarb-plugin/src/config_statement.rs +++ b/crates/snforge-scarb-plugin/src/config_statement.rs @@ -40,14 +40,14 @@ where let cheatcode_name = Collector::CHEATCODE_NAME; let config_cheatcode = formatdoc!( - r#" + r" let mut data = array![]; {value} .serialize(ref data); starknet::testing::cheatcode::<'{cheatcode_name}'>(data.span()); - "# + " ); Ok(append_config_statements(db, func, &config_cheatcode))