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

Replace format! without parameters with .to_string() #14090

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Violation for CommentedOutCode {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Remove commented-out code"))
Some("Remove commented-out code".to_string())
}
}

Expand Down
55 changes: 25 additions & 30 deletions crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,11 @@ impl Violation for MissingReturnTypeUndocumentedPublicFunction {
}

fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return type annotation"))
}
let title = match &self.annotation {
Some(annotation) => format!("Add return type annotation: `{annotation}`"),
None => "Add return type annotation".to_string(),
};
Some(title)
}
}

Expand Down Expand Up @@ -273,12 +272,11 @@ impl Violation for MissingReturnTypePrivateFunction {
}

fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return type annotation"))
}
let title = match &self.annotation {
Some(annotation) => format!("Add return type annotation: `{annotation}`"),
None => "Add return type annotation".to_string(),
};
Some(title)
}
}

Expand Down Expand Up @@ -330,12 +328,11 @@ impl Violation for MissingReturnTypeSpecialMethod {
}

fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return type annotation"))
}
let title = match &self.annotation {
Some(annotation) => format!("Add return type annotation: `{annotation}`"),
None => "Add return type annotation".to_string(),
};
Some(title)
}
}

Expand Down Expand Up @@ -378,12 +375,11 @@ impl Violation for MissingReturnTypeStaticMethod {
}

fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return type annotation"))
}
let title = match &self.annotation {
Some(annotation) => format!("Add return type annotation: `{annotation}`"),
None => "Add return type annotation".to_string(),
};
Some(title)
}
}

Expand Down Expand Up @@ -426,12 +422,11 @@ impl Violation for MissingReturnTypeClassMethod {
}

fn fix_title(&self) -> Option<String> {
let Self { annotation, .. } = self;
if let Some(annotation) = annotation {
Some(format!("Add return type annotation: `{annotation}`"))
} else {
Some(format!("Add return type annotation"))
}
let title = match &self.annotation {
Some(annotation) => format!("Add return type annotation: `{annotation}`"),
None => "Add return type annotation".to_string(),
};
Some(title)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Violation for TrioSyncCall {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Add `await`"))
Some("Add `await`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Violation for DuplicateValue {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Remove duplicate item"))
Some("Remove duplicate item".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Violation for MutableArgumentDefault {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace with `None`; initialize within function"))
Some("Replace with `None`; initialize within function".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Violation for UnreliableCallableCheck {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace with `callable()`"))
Some("Replace with `callable()`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ impl Violation for UnnecessaryDictComprehensionForIterable {
}

fn fix_title(&self) -> Option<String> {
if self.is_value_none_literal {
Some(format!("Replace with `dict.fromkeys(iterable, value)`)"))
let title = if self.is_value_none_literal {
"Replace with `dict.fromkeys(iterable, value)`)"
} else {
Some(format!("Replace with `dict.fromkeys(iterable)`)"))
}
"Replace with `dict.fromkeys(iterable)`)"
};
Some(title.to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl AlwaysFixableViolation for ShebangLeadingWhitespace {
}

fn fix_title(&self) -> String {
format!("Remove whitespace before shebang")
"Remove whitespace before shebang".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl AlwaysFixableViolation for FutureRequiredTypeAnnotation {
}

fn fix_title(&self) -> String {
format!("Add `from __future__ import annotations`")
"Add `from __future__ import annotations`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Violation for DirectLoggerInstantiation {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace with `logging.getLogger()`"))
Some("Replace with `logging.getLogger()`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Violation for InvalidGetLoggerArgument {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace with `__name__`"))
Some("Replace with `__name__`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Violation for UndocumentedWarn {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace `logging.WARN` with `logging.WARNING`"))
Some("Replace `logging.WARN` with `logging.WARNING`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Violation for UnnecessaryDictKwargs {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Remove unnecessary kwargs"))
Some("Remove unnecessary kwargs".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,18 @@ pub struct UnnecessaryPlaceholder {
impl AlwaysFixableViolation for UnnecessaryPlaceholder {
#[derive_message_formats]
fn message(&self) -> String {
let Self { kind } = self;
match kind {
match &self.kind {
Placeholder::Pass => format!("Unnecessary `pass` statement"),
Placeholder::Ellipsis => format!("Unnecessary `...` literal"),
}
}

fn fix_title(&self) -> String {
let Self { kind } = self;
match kind {
Placeholder::Pass => format!("Remove unnecessary `pass`"),
Placeholder::Ellipsis => format!("Remove unnecessary `...`"),
}
let title = match &self.kind {
Placeholder::Pass => "Remove unnecessary `pass`",
Placeholder::Ellipsis => "Remove unnecessary `...`",
};
title.to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl AlwaysFixableViolation for UnnecessaryRangeStart {
}

fn fix_title(&self) -> String {
format!("Remove `start` argument")
"Remove `start` argument".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Violation for UnnecessarySpread {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Remove unnecessary dict"))
Some("Remove unnecessary dict".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl AlwaysFixableViolation for AnyEqNeAnnotation {
}

fn fix_title(&self) -> String {
format!("Replace with `object`")
"Replace with `object`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Violation for CollectionsNamedTuple {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Replace with `typing.NamedTuple`"))
Some("Replace with `typing.NamedTuple`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl AlwaysFixableViolation for NonEmptyStubBody {
}

fn fix_title(&self) -> String {
format!("Replace function body with `...`")
"Replace function body with `...`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl AlwaysFixableViolation for PassInClassBody {
}

fn fix_title(&self) -> String {
format!("Remove unnecessary `pass`")
"Remove unnecessary `pass`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AlwaysFixableViolation for PassStatementStubBody {
}

fn fix_title(&self) -> String {
format!("Replace `pass` with `...`")
"Replace `pass` with `...`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Violation for UnaliasedCollectionsAbcSetImport {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Alias `Set` to `AbstractSet`"))
Some("Alias `Set` to `AbstractSet`".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Violation for UnnecessaryTypeUnion {
}

fn fix_title(&self) -> Option<String> {
Some(format!("Combine multiple `type` members"))
Some("Combine multiple `type` members".to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException {
}

fn fix_title(&self) -> String {
format!("Remove unnecessary parentheses")
"Remove unnecessary parentheses".to_string()
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ impl Violation for IfExprWithTrueFalse {
}

fn fix_title(&self) -> Option<String> {
let IfExprWithTrueFalse { is_compare } = self;
if *is_compare {
Some(format!("Remove unnecessary `True if ... else False`"))
let title = if self.is_compare {
"Remove unnecessary `True if ... else False`"
} else {
Some(format!("Replace with `bool(...)"))
}
"Replace with `bool(...)"
};
Some(title.to_string())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl AlwaysFixableViolation for InDictKeys {
}

fn fix_title(&self) -> String {
let InDictKeys { operator: _ } = self;
format!("Remove `.keys()`")
"Remove `.keys()`".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Violation for NeedlessBool {
if let Some(condition) = condition.as_ref().and_then(SourceCodeSnippet::full_display) {
Some(format!("Replace with `return {condition}`"))
} else {
Some(format!("Inline condition"))
Some("Inline condition".to_string())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl AlwaysFixableViolation for EmptyTypeCheckingBlock {
}

fn fix_title(&self) -> String {
format!("Delete empty type-checking block")
"Delete empty type-checking block".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl AlwaysFixableViolation for StaticJoinToFString {
if let Some(expression) = expression.full_display() {
format!("Replace with `{expression}`")
} else {
format!("Replace with f-string")
"Replace with f-string".to_string()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl AlwaysFixableViolation for UnnecessaryListCast {
}

fn fix_title(&self) -> String {
format!("Remove `list()` cast")
"Remove `list()` cast".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl AlwaysFixableViolation for InvalidEscapeSequence {

fn fix_title(&self) -> String {
match self.fix_title {
FixTitle::AddBackslash => format!("Add backslash to escape sequence"),
FixTitle::UseRawStringLiteral => format!("Use a raw string literal"),
FixTitle::AddBackslash => "Add backslash to escape sequence".to_string(),
FixTitle::UseRawStringLiteral => "Use a raw string literal".to_string(),
}
}
}
Expand Down
Loading
Loading