Skip to content

Commit f2b3fa2

Browse files
decofezerosnacks
andauthored
clippy: warn on if_not_else (autofix) (#14092)
* clippy: warn on if_not_else Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> * refactor: use contains_key + remove instead of if-let remove Simpler branch flip that preserves the original structure. Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> * fix: resolve new if_not_else and redundant_else findings after merge Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> * fix: flip if_not_else in keychain authorize Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> * fix: use multi-line format for blob_hashes if-else Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> * fix: rustfmt prefers single-line if-else here Co-Authored-By: zerosnacks <95942363+zerosnacks@users.noreply.github.com> --------- Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com>
1 parent 0b792f1 commit f2b3fa2

File tree

43 files changed

+205
-208
lines changed

Some content is hidden

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

43 files changed

+205
-208
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ explicit_iter_loop = "warn"
5656
from_iter_instead_of_collect = "warn"
5757
if_then_some_else_none = "warn"
5858
implicit_clone = "warn"
59+
if_not_else = "warn"
5960
imprecise_flops = "warn"
6061
iter_on_empty_collections = "warn"
6162
iter_with_drain = "warn"

benches/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,13 @@ impl BenchmarkProject {
175175
.status()
176176
.wrap_err("Failed to run npm install")?;
177177

178-
if !status.success() {
178+
if status.success() {
179+
sh_println!(" ✅ npm install completed successfully");
180+
} else {
179181
sh_println!(
180182
" ⚠️ Warning: npm install failed with exit code: {:?}",
181183
status.code()
182184
);
183-
} else {
184-
sh_println!(" ✅ npm install completed successfully");
185185
}
186186
}
187187
Ok(())

crates/anvil/src/eth/backend/mem/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,11 +1384,7 @@ impl<N: Network> Backend<N> {
13841384
gas_priority_fee: max_priority_fee_per_gas,
13851385
max_fee_per_blob_gas: max_fee_per_blob_gas
13861386
.or_else(|| {
1387-
if !blob_hashes.is_empty() {
1388-
evm_env.block_env.blob_gasprice()
1389-
} else {
1390-
Some(0)
1391-
}
1387+
if blob_hashes.is_empty() { Some(0) } else { evm_env.block_env.blob_gasprice() }
13921388
})
13931389
.unwrap_or_default(),
13941390
kind: match to {

crates/anvil/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ pub fn init_tracing() -> LoggingManager {
470470
// Mutate the given filter to include `node` logs if it is not already present.
471471
// This prevents the unexpected behaviour of not seeing any node logs if a RUST_LOG
472472
// is already present that doesn't set it.
473-
let rust_log_val = if !rust_log_val.contains("node") {
474-
format!("{rust_log_val},node=info")
475-
} else {
473+
let rust_log_val = if rust_log_val.contains("node") {
476474
rust_log_val
475+
} else {
476+
format!("{rust_log_val},node=info")
477477
};
478478

479479
let env_filter: EnvFilter =

crates/cast/src/args.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
195195
print_tokens(&tokens);
196196
}
197197
CastSubcommand::AbiEncode { sig, packed, args } => {
198-
if !packed {
199-
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
200-
} else {
198+
if packed {
201199
sh_println!("{}", SimpleCast::abi_encode_packed(&sig, &args)?)?
200+
} else {
201+
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
202202
}
203203
}
204204
CastSubcommand::AbiEncodeEvent { sig, args } => {

crates/cast/src/cmd/keychain.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ async fn run_check(wallet_address: Address, key_address: Address, rpc: RpcOpts)
546546

547547
// Expiry: show human-readable date and whether it's expired.
548548
let expiry_str = format_expiry(info.expiry);
549-
if info.expiry != u64::MAX {
549+
if info.expiry == u64::MAX {
550+
sh_println!("Expiry: {}", expiry_str)?;
551+
} else {
550552
let now = std::time::SystemTime::now()
551553
.duration_since(std::time::UNIX_EPOCH)
552554
.unwrap_or_default()
@@ -556,8 +558,6 @@ async fn run_check(wallet_address: Address, key_address: Address, rpc: RpcOpts)
556558
} else {
557559
sh_println!("Expiry: {}", expiry_str)?;
558560
}
559-
} else {
560-
sh_println!("Expiry: {}", expiry_str)?;
561561
}
562562

563563
sh_println!("Spending Limits: {}", if info.enforceLimits { "enforced" } else { "none" })?;
@@ -579,7 +579,17 @@ async fn run_authorize(
579579
) -> Result<()> {
580580
let enforce = enforce_limits || !limits.is_empty();
581581

582-
let calldata = if !allowed_calls.is_empty() {
582+
let calldata = if allowed_calls.is_empty() {
583+
// Use the legacy authorizeKey when no scopes are needed.
584+
IAccountKeychain::authorizeKeyCall {
585+
keyId: key_address,
586+
signatureType: key_type,
587+
expiry,
588+
enforceLimits: enforce,
589+
limits,
590+
}
591+
.abi_encode()
592+
} else {
583593
// Use the T3+ authorizeKey overload with KeyRestrictions when scopes are provided.
584594
let sig_type_u8 = match key_type {
585595
SignatureType::Secp256k1 => 0u8,
@@ -603,16 +613,6 @@ async fn run_authorize(
603613
config: restrictions,
604614
}
605615
.abi_encode()
606-
} else {
607-
// Use the legacy authorizeKey when no scopes are needed.
608-
IAccountKeychain::authorizeKeyCall {
609-
keyId: key_address,
610-
signatureType: key_type,
611-
expiry,
612-
enforceLimits: enforce,
613-
limits,
614-
}
615-
.abi_encode()
616616
};
617617

618618
send_keychain_tx(calldata, tx_opts, &send_tx).await
@@ -783,10 +783,10 @@ fn print_key_entry(entry: &tempo::KeyEntry) -> Result<()> {
783783
if let Some(key_address) = entry.key_address {
784784
sh_println!("Key Address: {key_address}")?;
785785

786-
if key_address != entry.wallet_address {
787-
sh_println!("Mode: keychain (access key)")?;
788-
} else {
786+
if key_address == entry.wallet_address {
789787
sh_println!("Mode: direct (EOA)")?;
788+
} else {
789+
sh_println!("Mode: keychain (access key)")?;
790790
}
791791
} else {
792792
sh_println!("Key Address: (not set)")?;

crates/cheatcodes/src/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ fn encode(values: Vec<DynSolValue>) -> Vec<u8> {
503503
/// Canonicalize a json path key to always start from the root of the document.
504504
/// Read more about json path syntax: <https://goessner.net/articles/JsonPath/>
505505
pub(super) fn canonicalize_json_path(path: &str) -> Cow<'_, str> {
506-
if !path.starts_with('$') { format!("${path}").into() } else { path.into() }
506+
if path.starts_with('$') { path.into() } else { format!("${path}").into() }
507507
}
508508

509509
/// Converts a JSON [`Value`] to a [`DynSolValue`] by trying to guess encoded type. For safer

crates/cheatcodes/src/test/assert.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ fn assert_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a
467467
}
468468

469469
fn assert_not_eq<'a, T: PartialEq>(left: &'a T, right: &'a T) -> ComparisonResult<'a, T> {
470-
if left != right {
471-
Ok(())
472-
} else {
470+
if left == right {
473471
Err(ComparisonAssertionError { kind: AssertionKind::Ne, left, right })
472+
} else {
473+
Ok(())
474474
}
475475
}
476476

crates/cheatcodes/src/test/expect.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,10 +1244,10 @@ pub(crate) fn get_emit_mismatch_message(
12441244
{
12451245
let (expected_name, expected_value) = &expected_params[param_idx];
12461246
let (_actual_name, actual_value) = &actual_params[param_idx];
1247-
let param_name = if !expected_name.is_empty() {
1248-
expected_name
1249-
} else {
1247+
let param_name = if expected_name.is_empty() {
12501248
&format!("param{param_idx}")
1249+
} else {
1250+
expected_name
12511251
};
12521252
return format!(
12531253
"{param_name}: expected={expected_value}, got={actual_value}",

crates/cheatcodes/src/test/revert_handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ pub(crate) fn handle_expect_revert(
198198

199199
// If we expect no reverts with a specific reason/reverter, but got a revert,
200200
// we need to check if it matches our criteria
201-
if !matches!(status, return_ok!()) {
201+
if matches!(status, return_ok!()) {
202+
// No revert occurred, which is what we expected
203+
Ok(success_return())
204+
} else {
202205
// We got a revert, but we expected 0 reverts
203206
// We need to check if this revert matches our expected criteria
204207

@@ -266,9 +269,6 @@ pub(crate) fn handle_expect_revert(
266269
}
267270
}
268271
}
269-
} else {
270-
// No revert occurred, which is what we expected
271-
Ok(success_return())
272272
}
273273
} else {
274274
ensure!(!matches!(status, return_ok!()), "next call did not revert as expected");

0 commit comments

Comments
 (0)