mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Derive message formats macro support to string (#14093)
This commit is contained in:
parent
bc0586d922
commit
fb94b71e63
382 changed files with 843 additions and 854 deletions
|
@ -49,7 +49,7 @@ impl Violation for EscapeSequenceInDocstring {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!(r#"Use `r"""` if any backslashes in a docstring"#)
|
||||
r#"Use `r"""` if any backslashes in a docstring"#.to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
|
@ -52,7 +52,7 @@ impl Violation for BlankLineAfterSummary {
|
|||
fn message(&self) -> String {
|
||||
let BlankLineAfterSummary { num_lines } = self;
|
||||
if *num_lines == 0 {
|
||||
format!("1 blank line required between summary line and description")
|
||||
"1 blank line required between summary line and description".to_string()
|
||||
} else {
|
||||
format!(
|
||||
"1 blank line required between summary line and description (found {num_lines})"
|
||||
|
|
|
@ -48,7 +48,7 @@ pub struct OneBlankLineBeforeClass;
|
|||
impl AlwaysFixableViolation for OneBlankLineBeforeClass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("1 blank line required before class docstring")
|
||||
"1 blank line required before class docstring".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
@ -100,7 +100,7 @@ pub struct OneBlankLineAfterClass;
|
|||
impl AlwaysFixableViolation for OneBlankLineAfterClass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("1 blank line required after class docstring")
|
||||
"1 blank line required after class docstring".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
@ -147,7 +147,7 @@ pub struct BlankLineBeforeClass;
|
|||
impl AlwaysFixableViolation for BlankLineBeforeClass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("No blank lines allowed before class docstring")
|
||||
"No blank lines allowed before class docstring".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Violation for EndsInPeriod {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("First line should end with a period")
|
||||
"First line should end with a period".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
|
@ -53,7 +53,7 @@ impl Violation for EndsInPunctuation {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("First line should end with a period, question mark, or exclamation point")
|
||||
"First line should end with a period, question mark, or exclamation point".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
|
@ -72,7 +72,7 @@ pub struct OverloadWithDocstring;
|
|||
impl Violation for OverloadWithDocstring {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Function decorated with `@overload` shouldn't contain a docstring")
|
||||
"Function decorated with `@overload` shouldn't contain a docstring".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ pub struct IndentWithSpaces;
|
|||
impl Violation for IndentWithSpaces {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Docstring should be indented with spaces, not tabs")
|
||||
"Docstring should be indented with spaces, not tabs".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub struct UnderIndentation;
|
|||
impl AlwaysFixableViolation for UnderIndentation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Docstring is under-indented")
|
||||
"Docstring is under-indented".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
@ -156,7 +156,7 @@ pub struct OverIndentation;
|
|||
impl AlwaysFixableViolation for OverIndentation {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Docstring is over-indented")
|
||||
"Docstring is over-indented".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
|
|
@ -64,7 +64,7 @@ pub struct MultiLineSummaryFirstLine;
|
|||
impl AlwaysFixableViolation for MultiLineSummaryFirstLine {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Multi-line docstring summary should start at the first line")
|
||||
"Multi-line docstring summary should start at the first line".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
@ -127,7 +127,7 @@ pub struct MultiLineSummarySecondLine;
|
|||
impl AlwaysFixableViolation for MultiLineSummarySecondLine {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Multi-line docstring summary should start at the second line")
|
||||
"Multi-line docstring summary should start at the second line".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
|
|
@ -49,7 +49,7 @@ pub struct NewLineAfterLastParagraph;
|
|||
impl AlwaysFixableViolation for NewLineAfterLastParagraph {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Multi-line docstring closing quotes should be on a separate line")
|
||||
"Multi-line docstring closing quotes should be on a separate line".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> String {
|
||||
|
|
|
@ -46,7 +46,7 @@ pub struct NoSignature;
|
|||
impl Violation for NoSignature {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("First line should not be the function's signature")
|
||||
"First line should not be the function's signature".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ impl Violation for SurroundingWhitespace {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("No whitespaces allowed surrounding docstring text")
|
||||
"No whitespaces allowed surrounding docstring text".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
|
@ -35,7 +35,7 @@ pub struct EmptyDocstring;
|
|||
impl Violation for EmptyDocstring {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Docstring is empty")
|
||||
"Docstring is empty".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ pub struct UndocumentedPublicModule;
|
|||
impl Violation for UndocumentedPublicModule {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public module")
|
||||
"Missing docstring in public module".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ pub struct UndocumentedPublicClass;
|
|||
impl Violation for UndocumentedPublicClass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public class")
|
||||
"Missing docstring in public class".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ pub struct UndocumentedPublicMethod;
|
|||
impl Violation for UndocumentedPublicMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public method")
|
||||
"Missing docstring in public method".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ pub struct UndocumentedPublicFunction;
|
|||
impl Violation for UndocumentedPublicFunction {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public function")
|
||||
"Missing docstring in public function".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ pub struct UndocumentedPublicPackage;
|
|||
impl Violation for UndocumentedPublicPackage {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public package")
|
||||
"Missing docstring in public package".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ pub struct UndocumentedMagicMethod;
|
|||
impl Violation for UndocumentedMagicMethod {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in magic method")
|
||||
"Missing docstring in magic method".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ pub struct UndocumentedPublicNestedClass;
|
|||
impl Violation for UndocumentedPublicNestedClass {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in public nested class")
|
||||
"Missing docstring in public nested class".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,7 @@ pub struct UndocumentedPublicInit;
|
|||
impl Violation for UndocumentedPublicInit {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("Missing docstring in `__init__`")
|
||||
"Missing docstring in `__init__`".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Violation for FitsOnOneLine {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!("One-line docstring should fit on one line")
|
||||
"One-line docstring should fit on one line".to_string()
|
||||
}
|
||||
|
||||
fn fix_title(&self) -> Option<String> {
|
||||
|
|
|
@ -45,7 +45,7 @@ pub struct DocstringStartsWithThis;
|
|||
impl Violation for DocstringStartsWithThis {
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
format!(r#"First word of the docstring should not be "This""#)
|
||||
r#"First word of the docstring should not be "This""#.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,10 +47,9 @@ impl Violation for TripleSingleQuotes {
|
|||
|
||||
#[derive_message_formats]
|
||||
fn message(&self) -> String {
|
||||
let TripleSingleQuotes { expected_quote } = self;
|
||||
match expected_quote {
|
||||
Quote::Double => format!(r#"Use triple double quotes `"""`"#),
|
||||
Quote::Single => format!(r"Use triple single quotes `'''`"),
|
||||
match self.expected_quote {
|
||||
Quote::Double => r#"Use triple double quotes `"""`"#.to_string(),
|
||||
Quote::Single => r"Use triple single quotes `'''`".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue