From 7ca39811c644904d2249aca6545ccbe60604d21b Mon Sep 17 00:00:00 2001 From: InSyncWithFoo Date: Fri, 22 Nov 2024 03:29:25 +0000 Subject: [PATCH] Clippy --- .../function_call_in_dataclass_default.rs | 13 ++++++++----- .../src/rules/ruff/rules/helpers.rs | 18 +++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs index bf9d38f33c2ee..5902584a71b9d 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/function_call_in_dataclass_default.rs @@ -91,10 +91,13 @@ pub(crate) fn function_call_in_dataclass_default( DataclassKind::Attrs(attrs_auto_attribs) => match attrs_auto_attribs { AttrsAutoAttribs::Unknown => return, - AttrsAutoAttribs::None => match any_annotated(&class_def.body) { - true => Some(AttrsAutoAttribs::True), - false => Some(AttrsAutoAttribs::False), - }, + AttrsAutoAttribs::None => { + if any_annotated(&class_def.body) { + Some(AttrsAutoAttribs::True) + } else { + Some(AttrsAutoAttribs::False) + } + } _ => Some(attrs_auto_attribs), }, @@ -151,7 +154,7 @@ pub(crate) fn function_call_in_dataclass_default( } #[inline] -fn any_annotated(class_body: &Vec) -> bool { +fn any_annotated(class_body: &[Stmt]) -> bool { class_body .iter() .any(|stmt| matches!(stmt, Stmt::AnnAssign(..))) diff --git a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs index a6f3816a624e7..d6a743b677bf4 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/helpers.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/helpers.rs @@ -135,9 +135,10 @@ pub(super) fn dataclass_kind( // https://www.attrs.org/en/stable/api.html#attrs.define // https://www.attrs.org/en/stable/api-attr.html#attr.s let Expr::Call(ExprCall { arguments, .. }) = &decorator.expression else { - let auto_attribs = match func.as_ref() { - "s" => AttrsAutoAttribs::False, - _ => AttrsAutoAttribs::None, + let auto_attribs = if *func == "s" { + AttrsAutoAttribs::False + } else { + AttrsAutoAttribs::None }; return Some(DataclassKind::Attrs(auto_attribs)); @@ -148,10 +149,13 @@ pub(super) fn dataclass_kind( }; let auto_attribs = match &auto_attribs.value { - Expr::BooleanLiteral(literal) => match literal.value { - true => AttrsAutoAttribs::True, - false => AttrsAutoAttribs::False, - }, + Expr::BooleanLiteral(literal) => { + if literal.value { + AttrsAutoAttribs::True + } else { + AttrsAutoAttribs::False + } + } Expr::NoneLiteral(..) => AttrsAutoAttribs::None, _ => AttrsAutoAttribs::Unknown, };