Skip to content

Commit ce87587

Browse files
committed
smplx: add extended clippy linting
* fix lints, which aren't related to docs
1 parent de2b61f commit ce87587

30 files changed

Lines changed: 149 additions & 96 deletions

Cargo.lock

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ minreq = { workspace = true }
2828
anyhow = "1"
2929
dotenvy = "0.15"
3030
clap = { version = "4", features = ["derive", "env"] }
31-
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
3231
toml_edit = { version = "0.23.9" }
3332
ctrlc = { version = "3.5.2", features = ["termination"] }
3433
serde_json = { version = "1.0.149" }

crates/cli/src/bin/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use clap::Parser;
22

3-
#[tokio::main]
4-
async fn main() -> anyhow::Result<()> {
3+
fn main() -> anyhow::Result<()> {
54
let _ = dotenvy::dotenv();
65

7-
Box::pin(smplx_cli::Cli::parse().run()).await?;
6+
smplx_cli::Cli::parse().run()?;
87

98
Ok(())
109
}

crates/cli/src/cli.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Cli {
2222
}
2323

2424
impl Cli {
25-
pub async fn run(&self) -> Result<(), CliError> {
25+
pub fn run(&self) -> Result<(), CliError> {
2626
match &self.command {
2727
Command::Init { additional_flags } => {
2828
let simplex_conf_path = Config::get_default_path()?;
@@ -49,13 +49,13 @@ impl Cli {
4949
let config_path = Config::get_default_path()?;
5050
let loaded_config = Config::load(config_path)?;
5151

52-
Ok(Regtest::run(loaded_config.regtest)?)
52+
Ok(Regtest::run(&loaded_config.regtest)?)
5353
}
5454
Command::Build => {
5555
let config_path = Config::get_default_path()?;
5656
let loaded_config = Config::load(config_path)?;
5757

58-
Ok(Build::run(loaded_config.build)?)
58+
Ok(Build::run(&loaded_config.build)?)
5959
}
6060
Command::Clean => {
6161
let config_path = Config::get_default_path()?;

crates/cli/src/commands/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::error::CommandError;
55
pub struct Build {}
66

77
impl Build {
8-
pub fn run(config: BuildConfig) -> Result<(), CommandError> {
8+
pub fn run(config: &BuildConfig) -> Result<(), CommandError> {
99
let output_dir = ArtifactsResolver::resolve_local_dir(&config.out_dir)?;
1010
let src_dir = ArtifactsResolver::resolve_local_dir(&config.src_dir)?;
1111
let files_to_build = ArtifactsResolver::resolve_files_to_build(&config.src_dir, &config.simf_files)?;

crates/cli/src/commands/clean.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ pub struct DeletedItems(Vec<PathBuf>);
1111

1212
impl Clean {
1313
pub fn run(config: BuildConfig) -> Result<(), CommandError> {
14-
let deleted_files = Self::delete_files(config)?;
14+
let deleted_files = Self::delete_files(&config)?;
1515

1616
println!("Deleted files: {deleted_files}");
1717

1818
Ok(())
1919
}
2020

21-
fn delete_files(config: BuildConfig) -> Result<DeletedItems, CleanError> {
21+
fn delete_files(config: &BuildConfig) -> Result<DeletedItems, CleanError> {
2222
let mut deleted_items = Vec::with_capacity(1);
2323
let generated_artifacts = Self::remove_artifacts(config)?;
2424

@@ -29,12 +29,12 @@ impl Clean {
2929
Ok(DeletedItems(deleted_items))
3030
}
3131

32-
fn remove_artifacts(config: BuildConfig) -> Result<Option<PathBuf>, CleanError> {
32+
fn remove_artifacts(config: &BuildConfig) -> Result<Option<PathBuf>, CleanError> {
3333
let output_dir = ArtifactsResolver::resolve_local_dir(&config.out_dir)
3434
.map_err(|e| CleanError::ResolveOutDir(e.to_string()))?;
3535

3636
let res = if output_dir.exists() {
37-
fs::remove_dir_all(&output_dir).map_err(|e| CleanError::RemoveOutDir(e, output_dir.to_path_buf()))?;
37+
fs::remove_dir_all(&output_dir).map_err(|e| CleanError::RemoveOutDir(e, output_dir.clone()))?;
3838
Some(output_dir)
3939
} else {
4040
None
@@ -46,11 +46,13 @@ impl Clean {
4646

4747
impl Display for DeletedItems {
4848
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49+
use std::fmt::Write;
50+
4951
let paths_len = self.0.len();
5052
let mut result = String::from("[");
5153

5254
for (index, path) in self.0.iter().enumerate() {
53-
result.push_str(&format!("\n {}", path.display()));
55+
let _ = write!(result, "\n {}", path.display());
5456

5557
if index < paths_len - 1 {
5658
result.push(',');
@@ -61,6 +63,6 @@ impl Display for DeletedItems {
6163

6264
result.push(']');
6365

64-
write!(f, "{}", result)
66+
write!(f, "{result}")
6567
}
6668
}

crates/cli/src/commands/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct InitFlags {
3333
pub lib: bool,
3434
}
3535

36+
#[allow(clippy::struct_excessive_bools)]
3637
#[derive(Debug, Args, Clone)]
3738
pub struct TestFlags {
3839
/// Show output from successful tests

crates/cli/src/commands/init.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct Init;
1111
impl Init {
1212
pub fn run(smplx_conf_path: impl AsRef<Path>, flags: &InitFlags) -> Result<(), CommandError> {
1313
if flags.lib {
14-
Self::generate_lib_inplace(&smplx_conf_path)?
14+
Self::generate_lib_inplace(&smplx_conf_path)?;
1515
}
1616

1717
Self::fill_simplex_toml(smplx_conf_path)?;
@@ -93,25 +93,25 @@ fn main() {
9393

9494
let file_name = file_name
9595
.to_str()
96-
.ok_or_else(|| InitError::NonUnicodeName(format!("{file_name:?}")))?;
96+
.ok_or_else(|| InitError::NonUnicodeName(format!("{}", file_name.display())))?;
9797

98-
Ok(format!("simplex_{}", file_name))
98+
Ok(format!("simplex_{file_name}"))
9999
}
100100

101101
fn get_smplx_max_version() -> Result<String, InitError> {
102-
let url = format!("https://crates.io/api/v1/crates/{}", SIMPLEX_CRATE_NAME);
102+
let url = format!("https://crates.io/api/v1/crates/{SIMPLEX_CRATE_NAME}");
103103

104104
let response = minreq::get(&url)
105105
.with_header("User-Agent", "simplex_generator")
106106
.send()
107-
.map_err(|e| InitError::CratesIoFetch(format!("Failed to fetch crate info: {}", e)))?;
107+
.map_err(|e| InitError::CratesIoFetch(format!("Failed to fetch crate info: {e}")))?;
108108

109109
let body = response
110110
.as_str()
111-
.map_err(|e| InitError::CratesIoFetch(format!("Invalid response body: {}", e)))?;
111+
.map_err(|e| InitError::CratesIoFetch(format!("Invalid response body: {e}")))?;
112112

113113
let json: serde_json::Value =
114-
serde_json::from_str(body).map_err(|e| InitError::CratesIoFetch(format!("Failed to parse JSON: {}", e)))?;
114+
serde_json::from_str(body).map_err(|e| InitError::CratesIoFetch(format!("Failed to parse JSON: {e}")))?;
115115

116116
let latest_version = json["crate"]["max_stable_version"]
117117
.as_str()
@@ -143,6 +143,7 @@ fn main() {
143143
Ok(())
144144
}
145145

146+
#[allow(clippy::unnecessary_wraps)]
146147
fn execute_cargo_fmt(file: impl AsRef<Path>) -> Result<(), InitError> {
147148
let mut cargo_test_command = std::process::Command::new("sh");
148149

crates/cli/src/commands/regtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::commands::error::CommandError;
99
pub struct Regtest {}
1010

1111
impl Regtest {
12-
pub fn run(config: RegtestConfig) -> Result<(), CommandError> {
12+
pub fn run(config: &RegtestConfig) -> Result<(), CommandError> {
1313
let (mut client, signer) = RegtestRunner::from_config(config)?;
1414

1515
let running = Arc::new(AtomicBool::new(true));

crates/cli/src/commands/test.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl Test {
1414
let cache_path = Self::get_test_config_cache_name()?;
1515

1616
if flags.verbose {
17-
config.verbosity = Some(Verbosity(4))
17+
config.verbosity = Some(Verbosity(4));
1818
}
1919

2020
config.to_file(&cache_path)?;
@@ -25,7 +25,7 @@ impl Test {
2525

2626
match output.status.code() {
2727
Some(code) => {
28-
println!("Exit Status: {}", code);
28+
println!("Exit Status: {code}");
2929

3030
if code == 0 {
3131
println!("{}", String::from_utf8(output.stdout).unwrap());
@@ -54,9 +54,10 @@ impl Test {
5454
}
5555

5656
fn build_test_command(filter: String, flags: &TestFlags) -> String {
57+
use std::fmt::Write;
5758
let mut command_as_arg = String::new();
5859

59-
command_as_arg.push_str(&format!("cargo test {filter}_{SMPLX_TEST_MARKER}"));
60+
let _ = write!(command_as_arg, "cargo test {filter}_{SMPLX_TEST_MARKER}");
6061

6162
let flag_args = Self::build_test_flags(flags);
6263

0 commit comments

Comments
 (0)