Skip to content

Commit

Permalink
ci: add clippy checks (#281)
Browse files Browse the repository at this point in the history
* ci: add clippy checks

* refactor: resolve clippy issues
  • Loading branch information
evilrobot-01 authored Sep 18, 2024
1 parent b274630 commit 582db18
Show file tree
Hide file tree
Showing 33 changed files with 195 additions and 201 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ jobs:
- name: Build default features
run: cargo build

clippy:
needs: lint
runs-on: ubuntu-latest
permissions:
checks: write
env:
RUSTFLAGS: "-Wmissing_docs"
steps:
- uses: actions/checkout@v4

- uses: "./.github/actions/init"
with:
git-user: ${{ env.GITHUB_ACTOR }}

- name: Annotate with Clippy warnings
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

deny:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -113,7 +132,7 @@ jobs:
needs: lint
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
os: [ "ubuntu-latest", "macos-latest" ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand All @@ -138,7 +157,7 @@ jobs:
needs: lint
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest"]
os: [ "ubuntu-latest", "macos-latest" ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
Expand Down
12 changes: 5 additions & 7 deletions crates/pop-cli/src/commands/build/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ impl BuildParachainCommand {
cli.warning("NOTE: this command is deprecated. Please use `pop build` (or simply `pop b`) in future...")?;
#[cfg(not(test))]
sleep(Duration::from_secs(3))
} else {
if !self.release {
cli.warning("NOTE: this command now defaults to DEBUG builds. Please use `--release` (or simply `-r`) for a release build...")?;
#[cfg(not(test))]
sleep(Duration::from_secs(3))
}
} else if !self.release {
cli.warning("NOTE: this command now defaults to DEBUG builds. Please use `--release` (or simply `-r`) for a release build...")?;
#[cfg(not(test))]
sleep(Duration::from_secs(3))
}

// Build parachain.
Expand All @@ -61,7 +59,7 @@ impl BuildParachainCommand {
let binary = build_parachain(&project_path, self.package, &mode, None)?;
cli.info(format!("The {project} was built in {mode} mode."))?;
cli.outro("Build completed successfully!")?;
let generated_files = vec![format!("Binary generated at: {}", binary.display())];
let generated_files = [format!("Binary generated at: {}", binary.display())];
let generated_files: Vec<_> = generated_files
.iter()
.map(|s| style(format!("{} {s}", console::Emoji("●", ">"))).dim().to_string())
Expand Down
17 changes: 6 additions & 11 deletions crates/pop-cli/src/commands/build/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl BuildSpecCommand {
config.build(&mut Cli)
},
};
return Ok("spec");
Ok("spec")
} else {
Cli.intro("Building your chain spec")?;
Cli.outro_cancel(
Expand Down Expand Up @@ -276,21 +276,17 @@ impl BuildSpecCommand {
spinner.set_message("Generating genesis code...");
let wasm_file_name = format!("para-{}.wasm", para_id);
let wasm_file = export_wasm_file(&binary_path, &raw_chain_spec, &wasm_file_name)?;
generated_files.push(format!(
"WebAssembly runtime file exported at: {}",
wasm_file.display().to_string()
));
generated_files
.push(format!("WebAssembly runtime file exported at: {}", wasm_file.display()));
}

if self.genesis_state {
spinner.set_message("Generating genesis state...");
let genesis_file_name = format!("para-{}-genesis-state", para_id);
let genesis_state_file =
generate_genesis_state_file(&binary_path, &raw_chain_spec, &genesis_file_name)?;
generated_files.push(format!(
"Genesis State file exported at: {}",
genesis_state_file.display().to_string()
));
generated_files
.push(format!("Genesis State file exported at: {}", genesis_state_file.display()));
}

cli.intro("Building your chain spec".to_string())?;
Expand Down Expand Up @@ -337,7 +333,6 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B

// Prompt for chain type.
// If relay is Kusama or Polkadot, then Live type is used and user is not prompted.
let chain_type: ChainType;
let mut prompt = cliclack::select("Choose the chain type: ".to_string());
let default = chain_spec
.as_ref()
Expand All @@ -356,7 +351,7 @@ async fn guide_user_to_generate_spec(args: BuildSpecCommand) -> anyhow::Result<B
chain_type.get_detailed_message().unwrap_or_default(),
);
}
chain_type = prompt.interact()?.clone();
let chain_type: ChainType = prompt.interact()?.clone();

// Prompt for relay chain.
let mut prompt =
Expand Down
12 changes: 5 additions & 7 deletions crates/pop-cli/src/commands/call/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ impl CallContractCommand {
"-x/--execute"
))?;
} else {
let weight_limit;
if self.gas_limit.is_some() && self.proof_size.is_some() {
weight_limit =
Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap());
let weight_limit = if self.gas_limit.is_some() && self.proof_size.is_some() {
Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap())
} else {
let spinner = cliclack::spinner();
spinner.start("Doing a dry run to estimate the gas...");
weight_limit = match dry_run_gas_estimate_call(&call_exec).await {
match dry_run_gas_estimate_call(&call_exec).await {
Ok(w) => {
log::info(format!("Gas limit: {:?}", w))?;
w
Expand All @@ -120,8 +118,8 @@ impl CallContractCommand {
outro_cancel("Call failed.")?;
return Ok(());
},
};
}
}
};
let spinner = cliclack::spinner();
spinner.start("Calling the contract...");

