mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 16:40:19 +00:00
Introduce Token element (#7048)
This commit is contained in:
parent
2f3a950f6f
commit
c05e4628b1
78 changed files with 733 additions and 723 deletions
|
@ -326,7 +326,7 @@ impl Format<PyFormatContext<'_>> for FormatStringPart {
|
|||
source_text_slice(self.range(), contains_newlines).fmt(f)?;
|
||||
}
|
||||
Cow::Owned(normalized) => {
|
||||
dynamic_text(&normalized, Some(self.start())).fmt(f)?;
|
||||
text(&normalized, Some(self.start())).fmt(f)?;
|
||||
}
|
||||
}
|
||||
self.preferred_quotes.fmt(f)
|
||||
|
@ -386,17 +386,17 @@ impl Format<PyFormatContext<'_>> for StringPrefix {
|
|||
// Retain the casing for the raw prefix:
|
||||
// https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#r-strings-and-r-strings
|
||||
if self.contains(StringPrefix::RAW) {
|
||||
text("r").fmt(f)?;
|
||||
token("r").fmt(f)?;
|
||||
} else if self.contains(StringPrefix::RAW_UPPER) {
|
||||
text("R").fmt(f)?;
|
||||
token("R").fmt(f)?;
|
||||
}
|
||||
|
||||
if self.contains(StringPrefix::BYTE) {
|
||||
text("b").fmt(f)?;
|
||||
token("b").fmt(f)?;
|
||||
}
|
||||
|
||||
if self.contains(StringPrefix::F_STRING) {
|
||||
text("f").fmt(f)?;
|
||||
token("f").fmt(f)?;
|
||||
}
|
||||
|
||||
// Remove the unicode prefix `u` if any because it is meaningless in Python 3+.
|
||||
|
@ -596,7 +596,7 @@ impl Format<PyFormatContext<'_>> for StringQuotes {
|
|||
(QuoteStyle::Double, true) => "\"\"\"",
|
||||
};
|
||||
|
||||
text(quotes).fmt(f)
|
||||
token(quotes).fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -839,7 +839,7 @@ fn format_docstring(string_part: &FormatStringPart, f: &mut PyFormatter) -> Form
|
|||
if already_normalized {
|
||||
source_text_slice(trimmed_line_range, ContainsNewlines::No).fmt(f)?;
|
||||
} else {
|
||||
dynamic_text(trim_both, Some(trimmed_line_range.start())).fmt(f)?;
|
||||
text(trim_both, Some(trimmed_line_range.start())).fmt(f)?;
|
||||
}
|
||||
}
|
||||
offset += first.text_len();
|
||||
|
@ -947,7 +947,7 @@ fn format_docstring_line(
|
|||
let indent_len =
|
||||
count_indentation_like_black(trim_end, f.options().tab_width()) - stripped_indentation;
|
||||
let in_docstring_indent = " ".repeat(indent_len.to_usize()) + trim_end.trim_start();
|
||||
dynamic_text(&in_docstring_indent, Some(offset)).fmt(f)?;
|
||||
text(&in_docstring_indent, Some(offset)).fmt(f)?;
|
||||
} else {
|
||||
// Take the string with the trailing whitespace removed, then also skip the leading
|
||||
// whitespace
|
||||
|
@ -957,7 +957,7 @@ fn format_docstring_line(
|
|||
source_text_slice(trimmed_line_range, ContainsNewlines::No).fmt(f)?;
|
||||
} else {
|
||||
// All indents are ascii spaces, so the slicing is correct
|
||||
dynamic_text(
|
||||
text(
|
||||
&trim_end[stripped_indentation.to_usize()..],
|
||||
Some(trimmed_line_range.start()),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue