Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(forge): enforce common::shell for forge crate #9231

Merged
merged 8 commits into from
Nov 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
enforce common shell for forge crate
zerosnacks committed Oct 30, 2024
commit c818ca86c26fd9595caf2f2ca7d6eb5844909df8
14 changes: 7 additions & 7 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ msrv = "1.80"
# so it is safe to ignore it as well
ignore-interior-mutability = ["bytes::Bytes", "alloy_primitives::Bytes"]

# disallowed-macros = [
# # See `foundry_common::shell`
# { path = "std::print", reason = "use `sh_print` or similar macros instead" },
# { path = "std::eprint", reason = "use `sh_eprint` or similar macros instead" },
# { path = "std::println", reason = "use `sh_println` or similar macros instead" },
# { path = "std::eprintln", reason = "use `sh_eprintln` or similar macros instead" },
# ]
disallowed-macros = [
# See `foundry_common::shell`
{ path = "std::print", reason = "use `sh_print` or similar macros instead" },
{ path = "std::eprint", reason = "use `sh_eprint` or similar macros instead" },
{ path = "std::println", reason = "use `sh_println` or similar macros instead" },
{ path = "std::eprintln", reason = "use `sh_eprintln` or similar macros instead" },
]
23 changes: 11 additions & 12 deletions crates/forge/bin/cmd/bind.rs
Original file line number Diff line number Diff line change
@@ -106,10 +106,9 @@ impl BindArgs {
}

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

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

if bindings_root.exists() {
if !self.overwrite {
println!("Bindings found. Checking for consistency.");
sh_println!("Bindings found. Checking for consistency.")?;
return self.check_existing_bindings(&artifacts, &bindings_root);
}

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

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

println!("Bindings have been generated to {}", bindings_root.display());
sh_println!("Bindings have been generated to {}", bindings_root.display())?;
Ok(())
}

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