Expand Down
6 changes: 3 additions & 3 deletions crates/pop-cli/src/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a, CLI: Cli> CleanCacheCommand<'a, CLI> {

for (_, file, _) in &contents {
// confirm removal
remove_file(&file)?;
remove_file(file)?;
}

self.cli.outro(format!("ℹ️ {} artifacts removed", contents.len()))?;
Expand Down Expand Up @@ -134,7 +134,7 @@ impl<'a, CLI: Cli> CleanCacheCommand<'a, CLI> {

/// Returns the contents of the specified path.
fn contents(path: &PathBuf) -> Result<Vec<(String, PathBuf, u64)>> {
let mut contents: Vec<_> = read_dir(&path)?
let mut contents: Vec<_> = read_dir(path)?
.filter_map(|e| {
e.ok().and_then(|e| {
e.file_name()
Expand All @@ -144,7 +144,7 @@ fn contents(path: &PathBuf) -> Result<Vec<(String, PathBuf, u64)>> {
.map(|f| (f.0 .0, f.0 .1, f.1.len()))
})
})
.filter(|(name, _, _)| !name.starts_with("."))
.filter(|(name, _, _)| !name.starts_with('.'))
.collect();
contents.sort_by(|(a, _, _), (b, _, _)| a.cmp(b));
Ok(contents)
Expand Down
12 changes: 6 additions & 6 deletions crates/pop-cli/src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ impl NewContractCommand {
};

is_template_supported(contract_type, &template)?;
generate_contract_from_template(name, &path, &template)?;
generate_contract_from_template(name, path, &template)?;

// If the contract is part of a workspace, add it to that workspace
if let Some(workspace_toml) = find_workspace_toml(&path) {
add_crate_to_workspace(&workspace_toml, &path)?;
if let Some(workspace_toml) = find_workspace_toml(path) {
add_crate_to_workspace(&workspace_toml, path)?;
}

Ok(())
Expand All @@ -95,7 +95,7 @@ fn is_template_supported(contract_type: &ContractType, template: &Contract) -> R
contract_type, template
)));
};
return Ok(());
Ok(())
}

/// Guide the user to generate a contract from available templates.
Expand Down Expand Up @@ -155,7 +155,7 @@ fn generate_contract_from_template(
fs::create_dir_all(contract_path.as_path())?;
let spinner = cliclack::spinner();
spinner.start("Generating contract...");
create_smart_contract(&name, contract_path.as_path(), template)?;
create_smart_contract(name, contract_path.as_path(), template)?;
spinner.clear();
// Replace spinner with success.
console::Term::stderr().clear_last_lines(2)?;
Expand All @@ -173,7 +173,7 @@ fn generate_contract_from_template(
format!("cd into {:?} and enjoy hacking! 🚀", contract_path.display()),
"Use `pop build` to build your contract.".into(),
];
next_steps.push(format!("Use `pop up contract` to deploy your contract to a live network."));
next_steps.push("Use `pop up contract` to deploy your contract to a live network.".to_string());
let next_steps: Vec<_> = next_steps
.iter()
.map(|s| style(format!("{} {s}", console::Emoji("●", ">"))).dim().to_string())
Expand Down
6 changes: 3 additions & 3 deletions crates/pop-cli/src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl NewPalletCommand {
multiselect_pick!(
TemplatePalletOptions,
"Are you interested in adding one of these types and their usual configuration to your pallet?",
vec![TemplatePalletOptions::DefaultConfig]
[TemplatePalletOptions::DefaultConfig]
)
} else {
multiselect_pick!(
Expand All @@ -120,14 +120,14 @@ impl NewPalletCommand {
pallet_custom_origin =
boolean_options.contains(&TemplatePalletOptions::CustomOrigin);
} else {
pallet_common_types = advanced_mode_args.config_common_types.clone();
pallet_common_types.clone_from(&advanced_mode_args.config_common_types);
pallet_default_config = advanced_mode_args.default_config;
if pallet_common_types.is_empty() && pallet_default_config {
return Err(anyhow::anyhow!(
"Specify at least a config common type to use default config."
));
}
pallet_storage = advanced_mode_args.storage.clone();
pallet_storage.clone_from(&advanced_mode_args.storage);
pallet_genesis = advanced_mode_args.genesis_config;
pallet_custom_origin = advanced_mode_args.custom_origin;
}
Expand Down
16 changes: 8 additions & 8 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn guide_user_to_generate_parachain(verify: bool) -> Result<NewParachainCo
decimals: 12,
initial_endowment: "1u64 << 60".to_string(),
};
if Provider::Pop.provides(&template) {
if Provider::Pop.provides(template) {
customizable_options = prompt_customizable_options()?;
}

Expand Down Expand Up @@ -195,7 +195,7 @@ async fn generate_parachain_from_template(
console::Term::stderr().clear_last_lines(2)?;
let mut verify_note = "".to_string();
if verify && tag.is_some() {
let url = url::Url::parse(&template.repository_url()?).expect("valid repository url");
let url = url::Url::parse(template.repository_url()?).expect("valid repository url");
let repo = GitHub::parse(url.as_str())?;
let commit = repo.get_commit_sha_from_release(&tag.clone().unwrap()).await;
verify_note = format!(" ✅ Fetched the latest release of the template along with its license based on the commit SHA for the release ({}).", commit.unwrap_or_default());
Expand Down Expand Up @@ -244,7 +244,7 @@ fn is_template_supported(provider: &Provider, template: &Parachain) -> Result<()
provider, template
)));
};
return Ok(());
Ok(())
}

