Refactor: Remove StringPart and AnyStringPart in favor of StringLikePart (#13772)
This commit is contained in:
@@ -3,13 +3,13 @@ use std::cmp::Ordering;
|
||||
use std::iter::FusedIterator;
|
||||
|
||||
use ruff_formatter::FormatContext;
|
||||
use ruff_python_ast::{str::Quote, AnyStringFlags, StringFlags};
|
||||
use ruff_python_ast::{str::Quote, AnyStringFlags, StringFlags, StringLikePart};
|
||||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::context::FStringState;
|
||||
use crate::prelude::*;
|
||||
use crate::preview::is_f_string_formatting_enabled;
|
||||
use crate::string::{Quoting, StringPart, StringQuotes};
|
||||
use crate::string::{Quoting, StringQuotes};
|
||||
use crate::QuoteStyle;
|
||||
|
||||
pub(crate) struct StringNormalizer<'a, 'src> {
|
||||
@@ -37,7 +37,7 @@ impl<'a, 'src> StringNormalizer<'a, 'src> {
|
||||
self
|
||||
}
|
||||
|
||||
fn quoting(&self, string: StringPart) -> Quoting {
|
||||
fn quoting(&self, string: StringLikePart) -> Quoting {
|
||||
if let FStringState::InsideExpressionElement(context) = self.context.f_string_state() {
|
||||
// If we're inside an f-string, we need to make sure to preserve the
|
||||
// existing quotes unless we're inside a triple-quoted f-string and
|
||||
@@ -66,7 +66,7 @@ impl<'a, 'src> StringNormalizer<'a, 'src> {
|
||||
}
|
||||
|
||||
/// Computes the strings preferred quotes.
|
||||
pub(crate) fn choose_quotes(&self, string: StringPart) -> QuoteSelection {
|
||||
pub(crate) fn choose_quotes(&self, string: StringLikePart) -> QuoteSelection {
|
||||
let raw_content = self.context.locator().slice(string.content_range());
|
||||
let first_quote_or_normalized_char_offset = raw_content
|
||||
.bytes()
|
||||
@@ -168,7 +168,7 @@ impl<'a, 'src> StringNormalizer<'a, 'src> {
|
||||
}
|
||||
|
||||
/// Computes the strings preferred quotes and normalizes its content.
|
||||
pub(crate) fn normalize(&self, string: StringPart) -> NormalizedString<'src> {
|
||||
pub(crate) fn normalize(&self, string: StringLikePart) -> NormalizedString<'src> {
|
||||
let raw_content = self.context.locator().slice(string.content_range());
|
||||
let quote_selection = self.choose_quotes(string);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user