fn check_ethers(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let bindings = self.get_multi(artifacts)?.build()?;
println!("Checking bindings for {} contracts.", bindings.len());
sh_println!("Checking bindings for {} contracts.", bindings.len())?;
if !self.module {
bindings
.ensure_consistent_crate(
@@ -294,14 +293,14 @@ impl BindArgs {
} else {
bindings.ensure_consistent_module(bindings_root, self.single_file)?;
}
println!("OK.");
sh_println!("OK.")?;
Ok(())
}

fn check_alloy(&self, artifacts: &Path, bindings_root: &Path) -> Result<()> {
let mut bindings = self.get_solmacrogen(artifacts)?;
bindings.generate_bindings()?;
println!("Checking bindings for {} contracts", bindings.instances.len());
sh_println!("Checking bindings for {} contracts", bindings.instances.len())?;
bindings.check_consistency(
&self.crate_name,
&self.crate_version,
@@ -311,7 +310,7 @@ impl BindArgs {
self.module,
self.alloy_version.clone(),
)?;
println!("OK.");
sh_println!("OK.")?;
Ok(())
}

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

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

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

if !self.module {
trace!(single_file = self.single_file, "generating crate");
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/bind_json.rs
Original file line number Diff line number Diff line change
@@ -439,7 +439,7 @@ impl ResolvedState {
}
fs::write(&self.target_path, &result)?;

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

Ok(result)
}
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/cache.rs
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ impl LsArgs {
ChainOrAll::All => cache = Config::list_foundry_cache()?,
}
}
print!("{cache}");
sh_print!("{cache}")?;
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/clone.rs
Original file line number Diff line number Diff line change
@@ -616,6 +616,7 @@ mod tests {
use foundry_test_utils::rpc::next_mainnet_etherscan_api_key;
use std::collections::BTreeMap;

#[allow(clippy::disallowed_macros)]
fn assert_successful_compilation(root: &PathBuf) -> ProjectCompileOutput {
println!("project_root: {root:#?}");
compile_project(root).expect("compilation failure")
18 changes: 9 additions & 9 deletions crates/forge/bin/cmd/compiler.rs
Original file line number Diff line number Diff line change
@@ -141,25 +141,25 @@ impl ResolveArgs {
}

if json {
println!("{}", serde_json::to_string(&output)?);
sh_println!("{}", serde_json::to_string(&output)?)?;
return Ok(());
}

for (language, compilers) in &output {
match verbosity {
0 => println!("{language}:"),
_ => println!("{language}:\n"),
0 => sh_println!("{language}:")?,
_ => sh_println!("{language}:\n")?,
}

for resolved_compiler in compilers {
let version = &resolved_compiler.version;
match verbosity {
0 => println!("- {version}"),
0 => sh_println!("- {version}")?,
_ => {
if let Some(evm) = &resolved_compiler.evm_version {
println!("{version} (<= {evm}):")
sh_println!("{version} (<= {evm}):")?
} else {
println!("{version}:")
sh_println!("{version}:")?
}
}
}
@@ -168,16 +168,16 @@ impl ResolveArgs {
let paths = &resolved_compiler.paths;
for (idx, path) in paths.iter().enumerate() {
if idx == paths.len() - 1 {
println!("└── {path}\n");
sh_println!("└── {path}\n")?
} else {
println!("├── {path}");
sh_println!("├── {path}")?
}
}
}
}

if verbosity == 0 {
println!();
sh_println!()?
}
}

12 changes: 6 additions & 6 deletions crates/forge/bin/cmd/create.rs
Original file line number Diff line number Diff line change
@@ -321,18 +321,18 @@ impl CreateArgs {
"deployedTo": address.to_string(),
"transactionHash": receipt.transaction_hash
});
println!("{output}");
sh_println!("{output}")?;
} else {
println!("Deployer: {deployer_address}");
println!("Deployed to: {address}");
println!("Transaction hash: {:?}", receipt.transaction_hash);
sh_println!("Deployer: {deployer_address}")?;
sh_println!("Deployed to: {address}")?;
sh_println!("Transaction hash: {:?}", receipt.transaction_hash)?;
};

if !self.verify {
return Ok(());
}

println!("Starting contract verification...");
sh_println!("Starting contract verification...")?;

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

2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/doc/server.rs
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ impl Server {
let file_404 = get_404_output_file(&input_404);

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

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

4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/eip712.rs
Original file line number Diff line number Diff line change
@@ -63,8 +63,8 @@ impl Eip712Args {

for (id, _) in structs_in_target {
if let Some(resolved) = resolver.resolve_struct_eip712(id)? {
println!("{resolved}");
println!();
sh_println!("{resolved}");
sh_println!();
}
}

4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/flatten.rs
Original file line number Diff line number Diff line change
@@ -64,9 +64,9 @@ impl FlattenArgs {
Some(output) => {
fs::create_dir_all(output.parent().unwrap())?;
fs::write(&output, flattened)?;
println!("Flattened file written at {}", output.display());
sh_println!("Flattened file written at {}", output.display())?;
}
None => println!("{flattened}"),
None => sh_println!("{flattened}")?,
};

Ok(())
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/fmt.rs
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ impl FmtArgs {
let new_format = diff.ratio() < 1.0;
if self.check || path.is_none() {
if self.raw {
print!("{output}");
sh_print!("{output}")?;
}

// If new format then compute diff summary.
4 changes: 2 additions & 2 deletions crates/forge/bin/cmd/geiger/mod.rs
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ impl GeigerArgs {
let sources = self.sources(&config).wrap_err("Failed to resolve files")?;

if config.ffi {
eprintln!("{}\n", "ffi enabled".red());
sh_warn!("FFI enabled")?;
}

let root = config.root.0;
@@ -112,7 +112,7 @@ impl GeigerArgs {
len
}
Err(err) => {
eprintln!("{err}");
let _ = sh_err!("{err}");
0
}
})
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/generate/mod.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ impl GenerateTestArgs {
// Write the test content to the test file.
fs::write(&test_file_path, test_content)?;

println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap());
sh_println!("{} test file: {}", "Generated".green(), test_file_path.to_str().unwrap())?;
Ok(())
}
}
14 changes: 7 additions & 7 deletions crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ impl InspectArgs {
.ok_or_else(|| eyre::eyre!("Failed to fetch lossless ABI"))?;
if pretty {
let source = foundry_cli::utils::abi_to_solidity(abi, &contract.name)?;
println!("{source}");
sh_println!("{source}")?;
} else {
print_json(abi)?;
}
@@ -201,7 +201,7 @@ pub fn print_storage_layout(storage_layout: Option<&StorageLayout>, pretty: bool
]);
}

println!("{table}");
sh_println!("{table}")?;
Ok(())
}

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

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

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

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

if pretty {
println!("{}", YUL_COMMENTS.replace_all(yul, ""));
sh_println!("{}", YUL_COMMENTS.replace_all(yul, ""))?;
} else {
println!("{yul}");
sh_println!("{yul}")?;
}

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

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

println!("{}", pretty_eof(&eof)?);
sh_println!("{}", pretty_eof(&eof)?)?;

Ok(())
}
14 changes: 7 additions & 7 deletions crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
@@ -412,9 +412,9 @@ impl Installer<'_> {

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

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

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

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

// default selection, return None
if input.is_empty() {
println!("Canceled branch matching");
sh_println!("Canceled branch matching")?;
return Ok(None)
}

@@ -497,7 +497,7 @@ impl Installer<'_> {
Ok(0) => Ok(Some(tag.into())),
Ok(i) if (1..=n_candidates).contains(&i) => {
let c = &candidates[i];
println!("[{i}] {c} selected");
sh_println!("[{i}] {c} selected")?;
Ok(Some(c.clone()))
}
_ => Ok(None),
Loading
Oops, something went wrong.