diff --git a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs index 733d3f5d64..f6e94c3e45 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/rules/assertion.rs @@ -66,12 +66,8 @@ impl Violation for CompositeAssertion { } fn autofix_title_formatter(&self) -> Option String> { - let CompositeAssertion { fixable } = self; - if *fixable { - Some(|_| format!("Break down assertion into multiple parts")) - } else { - None - } + self.fixable + .then_some(|_| format!("Break down assertion into multiple parts")) } } diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs index 35994aeead..738122cd2b 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_if.rs @@ -48,12 +48,8 @@ impl Violation for CollapsibleIf { } fn autofix_title_formatter(&self) -> Option String> { - let CollapsibleIf { fixable, .. } = self; - if *fixable { - Some(|_| format!("Combine `if` statements using `and`")) - } else { - None - } + self.fixable + .then_some(|_| format!("Combine `if` statements using `and`")) } } @@ -73,12 +69,9 @@ impl Violation for NeedlessBool { } fn autofix_title_formatter(&self) -> Option String> { - let NeedlessBool { fixable, .. } = self; - if *fixable { - Some(|NeedlessBool { condition, .. }| format!("Replace with `return {condition}`")) - } else { - None - } + self.fixable.then_some(|NeedlessBool { condition, .. }| { + format!("Replace with `return {condition}`") + }) } } @@ -124,18 +117,14 @@ impl Violation for UseTernaryOperator { #[derive_message_formats] fn message(&self) -> String { let UseTernaryOperator { contents, .. } = self; - format!("Use ternary operator `{contents}` instead of if-else-block") + format!("Use ternary operator `{contents}` instead of `if`-`else`-block") } fn autofix_title_formatter(&self) -> Option String> { - let UseTernaryOperator { fixable, .. } = self; - if *fixable { - Some(|UseTernaryOperator { contents, .. }| { - format!("Replace if-else-block with `{contents}`") + self.fixable + .then_some(|UseTernaryOperator { contents, .. }| { + format!("Replace `if`-`else`-block with `{contents}`") }) - } else { - None - } } } @@ -185,12 +174,8 @@ impl Violation for DictGetWithDefault { } fn autofix_title_formatter(&self) -> Option String> { - let DictGetWithDefault { fixable, .. } = self; - if *fixable { - Some(|DictGetWithDefault { contents, .. }| format!("Replace with `{contents}`")) - } else { - None - } + self.fixable + .then_some(|DictGetWithDefault { contents, .. }| format!("Replace with `{contents}`")) } } diff --git a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs index 25a19a067b..2af1a08a48 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/ast_with.rs @@ -55,12 +55,8 @@ impl Violation for MultipleWithStatements { } fn autofix_title_formatter(&self) -> Option String> { - let MultipleWithStatements { fixable, .. } = self; - if *fixable { - Some(|_| format!("Combine `with` statements")) - } else { - None - } + self.fixable + .then_some(|_| format!("Combine `with` statements")) } } diff --git a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs index ec4899635d..212796ee09 100644 --- a/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -26,7 +26,7 @@ impl Violation for LambdaAssignment { fn autofix_title_formatter(&self) -> Option String> { self.fixable - .then_some(|v| format!("Rewrite `{}` as a `def`", v.name)) + .then_some(|LambdaAssignment { name, .. }| format!("Rewrite `{name}` as a `def`")) } } diff --git a/crates/ruff/src/rules/pylint/rules/use_from_import.rs b/crates/ruff/src/rules/pylint/rules/use_from_import.rs index b131183a70..3798c024f4 100644 --- a/crates/ruff/src/rules/pylint/rules/use_from_import.rs +++ b/crates/ruff/src/rules/pylint/rules/use_from_import.rs @@ -25,14 +25,10 @@ impl Violation for ConsiderUsingFromImport { } fn autofix_title_formatter(&self) -> Option String> { - let ConsiderUsingFromImport { fixable, .. } = self; - if *fixable { - Some(|ConsiderUsingFromImport { module, name, .. }| { + self.fixable + .then_some(|ConsiderUsingFromImport { module, name, .. }| { format!("Replace with `from {module} import {name}`") }) - } else { - None - } } } diff --git a/crates/ruff/src/rules/pyupgrade/rules/import_replacements.rs b/crates/ruff/src/rules/pyupgrade/rules/import_replacements.rs index 77666760c9..4192a2b081 100644 --- a/crates/ruff/src/rules/pyupgrade/rules/import_replacements.rs +++ b/crates/ruff/src/rules/pyupgrade/rules/import_replacements.rs @@ -32,12 +32,8 @@ impl Violation for ImportReplacements { } fn autofix_title_formatter(&self) -> Option String> { - let ImportReplacements { fixable, .. } = self; - if *fixable { - Some(|ImportReplacements { module, .. }| format!("Import from `{module}`")) - } else { - None - } + self.fixable + .then_some(|ImportReplacements { module, .. }| format!("Import from `{module}`")) } } diff --git a/crates/ruff/src/rules/ruff/rules/unpack_instead_of_concatenating_to_collection_literal.rs b/crates/ruff/src/rules/ruff/rules/unpack_instead_of_concatenating_to_collection_literal.rs index 11e5604961..d7218c071a 100644 --- a/crates/ruff/src/rules/ruff/rules/unpack_instead_of_concatenating_to_collection_literal.rs +++ b/crates/ruff/src/rules/ruff/rules/unpack_instead_of_concatenating_to_collection_literal.rs @@ -24,16 +24,11 @@ impl Violation for UnpackInsteadOfConcatenatingToCollectionLiteral { } fn autofix_title_formatter(&self) -> Option String> { - let UnpackInsteadOfConcatenatingToCollectionLiteral { fixable, .. } = self; - if *fixable { - Some( - |UnpackInsteadOfConcatenatingToCollectionLiteral { expr, .. }| { - format!("Replace with `{expr}`") - }, - ) - } else { - None - } + self.fixable.then_some( + |UnpackInsteadOfConcatenatingToCollectionLiteral { expr, .. }| { + format!("Replace with `{expr}`") + }, + ) } }