diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d18ff599..71f4703c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,8 +16,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Install Rust nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + components: rustfmt + override: true + - name: Check formatting - run: cargo fmt --all -- --check + run: cargo +nightly fmt --all -- --check build: needs: lint diff --git a/crates/pop-cli/src/commands/build/spec.rs b/crates/pop-cli/src/commands/build/spec.rs index 768b467a..a40871dc 100644 --- a/crates/pop-cli/src/commands/build/spec.rs +++ b/crates/pop-cli/src/commands/build/spec.rs @@ -370,13 +370,13 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result { + ChainType::Live => for relay in RelayChain::VARIANTS { if !matches!( relay, - RelayChain::Westend - | RelayChain::Paseo | RelayChain::Kusama - | RelayChain::Polkadot + RelayChain::Westend | + RelayChain::Paseo | RelayChain::Kusama | + RelayChain::Polkadot ) { continue; } else { @@ -386,15 +386,14 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result { + }, + _ => for relay in RelayChain::VARIANTS { if matches!( relay, - RelayChain::Westend - | RelayChain::Paseo | RelayChain::Kusama - | RelayChain::Polkadot + RelayChain::Westend | + RelayChain::Paseo | RelayChain::Kusama | + RelayChain::Polkadot ) { continue; } else { @@ -404,8 +403,7 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result anyhow::Result<()> { async fn install_homebrew() -> anyhow::Result<()> { match cmd("which", vec!["brew"]).read() { Ok(output) => log::info(format!("ℹ️ Homebrew installed already at {}.", output))?, - Err(_) => { + Err(_) => run_external_script( "https://raw.githubusercontent.com/Homebrew/install/master/install.sh", ) - .await? - }, + .await?, } Ok(()) } diff --git a/crates/pop-cli/src/commands/new/pallet.rs b/crates/pop-cli/src/commands/new/pallet.rs index d886b40b..3c585c9a 100644 --- a/crates/pop-cli/src/commands/new/pallet.rs +++ b/crates/pop-cli/src/commands/new/pallet.rs @@ -84,11 +84,11 @@ impl NewPalletCommand { let mut pallet_custom_origin = false; if let Some(Mode::Advanced(advanced_mode_args)) = &self.mode { - if advanced_mode_args.config_common_types.is_empty() - && advanced_mode_args.storage.is_empty() - && !(advanced_mode_args.genesis_config - || advanced_mode_args.default_config - || advanced_mode_args.custom_origin) + if advanced_mode_args.config_common_types.is_empty() && + advanced_mode_args.storage.is_empty() && + !(advanced_mode_args.genesis_config || + advanced_mode_args.default_config || + advanced_mode_args.custom_origin) { Cli.info("Generate the pallet's config trait.")?; diff --git a/crates/pop-cli/src/commands/new/parachain.rs b/crates/pop-cli/src/commands/new/parachain.rs index ba69ea44..a9adb1bd 100644 --- a/crates/pop-cli/src/commands/new/parachain.rs +++ b/crates/pop-cli/src/commands/new/parachain.rs @@ -241,8 +241,8 @@ fn get_customization_value( decimals: Option, initial_endowment: Option, ) -> Result { - if !matches!(template, Parachain::Standard) - && (symbol.is_some() || decimals.is_some() || initial_endowment.is_some()) + if !matches!(template, Parachain::Standard) && + (symbol.is_some() || decimals.is_some() || initial_endowment.is_some()) { log::warning("Customization options are not available for this template")?; sleep(Duration::from_secs(3)) diff --git a/crates/pop-cli/src/commands/up/contract.rs b/crates/pop-cli/src/commands/up/contract.rs index 5541ec3a..e5be4966 100644 --- a/crates/pop-cli/src/commands/up/contract.rs +++ b/crates/pop-cli/src/commands/up/contract.rs @@ -326,8 +326,8 @@ pub fn has_contract_been_built(path: Option<&Path>) -> bool { Err(_) => return false, }; let contract_name = manifest.package().name(); - project_path.join("target/ink").exists() - && project_path.join(format!("target/ink/{}.contract", contract_name)).exists() + project_path.join("target/ink").exists() && + project_path.join(format!("target/ink/{}.contract", contract_name)).exists() } #[cfg(test)] diff --git a/crates/pop-cli/src/commands/up/parachain.rs b/crates/pop-cli/src/commands/up/parachain.rs index fe1bbc1a..e68d20a1 100644 --- a/crates/pop-cli/src/commands/up/parachain.rs +++ b/crates/pop-cli/src/commands/up/parachain.rs @@ -71,7 +71,7 @@ impl ZombienetCommand { .await { Ok(n) => n, - Err(e) => { + Err(e) => return match e { Error::Config(message) => { outro_cancel(format!("🚫 A configuration error occurred: `{message}`"))?; @@ -82,8 +82,7 @@ impl ZombienetCommand { Ok(()) }, _ => Err(e.into()), - } - }, + }, }; // Source any missing/stale binaries diff --git a/crates/pop-common/src/git.rs b/crates/pop-common/src/git.rs index 2e6b205a..f93fbc14 100644 --- a/crates/pop-common/src/git.rs +++ b/crates/pop-common/src/git.rs @@ -124,7 +124,8 @@ impl Git { Self::parse_latest_tag(tags.iter().flatten().collect::>()) } - /// Parses a list of tags to identify the latest one, prioritizing tags in the stable format first. + /// Parses a list of tags to identify the latest one, prioritizing tags in the stable format + /// first. fn parse_latest_tag(tags: Vec<&str>) -> Option { match Self::parse_stable_format(tags.clone()) { Some(last_stable_tag) => Some(last_stable_tag), diff --git a/crates/pop-common/src/lib.rs b/crates/pop-common/src/lib.rs index d10e792e..7206bc7e 100644 --- a/crates/pop-common/src/lib.rs +++ b/crates/pop-common/src/lib.rs @@ -35,18 +35,16 @@ pub fn target() -> Result<&'static str, Error> { } match ARCH { - "aarch64" => { + "aarch64" => return match OS { "macos" => Ok("aarch64-apple-darwin"), _ => Ok("aarch64-unknown-linux-gnu"), - } - }, - "x86_64" | "x86" => { + }, + "x86_64" | "x86" => return match OS { "macos" => Ok("x86_64-apple-darwin"), _ => Ok("x86_64-unknown-linux-gnu"), - } - }, + }, &_ => {}, } Err(Error::UnsupportedPlatform { arch: ARCH, os: OS }) diff --git a/crates/pop-common/src/manifest.rs b/crates/pop-common/src/manifest.rs index 4571d992..a2b8d330 100644 --- a/crates/pop-common/src/manifest.rs +++ b/crates/pop-common/src/manifest.rs @@ -29,14 +29,17 @@ pub fn from_path(path: Option<&Path>) -> Result { Ok(Manifest::from_path(path.canonicalize()?)?) } -/// This function is used to determine if a Path is contained inside a workspace, and returns a PathBuf to the workspace Cargo.toml if found. +/// This function is used to determine if a Path is contained inside a workspace, and returns a +/// PathBuf to the workspace Cargo.toml if found. /// /// # Arguments /// * `target_dir` - A directory that may be contained inside a workspace pub fn find_workspace_toml(target_dir: &Path) -> Option { let mut dir = target_dir; while let Some(parent) = dir.parent() { - // This condition is necessary to avoid that calling the function from a workspace using a path which isn't contained in a workspace returns `Some(Cargo.toml)` refering the workspace from where the function has been called instead of the expected `None`. + // This condition is necessary to avoid that calling the function from a workspace using a + // path which isn't contained in a workspace returns `Some(Cargo.toml)` refering the + // workspace from where the function has been called instead of the expected `None`. if parent.to_str() == Some("") { return None; } @@ -249,7 +252,9 @@ mod tests { if let Some(Item::Value(Value::Array(array))) = workspace_table.get("members") { assert!(array.iter().any(|item| { if let Value::String(item) = item { - // item is only the relative path from the Cargo.toml manifest, while test_buildder.insider_workspace_dir is the absolute path, so we can only test with contains + // item is only the relative path from the Cargo.toml manifest, while + // test_buildder.insider_workspace_dir is the absolute path, so we can only + // test with contains test_builder .inside_workspace_dir .as_ref() diff --git a/crates/pop-common/src/sourcing/binary.rs b/crates/pop-common/src/sourcing/binary.rs index a8063616..ae9bd5f9 100644 --- a/crates/pop-common/src/sourcing/binary.rs +++ b/crates/pop-common/src/sourcing/binary.rs @@ -45,13 +45,12 @@ impl Binary { pub fn latest(&self) -> Option<&str> { match self { Self::Local { .. } => None, - Self::Source { source, .. } => { + Self::Source { source, .. } => if let GitHub(ReleaseArchive { latest, .. }) = source { latest.as_deref() } else { None - } - }, + }, } } @@ -135,18 +134,15 @@ impl Binary { ) -> Result<(), Error> { match self { Self::Local { name, path, manifest, .. } => match manifest { - None => { + None => return Err(Error::MissingBinary(format!( "The {path:?} binary cannot be sourced automatically." - ))) - }, - Some(manifest) => { - from_local_package(manifest, name, release, status, verbose).await - }, - }, - Self::Source { source, cache, .. } => { - source.source(cache, release, status, verbose).await + ))), + Some(manifest) => + from_local_package(manifest, name, release, status, verbose).await, }, + Self::Source { source, cache, .. } => + source.source(cache, release, status, verbose).await, } } diff --git a/crates/pop-common/src/sourcing/mod.rs b/crates/pop-common/src/sourcing/mod.rs index 0ba28a02..81d0bc3f 100644 --- a/crates/pop-common/src/sourcing/mod.rs +++ b/crates/pop-common/src/sourcing/mod.rs @@ -210,9 +210,8 @@ impl GitHub { let artifacts: Vec<_> = artifacts .iter() .map(|name| match reference { - Some(reference) => { - (name.as_str(), cache.join(&format!("{name}-{reference}"))) - }, + Some(reference) => + (name.as_str(), cache.join(&format!("{name}-{reference}"))), None => (name.as_str(), cache.join(&name)), }) .collect(); @@ -379,11 +378,10 @@ async fn from_github_archive( // Prepare archive contents for build let entries: Vec<_> = read_dir(&working_dir)?.take(2).filter_map(|x| x.ok()).collect(); match entries.len() { - 0 => { + 0 => return Err(Error::ArchiveError( "The downloaded archive does not contain any entries.".into(), - )) - }, + )), 1 => working_dir = entries[0].path(), // Automatically switch to top level directory _ => {}, /* Assume that downloaded archive does not have a * top level directory */ diff --git a/crates/pop-common/src/templates/extractor.rs b/crates/pop-common/src/templates/extractor.rs index b0d1f47f..5f801999 100644 --- a/crates/pop-common/src/templates/extractor.rs +++ b/crates/pop-common/src/templates/extractor.rs @@ -42,8 +42,8 @@ fn copy_dir_all( for entry in fs::read_dir(src)? { let entry = entry?; let ty = entry.file_type()?; - if ty.is_dir() - && ignore_directories.contains(&entry.file_name().to_string_lossy().to_string()) + if ty.is_dir() && + ignore_directories.contains(&entry.file_name().to_string_lossy().to_string()) { continue; } else if ty.is_dir() { diff --git a/crates/pop-parachains/src/build.rs b/crates/pop-parachains/src/build.rs index 669ed1e8..38d760c5 100644 --- a/crates/pop-parachains/src/build.rs +++ b/crates/pop-parachains/src/build.rs @@ -49,8 +49,8 @@ pub fn is_supported(path: Option<&Path>) -> Result { const DEPENDENCIES: [&str; 4] = ["cumulus-client-collator", "cumulus-primitives-core", "parachains-common", "polkadot-sdk"]; Ok(DEPENDENCIES.into_iter().any(|d| { - manifest.dependencies.contains_key(d) - || manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) + manifest.dependencies.contains_key(d) || + manifest.workspace.as_ref().map_or(false, |w| w.dependencies.contains_key(d)) })) } diff --git a/crates/pop-parachains/src/up/mod.rs b/crates/pop-parachains/src/up/mod.rs index 390e990a..192da7ff 100644 --- a/crates/pop-parachains/src/up/mod.rs +++ b/crates/pop-parachains/src/up/mod.rs @@ -252,13 +252,12 @@ impl Zombienet { if let Some(command) = NetworkConfiguration::command(node).and_then(|c| c.as_str()) { match &relay { - Some(relay) => { + Some(relay) => if command.to_lowercase() != relay.binary.name() { return Err(Error::UnsupportedCommand(format!( "the relay chain command is unsupported: {command}", ))); - } - }, + }, None => { relay = Some( relay::from(command, version, runtime_version, chain, cache) diff --git a/crates/pop-parachains/src/utils/helpers.rs b/crates/pop-parachains/src/utils/helpers.rs index 7a27b87e..0e6f71cc 100644 --- a/crates/pop-parachains/src/utils/helpers.rs +++ b/crates/pop-parachains/src/utils/helpers.rs @@ -30,8 +30,8 @@ pub(crate) fn sanitize(target: &Path) -> Result<(), Error> { /// /// * `initial_endowment` - initial endowment amount to be checked for validity. pub fn is_initial_endowment_valid(initial_endowment: &str) -> bool { - initial_endowment.parse::().is_ok() - || is_valid_bitwise_left_shift(initial_endowment).is_ok() + initial_endowment.parse::().is_ok() || + is_valid_bitwise_left_shift(initial_endowment).is_ok() } // Auxiliar method to check if the endowment input with a shift left (1u64 << 60) format is valid. // Parse the self << rhs format and check the shift left operation is valid.