Update documentation to list double-quote preference first (#5507)

Closes https://github.com/astral-sh/ruff/issues/5496.
This commit is contained in:
Charlie Marsh 2023-07-04 14:06:01 -04:00 committed by GitHub
parent 521e6de2c8
commit 75da72bd7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -42,16 +42,16 @@ impl AlwaysAutofixableViolation for BadQuotesInlineString {
fn message(&self) -> String { fn message(&self) -> String {
let BadQuotesInlineString { quote } = self; let BadQuotesInlineString { quote } = self;
match quote { match quote {
Quote::Single => format!("Double quotes found but single quotes preferred"),
Quote::Double => format!("Single quotes found but double quotes preferred"), Quote::Double => format!("Single quotes found but double quotes preferred"),
Quote::Single => format!("Double quotes found but single quotes preferred"),
} }
} }
fn autofix_title(&self) -> String { fn autofix_title(&self) -> String {
let BadQuotesInlineString { quote } = self; let BadQuotesInlineString { quote } = self;
match quote { match quote {
Quote::Single => "Replace double quotes with single quotes".to_string(),
Quote::Double => "Replace single quotes with double quotes".to_string(), Quote::Double => "Replace single quotes with double quotes".to_string(),
Quote::Single => "Replace double quotes with single quotes".to_string(),
} }
} }
} }
@ -91,16 +91,16 @@ impl AlwaysAutofixableViolation for BadQuotesMultilineString {
fn message(&self) -> String { fn message(&self) -> String {
let BadQuotesMultilineString { quote } = self; let BadQuotesMultilineString { quote } = self;
match quote { match quote {
Quote::Single => format!("Double quote multiline found but single quotes preferred"),
Quote::Double => format!("Single quote multiline found but double quotes preferred"), Quote::Double => format!("Single quote multiline found but double quotes preferred"),
Quote::Single => format!("Double quote multiline found but single quotes preferred"),
} }
} }
fn autofix_title(&self) -> String { fn autofix_title(&self) -> String {
let BadQuotesMultilineString { quote } = self; let BadQuotesMultilineString { quote } = self;
match quote { match quote {
Quote::Single => "Replace double multiline quotes with single quotes".to_string(),
Quote::Double => "Replace single multiline quotes with double quotes".to_string(), Quote::Double => "Replace single multiline quotes with double quotes".to_string(),
Quote::Single => "Replace double multiline quotes with single quotes".to_string(),
} }
} }
} }
@ -139,16 +139,16 @@ impl AlwaysAutofixableViolation for BadQuotesDocstring {
fn message(&self) -> String { fn message(&self) -> String {
let BadQuotesDocstring { quote } = self; let BadQuotesDocstring { quote } = self;
match quote { match quote {
Quote::Single => format!("Double quote docstring found but single quotes preferred"),
Quote::Double => format!("Single quote docstring found but double quotes preferred"), Quote::Double => format!("Single quote docstring found but double quotes preferred"),
Quote::Single => format!("Double quote docstring found but single quotes preferred"),
} }
} }
fn autofix_title(&self) -> String { fn autofix_title(&self) -> String {
let BadQuotesDocstring { quote } = self; let BadQuotesDocstring { quote } = self;
match quote { match quote {
Quote::Single => "Replace double quotes docstring with single quotes".to_string(),
Quote::Double => "Replace single quotes docstring with double quotes".to_string(), Quote::Double => "Replace single quotes docstring with double quotes".to_string(),
Quote::Single => "Replace double quotes docstring with single quotes".to_string(),
} }
} }
} }
@ -186,8 +186,8 @@ impl AlwaysAutofixableViolation for AvoidableEscapedQuote {
const fn good_single(quote: Quote) -> char { const fn good_single(quote: Quote) -> char {
match quote { match quote {
Quote::Single => '\'',
Quote::Double => '"', Quote::Double => '"',
Quote::Single => '\'',
} }
} }
@ -200,22 +200,22 @@ const fn bad_single(quote: Quote) -> char {
const fn good_multiline(quote: Quote) -> &'static str { const fn good_multiline(quote: Quote) -> &'static str {
match quote { match quote {
Quote::Single => "'''",
Quote::Double => "\"\"\"", Quote::Double => "\"\"\"",
Quote::Single => "'''",
} }
} }
const fn good_multiline_ending(quote: Quote) -> &'static str { const fn good_multiline_ending(quote: Quote) -> &'static str {
match quote { match quote {
Quote::Single => "'\"\"\"",
Quote::Double => "\"'''", Quote::Double => "\"'''",
Quote::Single => "'\"\"\"",
} }
} }
const fn good_docstring(quote: Quote) -> &'static str { const fn good_docstring(quote: Quote) -> &'static str {
match quote { match quote {
Quote::Single => "'",
Quote::Double => "\"", Quote::Double => "\"",
Quote::Single => "'",
} }
} }

View File

@ -8,10 +8,10 @@ use ruff_macros::{CacheKey, CombineOptions, ConfigurationOptions};
#[serde(deny_unknown_fields, rename_all = "kebab-case")] #[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum Quote { pub enum Quote {
/// Use single quotes.
Single,
/// Use double quotes. /// Use double quotes.
Double, Double,
/// Use single quotes.
Single,
} }
impl Default for Quote { impl Default for Quote {

14
ruff.schema.json generated
View File

@ -1585,19 +1585,19 @@
}, },
"Quote": { "Quote": {
"oneOf": [ "oneOf": [
{
"description": "Use single quotes.",
"type": "string",
"enum": [
"single"
]
},
{ {
"description": "Use double quotes.", "description": "Use double quotes.",
"type": "string", "type": "string",
"enum": [ "enum": [
"double" "double"
] ]
},
{
"description": "Use single quotes.",
"type": "string",
"enum": [
"single"
]
} }
] ]
}, },