fn display_select_options(provider: &Provider) -> Result<&Parachain> {
Expand All @@ -270,11 +270,11 @@ fn get_customization_value(
log::warning("Customization options are not available for this template")?;
sleep(Duration::from_secs(3))
}
return Ok(Config {
Ok(Config {
symbol: symbol.clone().expect("default values"),
decimals: decimals.clone().expect("default values"),
decimals: decimals.expect("default values"),
initial_endowment: initial_endowment.clone().expect("default values"),
});
})
}

fn check_destination_path(name_template: &String) -> Result<&Path> {
Expand Down Expand Up @@ -305,7 +305,7 @@ fn check_destination_path(name_template: &String) -> Result<&Path> {
///
/// return: `Option<String>` - The release name selected by the user or None if no releases found.
async fn choose_release(template: &Parachain, verify: bool) -> Result<Option<String>> {
let url = url::Url::parse(&template.repository_url()?).expect("valid repository url");
let url = url::Url::parse(template.repository_url()?).expect("valid repository url");
let repo = GitHub::parse(url.as_str())?;

let license = if verify || template.license().is_none() {
Expand All @@ -323,7 +323,7 @@ async fn choose_release(template: &Parachain, verify: bool) -> Result<Option<Str
.collect();

let mut release_name = None;
if latest_3_releases.len() > 0 {
if !latest_3_releases.is_empty() {
release_name = Some(display_release_versions_to_user(latest_3_releases)?);
} else {
// If supported_versions exists and no other releases are found,
Expand Down
17 changes: 8 additions & 9 deletions crates/pop-cli/src/commands/up/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,12 @@ impl UpContractCommand {
},
};

let weight_limit;
if self.gas_limit.is_some() && self.proof_size.is_some() {
weight_limit = Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap());
let weight_limit = if self.gas_limit.is_some() && self.proof_size.is_some() {
Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap())
} else {
let spinner = spinner();
spinner.start("Doing a dry run to estimate the gas...");
weight_limit = match dry_run_gas_estimate_instantiate(&instantiate_exec).await {
match dry_run_gas_estimate_instantiate(&instantiate_exec).await {
Ok(w) => {
spinner.stop(format!("Gas limit estimate: {:?}", w));
w
Expand All @@ -218,8 +217,8 @@ impl UpContractCommand {
Cli.outro_cancel(FAILED)?;
return Ok(());
},
};
}
}
};

// Finally upload and instantiate.
if !self.dry_run {
Expand Down Expand Up @@ -270,7 +269,7 @@ impl UpContractCommand {
spinner.stop(format!("Contract uploaded: The code hash is {:?}", code_hash));
log::warning("NOTE: The contract has not been instantiated.")?;
}
return Ok(());
Ok(())
}

/// Handles the optional termination of a local running node.
Expand Down Expand Up @@ -299,7 +298,7 @@ impl UpContractCommand {

impl From<UpContractCommand> for UpOpts {
fn from(cmd: UpContractCommand) -> Self {
return UpOpts {
UpOpts {
path: cmd.path,
constructor: cmd.constructor,
args: cmd.args,
Expand All @@ -309,7 +308,7 @@ impl From<UpContractCommand> for UpOpts {
salt: cmd.salt,
url: cmd.url,
suri: cmd.suri,
};
}
}
}

Expand Down
Loading

0 comments on commit 582db18

Please sign in to comment.