mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-05 16:11:15 +00:00
parent
a95deec00f
commit
424b720c19
62 changed files with 1799 additions and 3890 deletions
|
@ -2,8 +2,7 @@ use ruff_formatter::FormatRuleWithOptions;
|
|||
use ruff_python_ast::StringLiteral;
|
||||
|
||||
use crate::prelude::*;
|
||||
use crate::preview::is_f_string_implicit_concatenated_string_literal_quotes_enabled;
|
||||
use crate::string::{docstring, Quoting, StringNormalizer};
|
||||
use crate::string::{docstring, StringNormalizer};
|
||||
use crate::QuoteStyle;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -28,12 +27,6 @@ pub enum StringLiteralKind {
|
|||
String,
|
||||
/// A string literal used as a docstring.
|
||||
Docstring,
|
||||
/// A string literal that is implicitly concatenated with an f-string. This
|
||||
/// makes the overall expression an f-string whose quoting detection comes
|
||||
/// from the parent node (f-string expression).
|
||||
#[deprecated]
|
||||
#[allow(private_interfaces)]
|
||||
InImplicitlyConcatenatedFString(Quoting),
|
||||
}
|
||||
|
||||
impl StringLiteralKind {
|
||||
|
@ -41,26 +34,6 @@ impl StringLiteralKind {
|
|||
pub(crate) const fn is_docstring(self) -> bool {
|
||||
matches!(self, StringLiteralKind::Docstring)
|
||||
}
|
||||
|
||||
/// Returns the quoting to be used for this string literal.
|
||||
fn quoting(self, context: &PyFormatContext) -> Quoting {
|
||||
match self {
|
||||
StringLiteralKind::String | StringLiteralKind::Docstring => Quoting::CanChange,
|
||||
#[allow(deprecated)]
|
||||
StringLiteralKind::InImplicitlyConcatenatedFString(quoting) => {
|
||||
// Allow string literals to pick the "optimal" quote character
|
||||
// even if any other fstring in the implicit concatenation uses an expression
|
||||
// containing a quote character.
|
||||
// TODO: Remove StringLiteralKind::InImplicitlyConcatenatedFString when promoting
|
||||
// this style to stable and remove the layout from `AnyStringPart::String`.
|
||||
if is_f_string_implicit_concatenated_string_literal_quotes_enabled(context) {
|
||||
Quoting::CanChange
|
||||
} else {
|
||||
quoting
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatNodeRule<StringLiteral> for FormatStringLiteral {
|
||||
|
@ -75,7 +48,6 @@ impl FormatNodeRule<StringLiteral> for FormatStringLiteral {
|
|||
};
|
||||
|
||||
let normalized = StringNormalizer::from_context(f.context())
|
||||
.with_quoting(self.layout.quoting(f.context()))
|
||||
.with_preferred_quote_style(quote_style)
|
||||
.normalize(item.into());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue