Skip to content

Commit faa5a3e

Browse files
authored
refactor: clippy (#1223)
* refactor: clippy * refactor: review
1 parent f0941f8 commit faa5a3e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1157
-1401
lines changed

.vscode/settings.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
"cargo",
44
"clippy",
55
"--package=clarinet-cli",
6-
"--message-format=json",
7-
"--",
8-
"--no-deps"
6+
"--message-format=json"
97
]
108
}

clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type-complexity-threshold = 1000
2+
too-many-arguments-threshold = 12

components/clarinet-cli/src/deployments/mod.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
pub mod types;
22
mod ui;
33

4+
use std::fs::{self};
5+
use std::path::PathBuf;
46
pub use ui::start_ui;
57

6-
use hiro_system_kit;
7-
88
use clarinet_deployments::types::{DeploymentGenerationArtifacts, DeploymentSpecification};
9-
10-
use clarinet_files::{FileLocation, ProjectManifest};
11-
129
use clarinet_files::chainhook_types::StacksNetwork;
13-
14-
use serde_yaml;
15-
16-
use std::fs::{self};
17-
18-
use std::path::PathBuf;
10+
use clarinet_files::{FileLocation, ProjectManifest};
1911

2012
#[derive(Deserialize, Debug)]
2113
pub struct Balance {
@@ -79,7 +71,7 @@ fn get_deployments_files(
7971
let is_extension_valid = file
8072
.extension()
8173
.and_then(|ext| ext.to_str())
82-
.and_then(|ext| Some(ext == "yml" || ext == "yaml"));
74+
.map(|ext| ext == "yml" || ext == "yaml");
8375

8476
if let Some(true) = is_extension_valid {
8577
let relative_path = file.clone();
@@ -99,13 +91,13 @@ pub fn write_deployment(
9991
if target_location.exists() && prompt_override {
10092
println!(
10193
"Deployment {} already exists.\n{}?",
102-
target_location.to_string(),
94+
target_location,
10395
yellow!("Overwrite [Y/n]")
10496
);
10597
let mut buffer = String::new();
10698
std::io::stdin().read_line(&mut buffer).unwrap();
107-
if buffer.starts_with("n") {
108-
return Err(format!("deployment update aborted"));
99+
if buffer.starts_with('n') {
100+
return Err("deployment update aborted".to_string());
109101
}
110102
}
111103

components/clarinet-cli/src/deployments/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ impl DeploymentSynthesis {
3434
Ok(res) => res,
3535
Err(err) => panic!("unable to serialize deployment {}", err),
3636
};
37-
return DeploymentSynthesis {
37+
DeploymentSynthesis {
3838
total_cost,
3939
blocks_count,
4040
content,
41-
};
41+
}
4242
}
4343
}
4444

components/clarinet-cli/src/deployments/ui/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[allow(dead_code)]
22
mod app;
3-
#[allow(dead_code)]
3+
4+
#[allow(clippy::module_inception)]
45
mod ui;
56

67
use app::App;

components/clarinet-cli/src/frontend/cli.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ use super::telemetry::{telemetry_report_event, DeveloperUsageDigest, DeveloperUs
5555
/// For Clarinet documentation, refer to https://docs.hiro.so/clarinet/introduction.
5656
/// Report any issues here https://github.com/hirosystems/clarinet/issues/new.
5757
#[derive(Parser, PartialEq, Clone, Debug)]
58-
#[clap(version = option_env!("CARGO_PKG_VERSION").expect("Unable to detect version"), name = "clarinet", bin_name = "clarinet")]
58+
#[clap(version = env!("CARGO_PKG_VERSION"), name = "clarinet", bin_name = "clarinet")]
5959
struct Opts {
6060
#[clap(subcommand)]
6161
command: Command,
6262
}
6363

64+
#[allow(clippy::upper_case_acronyms)]
6465
#[derive(Subcommand, PartialEq, Clone, Debug)]
6566
enum Command {
6667
/// Create and scaffold a new project
@@ -123,6 +124,7 @@ enum Requirements {
123124
AddRequirement(AddRequirement),
124125
}
125126

127+
#[allow(clippy::enum_variant_names)]
126128
#[derive(Subcommand, PartialEq, Clone, Debug)]
127129
#[clap(bin_name = "deployment", aliases = &["deployment"])]
128130
enum Deployments {
@@ -137,6 +139,7 @@ enum Deployments {
137139
ApplyDeployment(ApplyDeployment),
138140
}
139141

142+
#[allow(clippy::enum_variant_names)]
140143
#[derive(Subcommand, PartialEq, Clone, Debug)]
141144
#[clap(bin_name = "chainhook", aliases = &["chainhook"])]
142145
enum Chainhooks {
@@ -663,7 +666,7 @@ pub fn main() {
663666
#[cfg(feature = "telemetry")]
664667
telemetry_report_event(DeveloperUsageEvent::NewProject(DeveloperUsageDigest::new(
665668
&project_opts.name,
666-
&vec![],
669+
&[],
667670
)));
668671
}
669672
}
@@ -834,9 +837,9 @@ pub fn main() {
834837
println!("{}", yellow!("Continue [Y/n]?"));
835838
let mut buffer = String::new();
836839
std::io::stdin().read_line(&mut buffer).unwrap();
837-
if !buffer.starts_with("Y")
838-
&& !buffer.starts_with("y")
839-
&& !buffer.starts_with("\n")
840+
if !buffer.starts_with('Y')
841+
&& !buffer.starts_with('y')
842+
&& !buffer.starts_with('\n')
840843
{
841844
println!("Deployment aborted");
842845
std::process::exit(1);
@@ -1154,8 +1157,7 @@ pub fn main() {
11541157
}
11551158

11561159
if success {
1157-
println!("{} Syntax of contract successfully checked", green!("✔"));
1158-
return;
1160+
println!("{} Syntax of contract successfully checked", green!("✔"))
11591161
} else {
11601162
std::process::exit(1);
11611163
}
@@ -1394,9 +1396,8 @@ fn load_manifest_or_exit(path: Option<String>) -> ProjectManifest {
13941396
}
13951397

13961398
fn load_manifest_or_warn(path: Option<String>) -> Option<ProjectManifest> {
1397-
let manifest_location = get_manifest_location_or_warn(path);
1398-
if manifest_location.is_some() {
1399-
let manifest = match ProjectManifest::from_location(&manifest_location.unwrap()) {
1399+
if let Some(manifest_location) = get_manifest_location_or_warn(path) {
1400+
let manifest = match ProjectManifest::from_location(&manifest_location) {
14001401
Ok(manifest) => manifest,
14011402
Err(message) => {
14021403
println!(
@@ -1584,7 +1585,7 @@ pub fn load_deployment_if_exists(
15841585
println!("{}", yellow!("Overwrite? [Y/n]"));
15851586
let mut buffer = String::new();
15861587
std::io::stdin().read_line(&mut buffer).unwrap();
1587-
if buffer.starts_with("n") {
1588+
if buffer.starts_with('n') {
15881589
Some(load_deployment(manifest, &default_deployment_location))
15891590
} else {
15901591
default_deployment_location

components/clarinet-cli/src/frontend/telemetry.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub struct DeveloperUsageDigest {
2424
}
2525

2626
impl DeveloperUsageDigest {
27-
pub fn new(project_id: &str, team_id: &Vec<String>) -> Self {
27+
pub fn new(project_id: &str, team_id: &[String]) -> Self {
2828
let hashed_project_id = Hash160::from_data(project_id.as_bytes());
2929
let hashed_team_id = Hash160::from_data(team_id.join(",").as_bytes());
3030
Self {
31-
project_id: format!("0x{}", bytes_to_hex(&hashed_project_id.to_bytes().to_vec())),
32-
team_id: format!("0x{}", bytes_to_hex(&hashed_team_id.to_bytes().to_vec())),
31+
project_id: format!("0x{}", bytes_to_hex(hashed_project_id.to_bytes().as_ref())),
32+
team_id: format!("0x{}", bytes_to_hex(hashed_team_id.to_bytes().as_ref())),
3333
}
3434
}
3535
}
@@ -48,9 +48,7 @@ pub fn telemetry_report_event(event: DeveloperUsageEvent) {
4848
async fn send_event(event: DeveloperUsageEvent) {
4949
let segment_api_key = "Q3xpmFRvy0psXnwBEXErtMBIeabOVjbC";
5050

51-
let clarinet_version = option_env!("CARGO_PKG_VERSION")
52-
.expect("Unable to detect version")
53-
.to_string();
51+
let clarinet_version = env!("CARGO_PKG_VERSION").to_string();
5452
let ci_mode = option_env!("CLARINET_MODE_CI").unwrap_or("0").to_string();
5553
let os = std::env::consts::OS;
5654

@@ -153,10 +151,10 @@ async fn send_event(event: DeveloperUsageEvent) {
153151
segment_api_key.to_string(),
154152
Message::from(Track {
155153
user: User::UserId {
156-
user_id: format!("0x{}", bytes_to_hex(&user_id.to_bytes().to_vec())),
154+
user_id: format!("0x{}", bytes_to_hex(user_id.to_bytes().as_ref())),
157155
},
158156
event: event_name.into(),
159-
properties: properties,
157+
properties,
160158
..Default::default()
161159
}),
162160
)

components/clarinet-cli/src/generate/chainhook.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ networks:
6565
.expect("unable to retrieve project root");
6666
new_file.append_path(&format!("chainhooks/{}", name))?;
6767
if new_file.exists() {
68-
return Err(format!("{} already exists", new_file.to_string()));
68+
return Err(format!("{} already exists", new_file));
6969
}
7070
let change = FileCreation {
7171
comment: format!("{} chainhooks/{}", green!("Created file"), name),

components/clarinet-cli/src/generate/contract.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl GetChangesForNewContract {
7979
new_file.append_path("contracts")?;
8080
new_file.append_path(&name)?;
8181
if new_file.exists() {
82-
return Err(format!("{} already exists", new_file.to_string()));
82+
return Err(format!("{} already exists", new_file));
8383
}
8484
let change = FileCreation {
8585
comment: format!("{} contracts/{}", green!("Created file"), name),
@@ -121,7 +121,7 @@ describe("example tests", () => {
121121
new_file.append_path("tests")?;
122122
new_file.append_path(&name)?;
123123
if new_file.exists() {
124-
return Err(format!("{} already exists", new_file.to_string()));
124+
return Err(format!("{} already exists", new_file));
125125
}
126126
let change = FileCreation {
127127
comment: format!("{} tests/{}", green!("Created file"), name),

components/clarinet-cli/src/integrate/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ pub fn run_devnet(
4444
.network_config
4545
.as_ref()
4646
.and_then(|c| c.devnet.as_ref())
47-
.and_then(|d| Some(d.working_dir.to_string()))
47+
.map(|d| d.working_dir.to_string())
4848
.ok_or("unable to read settings/Devnet.toml")?;
4949
fs::create_dir_all(&working_dir)
5050
.map_err(|_| format!("unable to create dir {}", working_dir))?;
5151
let mut log_path = PathBuf::from_str(&working_dir)
52-
.map_err(|e| format!("unable to working_dir {}\n{}", working_dir, e.to_string()))?;
52+
.map_err(|e| format!("unable to working_dir {}\n{}", working_dir, e))?;
5353
log_path.push("devnet.log");
5454

5555
let file = OpenOptions::new()
5656
.create(true)
5757
.write(true)
5858
.truncate(true)
5959
.open(log_path)
60-
.map_err(|e| format!("unable to create log file {}", e.to_string()))?;
60+
.map_err(|e| format!("unable to create log file {}", e))?;
6161

6262
let decorator = slog_term::PlainDecorator::new(file);
6363
let drain = slog_term::FullFormat::new(decorator).build().fuse();

0 commit comments

Comments
 (0)