Skip to content

Commit 75cfc24

Browse files
zerosnacksleovct
authored andcommitted
chore(forge): enforce common::shell for forge crate (foundry-rs#9231)
* enforce common shell for forge crate * revert clippy.toml * fix tests * avoid empty printlns * fix missed eprint / print * avoid style regression
1 parent 5436a46 commit 75cfc24

29 files changed

+136
-131
lines changed

crates/cast/bin/cmd/create2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ impl Create2Args {
193193

194194
sh_println!("Configuration:")?;
195195
sh_println!("Init code hash: {init_code_hash}")?;
196-
sh_println!("Regex patterns: {:?}", regex.patterns())?;
197-
sh_println!()?;
196+
sh_println!("Regex patterns: {:?}\n", regex.patterns())?;
198197
sh_println!(
199198
"Starting to generate deterministic contract address with {n_threads} threads..."
200199
)?;

crates/forge/bin/cmd/bind.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ impl BindArgs {
106106
}
107107

108108
if self.ethers {
109-
eprintln!(
110-
"Warning: `--ethers` bindings are deprecated and will be removed in the future. \
111-
Consider using `--alloy` (default) instead."
112-
);
109+
sh_warn!(
110+
"`--ethers` bindings are deprecated and will be removed in the future. Consider using `--alloy` (default) instead."
111+
)?;
113112
}
114113

115114
let config = self.try_load_config_emit_warnings()?;
@@ -118,7 +117,7 @@ impl BindArgs {
118117

119118
if bindings_root.exists() {
120119
if !self.overwrite {
121-
println!("Bindings found. Checking for consistency.");
120+
sh_println!("Bindings found. Checking for consistency.")?;
122121
return self.check_existing_bindings(&artifacts, &bindings_root);
123122
}
124123

@@ -128,7 +127,7 @@ impl BindArgs {
128127

129128
self.generate_bindings(&artifacts, &bindings_root)?;
130129

131-
println!("Bindings have been generated to {}", bindings_root.display());
130+
sh_println!("Bindings have been generated to {}", bindings_root.display())?;
132131
Ok(())
133132
}
134133

@@ -274,7 +273,7 @@ impl BindArgs {
274273

275274
fn check_ethers(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
276275
let bindings = self.get_multi(artifacts)?.build()?;
277-
println!("Checking bindings for {} contracts.", bindings.len());
276+
sh_println!("Checking bindings for {} contracts.", bindings.len())?;
278277
if !self.module {
279278
bindings
280279
.ensure_consistent_crate(
@@ -294,14 +293,14 @@ impl BindArgs {
294293
} else {
295294
bindings.ensure_consistent_module(bindings_root, self.single_file)?;
296295
}
297-
println!("OK.");
296+
sh_println!("OK.")?;
298297
Ok(())
299298
}
300299

301300
fn check_alloy(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
302301
let mut bindings = self.get_solmacrogen(artifacts)?;
303302
bindings.generate_bindings()?;
304-
println!("Checking bindings for {} contracts", bindings.instances.len());
303+
sh_println!("Checking bindings for {} contracts", bindings.instances.len())?;
305304
bindings.check_consistency(
306305
&self.crate_name,
307306
&self.crate_version,
@@ -311,7 +310,7 @@ impl BindArgs {
311310
self.module,
312311
self.alloy_version.clone(),
313312
)?;
314-
println!("OK.");
313+
sh_println!("OK.")?;
315314
Ok(())
316315
}
317316

@@ -326,7 +325,7 @@ impl BindArgs {
326325

327326
fn generate_ethers(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
328327
let mut bindings = self.get_multi(artifacts)?.build()?;
329-
println!("Generating bindings for {} contracts", bindings.len());
328+
sh_println!("Generating bindings for {} contracts", bindings.len())?;
330329
if !self.module {
331330
trace!(single_file = self.single_file, "generating crate");
332331
if !self.skip_extra_derives {
@@ -346,7 +345,7 @@ impl BindArgs {
346345

347346
fn generate_alloy(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
348347
let mut solmacrogen = self.get_solmacrogen(artifacts)?;
349-
println!("Generating bindings for {} contracts", solmacrogen.instances.len());
348+
sh_println!("Generating bindings for {} contracts", solmacrogen.instances.len())?;
350349

351350
if !self.module {
352351
trace!(single_file = self.single_file, "generating crate");

crates/forge/bin/cmd/bind_json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl ResolvedState {
439439
}
440440
fs::write(&self.target_path, &result)?;
441441

442-
println!("Bindings written to {}", self.target_path.display());
442+
sh_println!("Bindings written to {}", self.target_path.display())?;
443443

444444
Ok(result)
445445
}

crates/forge/bin/cmd/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl LsArgs {
101101
ChainOrAll::All => cache = Config::list_foundry_cache()?,
102102
}
103103
}
104-
print!("{cache}");
104+
sh_print!("{cache}")?;
105105
Ok(())
106106
}
107107
}

crates/forge/bin/cmd/clone.rs

+1
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ mod tests {
616616
use foundry_test_utils::rpc::next_mainnet_etherscan_api_key;
617617
use std::collections::BTreeMap;
618618

619+
#[allow(clippy::disallowed_macros)]
619620
fn assert_successful_compilation(root: &PathBuf) -> ProjectCompileOutput {
620621
println!("project_root: {root:#?}");
621622
compile_project(root).expect("compilation failure")

crates/forge/bin/cmd/compiler.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,25 @@ impl ResolveArgs {
141141
}
142142

143143
if json {
144-
println!("{}", serde_json::to_string(&output)?);
144+
sh_println!("{}", serde_json::to_string(&output)?)?;
145145
return Ok(());
146146
}
147147

148148
for (language, compilers) in &output {
149149
match verbosity {
150-
0 => println!("{language}:"),
151-
_ => println!("{language}:\n"),
150+
0 => sh_println!("{language}:")?,
151+
_ => sh_println!("{language}:\n")?,
152152
}
153153

154154
for resolved_compiler in compilers {
155155
let version = &resolved_compiler.version;
156156
match verbosity {
157-
0 => println!("- {version}"),
157+
0 => sh_println!("- {version}")?,
158158
_ => {
159159
if let Some(evm) = &resolved_compiler.evm_version {
160-
println!("{version} (<= {evm}):")
160+
sh_println!("{version} (<= {evm}):")?
161161
} else {
162-
println!("{version}:")
162+
sh_println!("{version}:")?
163163
}
164164
}
165165
}
@@ -168,16 +168,16 @@ impl ResolveArgs {
168168
let paths = &resolved_compiler.paths;
169169
for (idx, path) in paths.iter().enumerate() {
170170
if idx == paths.len() - 1 {
171-
println!("└── {path}\n");
171+
sh_println!("└── {path}\n")?
172172
} else {
173-
println!("├── {path}");
173+
sh_println!("├── {path}")?
174174
}
175175
}
176176
}
177177
}
178178

179179
if verbosity == 0 {
180-
println!();
180+
sh_println!()?
181181
}
182182
}
183183

crates/forge/bin/cmd/create.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,18 @@ impl CreateArgs {
318318
"deployedTo": address.to_string(),
319319
"transactionHash": receipt.transaction_hash
320320
});
321-
println!("{output}");
321+
sh_println!("{output}")?;
322322
} else {
323-
println!("Deployer: {deployer_address}");
324-
println!("Deployed to: {address}");
325-
println!("Transaction hash: {:?}", receipt.transaction_hash);
323+
sh_println!("Deployer: {deployer_address}")?;
324+
sh_println!("Deployed to: {address}")?;
325+
sh_println!("Transaction hash: {:?}", receipt.transaction_hash)?;
326326
};
327327

328328
if !self.verify {
329329
return Ok(());
330330
}
331331

332-
println!("Starting contract verification...");
332+
sh_println!("Starting contract verification...")?;
333333

334334
let num_of_optimizations = if self.opts.compiler.optimize.unwrap_or_default() {
335335
self.opts.compiler.optimizer_runs
@@ -358,7 +358,7 @@ impl CreateArgs {
358358
show_standard_json_input: self.show_standard_json_input,
359359
guess_constructor_args: false,
360360
};
361-
println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier);
361+
sh_println!("Waiting for {} to detect contract deployment...", verify.verifier.verifier)?;
362362
verify.run().await
363363
}
364364

crates/forge/bin/cmd/doc/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Server {
7575
let file_404 = get_404_output_file(&input_404);
7676

7777
let serving_url = format!("http://{address}");
78-
println!("Serving on: {serving_url}");
78+
sh_println!("Serving on: {serving_url}")?;
7979

8080
let thread_handle = std::thread::spawn(move || serve(build_dir, sockaddr, &file_404));
8181

crates/forge/bin/cmd/eip712.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ impl Eip712Args {
6363

6464
for (id, _) in structs_in_target {
6565
if let Some(resolved) = resolver.resolve_struct_eip712(id)? {
66-
println!("{resolved}");
67-
println!();
66+
sh_println!("{resolved}\n")?;
6867
}
6968
}
7069

crates/forge/bin/cmd/flatten.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ impl FlattenArgs {
6464
Some(output) => {
6565
fs::create_dir_all(output.parent().unwrap())?;
6666
fs::write(&output, flattened)?;
67-
println!("Flattened file written at {}", output.display());
67+
sh_println!("Flattened file written at {}", output.display())?;
6868
}
69-
None => println!("{flattened}"),
69+
None => sh_println!("{flattened}")?,
7070
};
7171

7272
Ok(())

crates/forge/bin/cmd/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl FmtArgs {
129129
let new_format = diff.ratio() < 1.0;
130130
if self.check || path.is_none() {
131131
if self.raw {
132-
print!("{output}");
132+
sh_print!("{output}")?;
133133
}
134134

135135
// If new format then compute diff summary.

crates/forge/bin/cmd/geiger/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use foundry_config::{impl_figment_convert_basic, Config};
66
use itertools::Itertools;
77
use rayon::prelude::*;
88
use std::path::PathBuf;
9-
use yansi::Paint;
109

1110
mod error;
1211

@@ -95,7 +94,7 @@ impl GeigerArgs {
9594
let sources = self.sources(&config).wrap_err("Failed to resolve files")?;
9695

9796
if config.ffi {
98-
eprintln!("{}\n", "ffi enabled".red());
97+
sh_warn!("FFI enabled\n")?;
9998
}
10099

101100
let root = config.root.0;
@@ -107,12 +106,12 @@ impl GeigerArgs {
107106
let len = metrics.cheatcodes.len();
108107
let printer = SolFileMetricsPrinter { metrics: &metrics, root: &root };
109108
if self.full || len == 0 {
110-
eprint!("{printer}");
109+
let _ = sh_eprint!("{printer}");
111110
}
112111
len
113112
}
114113
Err(err) => {
115-
eprintln!("{err}");
114+
let _ = sh_err!("{err}");
116115
0
117116
}
118117
})

crates/forge/bin/cmd/generate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl GenerateTestArgs {
4444
// Write the test content to the test file.
4545
fs::write(&test_file_path, test_content)?;
4646

47-
println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap());
47+
sh_println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap())?;
4848
Ok(())
4949
}
5050
}

crates/forge/bin/cmd/inspect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl InspectArgs {
8787
.ok_or_else(|| eyre::eyre!("Failed to fetch lossless ABI"))?;
8888
if pretty {
8989
let source = foundry_cli::utils::abi_to_solidity(abi, &contract.name)?;
90-
println!("{source}");
90+
sh_println!("{source}")?;
9191
} else {
9292
print_json(abi)?;
9393
}
@@ -201,7 +201,7 @@ pub fn print_storage_layout(storage_layout: Option<&StorageLayout>, pretty: bool
201201
]);
202202
}
203203

204-
println!("{table}");
204+
sh_println!("{table}")?;
205205
Ok(())
206206
}
207207

@@ -390,12 +390,12 @@ impl ContractArtifactField {
390390
}
391391

392392
fn print_json(obj: &impl serde::Serialize) -> Result<()> {
393-
println!("{}", serde_json::to_string_pretty(obj)?);
393+
sh_println!("{}", serde_json::to_string_pretty(obj)?)?;
394394
Ok(())
395395
}
396396

397397
fn print_json_str(obj: &impl serde::Serialize, key: Option<&str>) -> Result<()> {
398-
println!("{}", get_json_str(obj, key)?);
398+
sh_println!("{}", get_json_str(obj, key)?)?;
399399
Ok(())
400400
}
401401

@@ -408,9 +408,9 @@ fn print_yul(yul: Option<&str>, pretty: bool) -> Result<()> {
408408
LazyLock::new(|| Regex::new(r"(///.*\n\s*)|(\s*/\*\*.*\*/)").unwrap());
409409

410410
if pretty {
411-
println!("{}", YUL_COMMENTS.replace_all(yul, ""));
411+
sh_println!("{}", YUL_COMMENTS.replace_all(yul, ""))?;
412412
} else {
413-
println!("{yul}");
413+
sh_println!("{yul}")?;
414414
}
415415

416416
Ok(())
@@ -450,7 +450,7 @@ fn print_eof(bytecode: Option<CompactBytecode>) -> Result<()> {
450450

451451
let eof = Eof::decode(bytecode).wrap_err("Failed to decode EOF")?;
452452

453-
println!("{}", pretty_eof(&eof)?);
453+
sh_println!("{}", pretty_eof(&eof)?)?;
454454

455455
Ok(())
456456
}

crates/forge/bin/cmd/install.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,9 @@ impl Installer<'_> {
412412

413413
// multiple candidates, ask the user to choose one or skip
414414
candidates.insert(0, String::from("SKIP AND USE ORIGINAL TAG"));
415-
println!("There are multiple matching tags:");
415+
sh_println!("There are multiple matching tags:")?;
416416
for (i, candidate) in candidates.iter().enumerate() {
417-
println!("[{i}] {candidate}");
417+
sh_println!("[{i}] {candidate}")?;
418418
}
419419

420420
let n_candidates = candidates.len();
@@ -429,7 +429,7 @@ impl Installer<'_> {
429429
Ok(0) => return Ok(tag.into()),
430430
Ok(i) if (1..=n_candidates).contains(&i) => {
431431
let c = &candidates[i];
432-
println!("[{i}] {c} selected");
432+
sh_println!("[{i}] {c} selected")?;
433433
return Ok(c.clone())
434434
}
435435
_ => continue,
@@ -474,9 +474,9 @@ impl Installer<'_> {
474474

475475
// multiple candidates, ask the user to choose one or skip
476476
candidates.insert(0, format!("{tag} (original branch)"));
477-
println!("There are multiple matching branches:");
477+
sh_println!("There are multiple matching branches:")?;
478478
for (i, candidate) in candidates.iter().enumerate() {
479-
println!("[{i}] {candidate}");
479+
sh_println!("[{i}] {candidate}")?;
480480
}
481481

482482
let n_candidates = candidates.len();
@@ -488,7 +488,7 @@ impl Installer<'_> {
488488

489489
// default selection, return None
490490
if input.is_empty() {
491-
println!("Canceled branch matching");
491+
sh_println!("Canceled branch matching")?;
492492
return Ok(None)
493493
}
494494

@@ -497,7 +497,7 @@ impl Installer<'_> {
497497
Ok(0) => Ok(Some(tag.into())),
498498
Ok(i) if (1..=n_candidates).contains(&i) => {
499499
let c = &candidates[i];
500-
println!("[{i}] {c} selected");
500+
sh_println!("[{i}] {c} selected")?;
501501
Ok(Some(c.clone()))
502502
}
503503
_ => Ok(None),

0 commit comments

Comments
 (0)