From 0e9427255fe3f9f42e1947a6f35af4483c101e95 Mon Sep 17 00:00:00 2001 From: Harutaka Kawamura Date: Mon, 9 Dec 2024 23:54:57 +0900 Subject: [PATCH] [`pyupgrade`] Remove unreachable code in `UP015` implementation (#14871) --- .../pyupgrade/rules/redundant_open_modes.rs | 59 ++++++------------- 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs index 1b4dccc0c27ea..68738cd6a41ef 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -71,47 +71,24 @@ pub(crate) fn redundant_open_modes(checker: &mut Checker, call: &ast::ExprCall) return; } - match call.arguments.find_argument("mode", 1) { - None => { - if !call.arguments.is_empty() { - if let Some(keyword) = call.arguments.find_keyword("mode") { - if let Expr::StringLiteral(ast::ExprStringLiteral { - value: mode_param_value, - .. - }) = &keyword.value - { - if let Ok(mode) = OpenMode::from_chars(mode_param_value.chars()) { - let reduced = mode.reduce(); - if reduced != mode { - checker.diagnostics.push(create_diagnostic( - call, - &keyword.value, - reduced, - checker.tokens(), - checker.stylist(), - )); - } - } - } - } - } - } - Some(mode_param) => { - if let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = &mode_param { - if let Ok(mode) = OpenMode::from_chars(value.chars()) { - let reduced = mode.reduce(); - if reduced != mode { - checker.diagnostics.push(create_diagnostic( - call, - mode_param, - reduced, - checker.tokens(), - checker.stylist(), - )); - } - } - } - } + let Some(mode_param) = call.arguments.find_argument("mode", 1) else { + return; + }; + let Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) = &mode_param else { + return; + }; + let Ok(mode) = OpenMode::from_chars(value.chars()) else { + return; + }; + let reduced = mode.reduce(); + if reduced != mode { + checker.diagnostics.push(create_diagnostic( + call, + mode_param, + reduced, + checker.tokens(), + checker.stylist(), + )); } }