mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
Upgrade to Rust 1.78 (#11260)
This commit is contained in:
parent
349a4cf8ce
commit
6a1e555537
69 changed files with 67 additions and 549 deletions
|
@ -3,5 +3,10 @@ doc-valid-idents = [
|
||||||
"CodeQL",
|
"CodeQL",
|
||||||
"IPython",
|
"IPython",
|
||||||
"NumPy",
|
"NumPy",
|
||||||
|
"LibCST",
|
||||||
|
"SCREAMING_SNAKE_CASE",
|
||||||
|
"SQLAlchemy",
|
||||||
|
"McCabe",
|
||||||
|
"FastAPI",
|
||||||
"..",
|
"..",
|
||||||
]
|
]
|
||||||
|
|
|
@ -338,7 +338,7 @@ pub struct CheckCommand {
|
||||||
/// The name of the file when passing it through stdin.
|
/// The name of the file when passing it through stdin.
|
||||||
#[arg(long, help_heading = "Miscellaneous")]
|
#[arg(long, help_heading = "Miscellaneous")]
|
||||||
pub stdin_filename: Option<PathBuf>,
|
pub stdin_filename: Option<PathBuf>,
|
||||||
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
|
/// List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For
|
||||||
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
|
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub extension: Option<Vec<ExtensionPair>>,
|
pub extension: Option<Vec<ExtensionPair>>,
|
||||||
|
@ -466,7 +466,7 @@ pub struct FormatCommand {
|
||||||
/// The name of the file when passing it through stdin.
|
/// The name of the file when passing it through stdin.
|
||||||
#[arg(long, help_heading = "Miscellaneous")]
|
#[arg(long, help_heading = "Miscellaneous")]
|
||||||
pub stdin_filename: Option<PathBuf>,
|
pub stdin_filename: Option<PathBuf>,
|
||||||
/// List of mappings from file extension to language (one of ["python", "ipynb", "pyi"]). For
|
/// List of mappings from file extension to language (one of `python`, `ipynb`, `pyi`). For
|
||||||
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
|
/// example, to treat `.ipy` files as IPython notebooks, use `--extension ipy:ipynb`.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub extension: Option<Vec<ExtensionPair>>,
|
pub extension: Option<Vec<ExtensionPair>>,
|
||||||
|
|
|
@ -344,7 +344,7 @@ pub struct RemoveSoftLinesBuffer<'a, Context> {
|
||||||
|
|
||||||
/// Caches the interned elements after the soft line breaks have been removed.
|
/// Caches the interned elements after the soft line breaks have been removed.
|
||||||
///
|
///
|
||||||
/// The `key` is the [Interned] element as it has been passed to [Self::write_element] or the child of another
|
/// The `key` is the [Interned] element as it has been passed to [`Self::write_element`] or the child of another
|
||||||
/// [Interned] element. The `value` is the matching document of the key where all soft line breaks have been removed.
|
/// [Interned] element. The `value` is the matching document of the key where all soft line breaks have been removed.
|
||||||
///
|
///
|
||||||
/// It's fine to not snapshot the cache. The worst that can happen is that it holds on interned elements
|
/// It's fine to not snapshot the cache. The worst that can happen is that it holds on interned elements
|
||||||
|
|
|
@ -18,10 +18,10 @@ pub enum FormatError {
|
||||||
InvalidDocument(InvalidDocumentError),
|
InvalidDocument(InvalidDocumentError),
|
||||||
|
|
||||||
/// Formatting failed because some content encountered a situation where a layout
|
/// Formatting failed because some content encountered a situation where a layout
|
||||||
/// choice by an enclosing [crate::Format] resulted in a poor layout for a child [crate::Format].
|
/// choice by an enclosing [`crate::Format`] resulted in a poor layout for a child [`crate::Format`].
|
||||||
///
|
///
|
||||||
/// It's up to an enclosing [crate::Format] to handle the error and pick another layout.
|
/// It's up to an enclosing [`crate::Format`] to handle the error and pick another layout.
|
||||||
/// This error should not be raised if there's no outer [crate::Format] handling the poor layout error,
|
/// This error should not be raised if there's no outer [`crate::Format`] handling the poor layout error,
|
||||||
/// avoiding that formatting of the whole document fails.
|
/// avoiding that formatting of the whole document fails.
|
||||||
PoorLayout,
|
PoorLayout,
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,10 @@ use ruff_text_size::TextSize;
|
||||||
/// Use the helper functions like [`crate::builders::space`], [`crate::builders::soft_line_break`] etc. defined in this file to create elements.
|
/// Use the helper functions like [`crate::builders::space`], [`crate::builders::soft_line_break`] etc. defined in this file to create elements.
|
||||||
#[derive(Clone, Eq, PartialEq)]
|
#[derive(Clone, Eq, PartialEq)]
|
||||||
pub enum FormatElement {
|
pub enum FormatElement {
|
||||||
/// A space token, see [crate::builders::space] for documentation.
|
/// A space token, see [`crate::builders::space`] for documentation.
|
||||||
Space,
|
Space,
|
||||||
|
|
||||||
/// A new line, see [crate::builders::soft_line_break], [crate::builders::hard_line_break], and [crate::builders::soft_line_break_or_space] for documentation.
|
/// A new line, see [`crate::builders::soft_line_break`], [`crate::builders::hard_line_break`], and [`crate::builders::soft_line_break_or_space`] for documentation.
|
||||||
Line(LineMode),
|
Line(LineMode),
|
||||||
|
|
||||||
/// Forces the parent group to print in expanded mode.
|
/// Forces the parent group to print in expanded mode.
|
||||||
|
@ -108,13 +108,13 @@ impl std::fmt::Debug for FormatElement {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||||
pub enum LineMode {
|
pub enum LineMode {
|
||||||
/// See [crate::builders::soft_line_break_or_space] for documentation.
|
/// See [`crate::builders::soft_line_break_or_space`] for documentation.
|
||||||
SoftOrSpace,
|
SoftOrSpace,
|
||||||
/// See [crate::builders::soft_line_break] for documentation.
|
/// See [`crate::builders::soft_line_break`] for documentation.
|
||||||
Soft,
|
Soft,
|
||||||
/// See [crate::builders::hard_line_break] for documentation.
|
/// See [`crate::builders::hard_line_break`] for documentation.
|
||||||
Hard,
|
Hard,
|
||||||
/// See [crate::builders::empty_line] for documentation.
|
/// See [`crate::builders::empty_line`] for documentation.
|
||||||
Empty,
|
Empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,14 @@ use std::num::NonZeroU8;
|
||||||
/// will be applied to all elements in between the start/end tags.
|
/// will be applied to all elements in between the start/end tags.
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum Tag {
|
pub enum Tag {
|
||||||
/// Indents the content one level deeper, see [crate::builders::indent] for documentation and examples.
|
/// Indents the content one level deeper, see [`crate::builders::indent`] for documentation and examples.
|
||||||
StartIndent,
|
StartIndent,
|
||||||
EndIndent,
|
EndIndent,
|
||||||
|
|
||||||
/// Variant of [TagKind::Indent] that indents content by a number of spaces. For example, `Align(2)`
|
/// Variant of [`TagKind::Indent`] that indents content by a number of spaces. For example, `Align(2)`
|
||||||
/// indents any content following a line break by an additional two spaces.
|
/// indents any content following a line break by an additional two spaces.
|
||||||
///
|
///
|
||||||
/// Nesting (Aligns)[TagKind::Align] has the effect that all except the most inner align are handled as (Indent)[TagKind::Indent].
|
/// Nesting (Aligns)[`TagKind::Align`] has the effect that all except the most inner align are handled as (Indent)[`TagKind::Indent`].
|
||||||
StartAlign(Align),
|
StartAlign(Align),
|
||||||
EndAlign,
|
EndAlign,
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ pub enum Tag {
|
||||||
/// - on a single line: Omitting `LineMode::Soft` line breaks and printing spaces for `LineMode::SoftOrSpace`
|
/// - on a single line: Omitting `LineMode::Soft` line breaks and printing spaces for `LineMode::SoftOrSpace`
|
||||||
/// - on multiple lines: Printing all line breaks
|
/// - on multiple lines: Printing all line breaks
|
||||||
///
|
///
|
||||||
/// See [crate::builders::group] for documentation and examples.
|
/// See [`crate::builders::group`] for documentation and examples.
|
||||||
StartGroup(Group),
|
StartGroup(Group),
|
||||||
EndGroup,
|
EndGroup,
|
||||||
|
|
||||||
|
@ -44,22 +44,22 @@ pub enum Tag {
|
||||||
EndConditionalGroup,
|
EndConditionalGroup,
|
||||||
|
|
||||||
/// Allows to specify content that gets printed depending on whatever the enclosing group
|
/// Allows to specify content that gets printed depending on whatever the enclosing group
|
||||||
/// is printed on a single line or multiple lines. See [crate::builders::if_group_breaks] for examples.
|
/// is printed on a single line or multiple lines. See [`crate::builders::if_group_breaks`] for examples.
|
||||||
StartConditionalContent(Condition),
|
StartConditionalContent(Condition),
|
||||||
EndConditionalContent,
|
EndConditionalContent,
|
||||||
|
|
||||||
/// Optimized version of [Tag::StartConditionalContent] for the case where some content
|
/// Optimized version of [`Tag::StartConditionalContent`] for the case where some content
|
||||||
/// should be indented if the specified group breaks.
|
/// should be indented if the specified group breaks.
|
||||||
StartIndentIfGroupBreaks(GroupId),
|
StartIndentIfGroupBreaks(GroupId),
|
||||||
EndIndentIfGroupBreaks,
|
EndIndentIfGroupBreaks,
|
||||||
|
|
||||||
/// Concatenates multiple elements together with a given separator printed in either
|
/// Concatenates multiple elements together with a given separator printed in either
|
||||||
/// flat or expanded mode to fill the print width. Expect that the content is a list of alternating
|
/// flat or expanded mode to fill the print width. Expect that the content is a list of alternating
|
||||||
/// [element, separator] See [crate::Formatter::fill].
|
/// [element, separator] See [`crate::Formatter::fill`].
|
||||||
StartFill,
|
StartFill,
|
||||||
EndFill,
|
EndFill,
|
||||||
|
|
||||||
/// Entry inside of a [Tag::StartFill]
|
/// Entry inside of a [`Tag::StartFill`]
|
||||||
StartEntry,
|
StartEntry,
|
||||||
EndEntry,
|
EndEntry,
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ pub enum Tag {
|
||||||
/// Special semantic element marking the content with a label.
|
/// Special semantic element marking the content with a label.
|
||||||
/// This does not directly influence how the content will be printed.
|
/// This does not directly influence how the content will be printed.
|
||||||
///
|
///
|
||||||
/// See [crate::builders::labelled] for documentation.
|
/// See [`crate::builders::labelled`] for documentation.
|
||||||
StartLabelled(LabelId),
|
StartLabelled(LabelId),
|
||||||
EndLabelled,
|
EndLabelled,
|
||||||
|
|
||||||
|
|
|
@ -189,27 +189,6 @@ impl<'a, 'print> Queue<'a> for FitsQueue<'a, 'print> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator that calls [`Queue::pop`] until it reaches the end of the document.
|
|
||||||
///
|
|
||||||
/// The iterator traverses into the content of any [`FormatElement::Interned`].
|
|
||||||
pub(super) struct QueueIterator<'a, 'q, Q: Queue<'a>> {
|
|
||||||
queue: &'q mut Q,
|
|
||||||
lifetime: PhantomData<&'a ()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, Q> Iterator for QueueIterator<'a, '_, Q>
|
|
||||||
where
|
|
||||||
Q: Queue<'a>,
|
|
||||||
{
|
|
||||||
type Item = &'a FormatElement;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.queue.pop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, Q> FusedIterator for QueueIterator<'a, '_, Q> where Q: Queue<'a> {}
|
|
||||||
|
|
||||||
pub(super) struct QueueContentIterator<'a, 'q, Q: Queue<'a>> {
|
pub(super) struct QueueContentIterator<'a, 'q, Q: Queue<'a>> {
|
||||||
queue: &'q mut Q,
|
queue: &'q mut Q,
|
||||||
kind: TagKind,
|
kind: TagKind,
|
||||||
|
|
|
@ -8,9 +8,6 @@ pub(super) trait Stack<T> {
|
||||||
|
|
||||||
/// Returns the last element if any
|
/// Returns the last element if any
|
||||||
fn top(&self) -> Option<&T>;
|
fn top(&self) -> Option<&T>;
|
||||||
|
|
||||||
/// Returns `true` if the stack is empty
|
|
||||||
fn is_empty(&self) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Stack<T> for Vec<T> {
|
impl<T> Stack<T> for Vec<T> {
|
||||||
|
@ -25,10 +22,6 @@ impl<T> Stack<T> for Vec<T> {
|
||||||
fn top(&self) -> Option<&T> {
|
fn top(&self) -> Option<&T> {
|
||||||
self.last()
|
self.last()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
|
||||||
self.is_empty()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Stack that is stacked on top of another stack. Guarantees that the underlying stack remains unchanged.
|
/// A Stack that is stacked on top of another stack. Guarantees that the underlying stack remains unchanged.
|
||||||
|
@ -80,10 +73,6 @@ where
|
||||||
.last()
|
.last()
|
||||||
.or_else(|| self.original.as_slice().last())
|
.or_else(|| self.original.as_slice().last())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
|
||||||
self.stack.is_empty() && self.original.len() == 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -273,7 +273,7 @@ pub(crate) struct TodoComment<'a> {
|
||||||
pub(crate) directive: TodoDirective<'a>,
|
pub(crate) directive: TodoDirective<'a>,
|
||||||
/// The comment's actual [`TextRange`].
|
/// The comment's actual [`TextRange`].
|
||||||
pub(crate) range: TextRange,
|
pub(crate) range: TextRange,
|
||||||
/// The comment range's position in [`Indexer`].comment_ranges()
|
/// The comment range's position in [`Indexer::comment_ranges`]
|
||||||
pub(crate) range_index: usize,
|
pub(crate) range_index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl CacheKey for LineLength {
|
||||||
pub enum ParseLineWidthError {
|
pub enum ParseLineWidthError {
|
||||||
/// The string could not be parsed as a valid [u16]
|
/// The string could not be parsed as a valid [u16]
|
||||||
ParseError(ParseIntError),
|
ParseError(ParseIntError),
|
||||||
/// The [u16] value of the string is not a valid [LineLength]
|
/// The [u16] value of the string is not a valid [`LineLength`]
|
||||||
TryFromIntError(LineLengthFromIntError),
|
TryFromIntError(LineLengthFromIntError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -531,7 +531,7 @@ pub(crate) fn fix_unnecessary_double_cast_or_process(
|
||||||
.find(|argument| argument.keyword.is_none())
|
.find(|argument| argument.keyword.is_none())
|
||||||
{
|
{
|
||||||
let mut arg = arg.clone();
|
let mut arg = arg.clone();
|
||||||
arg.comma = first.comma.clone();
|
arg.comma.clone_from(&first.comma);
|
||||||
arg.whitespace_after_arg = first.whitespace_after_arg.clone();
|
arg.whitespace_after_arg = first.whitespace_after_arg.clone();
|
||||||
iter::once(arg)
|
iter::once(arg)
|
||||||
.chain(rest.iter().cloned())
|
.chain(rest.iter().cloned())
|
||||||
|
|
|
@ -67,8 +67,8 @@ pub(crate) fn fix_multiple_with_statements(
|
||||||
|
|
||||||
outer_with.items.append(&mut inner_with.items);
|
outer_with.items.append(&mut inner_with.items);
|
||||||
if outer_with.lpar.is_none() {
|
if outer_with.lpar.is_none() {
|
||||||
outer_with.lpar = inner_with.lpar.clone();
|
outer_with.lpar.clone_from(&inner_with.lpar);
|
||||||
outer_with.rpar = inner_with.rpar.clone();
|
outer_with.rpar.clone_from(&inner_with.rpar);
|
||||||
}
|
}
|
||||||
outer_with.body = inner_with.body.clone();
|
outer_with.body = inner_with.body.clone();
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub(crate) fn redundant_backslash(
|
||||||
let start = locator.line_start(token.start());
|
let start = locator.line_start(token.start());
|
||||||
start_index = continuation_lines
|
start_index = continuation_lines
|
||||||
.binary_search(&start)
|
.binary_search(&start)
|
||||||
.map_or_else(|err_index| err_index, |ok_index| ok_index);
|
.unwrap_or_else(|err_index| err_index);
|
||||||
}
|
}
|
||||||
parens += 1;
|
parens += 1;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ pub(crate) fn redundant_backslash(
|
||||||
let end = locator.line_start(token.start());
|
let end = locator.line_start(token.start());
|
||||||
let end_index = continuation_lines
|
let end_index = continuation_lines
|
||||||
.binary_search(&end)
|
.binary_search(&end)
|
||||||
.map_or_else(|err_index| err_index, |ok_index| ok_index);
|
.unwrap_or_else(|err_index| err_index);
|
||||||
for continuation_line in &continuation_lines[start_index..end_index] {
|
for continuation_line in &continuation_lines[start_index..end_index] {
|
||||||
let backslash_end = locator.line_end(*continuation_line);
|
let backslash_end = locator.line_end(*continuation_line);
|
||||||
let backslash_start = backslash_end - TextSize::new(1);
|
let backslash_start = backslash_end - TextSize::new(1);
|
||||||
|
|
|
@ -48,7 +48,7 @@ impl SortingStyle {
|
||||||
/// an "isort-style sort".
|
/// an "isort-style sort".
|
||||||
///
|
///
|
||||||
/// An isort-style sort sorts items first according to their casing:
|
/// An isort-style sort sorts items first according to their casing:
|
||||||
/// `SCREAMING_SNAKE_CASE` names (conventionally used for global constants)
|
/// SCREAMING_SNAKE_CASE names (conventionally used for global constants)
|
||||||
/// come first, followed by CamelCase names (conventionally used for
|
/// come first, followed by CamelCase names (conventionally used for
|
||||||
/// classes), followed by anything else. Within each category,
|
/// classes), followed by anything else. Within each category,
|
||||||
/// a [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order)
|
/// a [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order)
|
||||||
|
|
|
@ -1006,7 +1006,7 @@ impl ConversionFlag {
|
||||||
pub struct DebugText {
|
pub struct DebugText {
|
||||||
/// The text between the `{` and the expression node.
|
/// The text between the `{` and the expression node.
|
||||||
pub leading: String,
|
pub leading: String,
|
||||||
/// The text between the expression and the conversion, the format_spec, or the `}`, depending on what's present in the source
|
/// The text between the expression and the conversion, the `format_spec`, or the `}`, depending on what's present in the source
|
||||||
pub trailing: String,
|
pub trailing: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl<K: std::hash::Hash + Eq, V> MultiMap<K, V> {
|
||||||
/// Returns `true` if `key` has any *leading*, *dangling*, or *trailing* parts.
|
/// Returns `true` if `key` has any *leading*, *dangling*, or *trailing* parts.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(super) fn has(&self, key: &K) -> bool {
|
pub(super) fn has(&self, key: &K) -> bool {
|
||||||
self.index.get(key).is_some()
|
self.index.contains_key(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the *leading*, *dangling*, and *trailing* parts of `key`.
|
/// Returns the *leading*, *dangling*, and *trailing* parts of `key`.
|
||||||
|
@ -382,16 +382,16 @@ where
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct InOrderEntry {
|
struct InOrderEntry {
|
||||||
/// Index into the [MultiMap::parts] vector where the leading parts of this entry start
|
/// Index into the [`MultiMap::parts`] vector where the leading parts of this entry start
|
||||||
leading_start: PartIndex,
|
leading_start: PartIndex,
|
||||||
|
|
||||||
/// Index into the [MultiMap::parts] vector where the dangling parts (and, thus, the leading parts end) start.
|
/// Index into the [`MultiMap::parts`] vector where the dangling parts (and, thus, the leading parts end) start.
|
||||||
dangling_start: PartIndex,
|
dangling_start: PartIndex,
|
||||||
|
|
||||||
/// Index into the [MultiMap::parts] vector where the trailing parts (and, thus, the dangling parts end) of this entry start
|
/// Index into the [`MultiMap::parts`] vector where the trailing parts (and, thus, the dangling parts end) of this entry start
|
||||||
trailing_start: Option<PartIndex>,
|
trailing_start: Option<PartIndex>,
|
||||||
|
|
||||||
/// Index into the [MultiMap::parts] vector where the trailing parts of this entry end
|
/// Index into the [`MultiMap::parts`] vector where the trailing parts of this entry end
|
||||||
trailing_end: Option<PartIndex>,
|
trailing_end: Option<PartIndex>,
|
||||||
|
|
||||||
_count: Count<InOrderEntry>,
|
_count: Count<InOrderEntry>,
|
||||||
|
@ -505,7 +505,7 @@ impl InOrderEntry {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct OutOfOrderEntry {
|
struct OutOfOrderEntry {
|
||||||
/// Index into the [MultiMap::out_of_order] vector at which offset the leaading vec is stored.
|
/// Index into the [`MultiMap::out_of_order`] vector at which offset the leaading vec is stored.
|
||||||
leading_index: usize,
|
leading_index: usize,
|
||||||
_count: Count<OutOfOrderEntry>,
|
_count: Count<OutOfOrderEntry>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,9 +195,9 @@ type CommentsMap<'a> = MultiMap<NodeRefEqualityKey<'a>, SourceComment>;
|
||||||
/// Cloning `comments` is cheap as it only involves bumping a reference counter.
|
/// Cloning `comments` is cheap as it only involves bumping a reference counter.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Comments<'a> {
|
pub(crate) struct Comments<'a> {
|
||||||
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [crate::Formatter].
|
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [`crate::Formatter`].
|
||||||
/// Independent lifetimes are necessary to support the use case where a (formattable object)[crate::Format]
|
/// Independent lifetimes are necessary to support the use case where a (formattable object)[`crate::Format`]
|
||||||
/// iterates over all comments, and writes them into the [crate::Formatter] (mutably borrowing the [crate::Formatter] and in turn its context).
|
/// iterates over all comments, and writes them into the [`crate::Formatter`] (mutably borrowing the [`crate::Formatter`] and in turn its context).
|
||||||
///
|
///
|
||||||
/// ```block
|
/// ```block
|
||||||
/// for leading in f.context().comments().leading_comments(node) {
|
/// for leading in f.context().comments().leading_comments(node) {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use ruff_python_ast::{Expr, ExprAttribute, ExprNumberLiteral, Number};
|
||||||
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
|
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||||
};
|
};
|
||||||
|
@ -123,15 +123,6 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
|
||||||
write!(f, [format_inner])
|
write!(f, [format_inner])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// handle in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprAttribute {
|
impl NeedsParentheses for ExprAttribute {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprBinOp;
|
use ruff_python_ast::ExprBinOp;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::binary_like::BinaryLike;
|
use crate::expression::binary_like::BinaryLike;
|
||||||
use crate::expression::has_parentheses;
|
use crate::expression::has_parentheses;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
|
@ -16,15 +15,6 @@ impl FormatNodeRule<ExprBinOp> for FormatExprBinOp {
|
||||||
fn fmt_fields(&self, item: &ExprBinOp, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &ExprBinOp, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
BinaryLike::Binary(item).fmt(f)
|
BinaryLike::Binary(item).fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled inside of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprBinOp {
|
impl NeedsParentheses for ExprBinOp {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprBytesLiteral;
|
use ruff_python_ast::ExprBytesLiteral;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -21,15 +20,6 @@ impl FormatNodeRule<ExprBytesLiteral> for FormatExprBytesLiteral {
|
||||||
.fmt(f),
|
.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprBytesLiteral {
|
impl NeedsParentheses for ExprBytesLiteral {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::FormatRuleWithOptions;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::{Expr, ExprCall};
|
use ruff_python_ast::{Expr, ExprCall};
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||||
};
|
};
|
||||||
|
@ -74,14 +74,6 @@ impl FormatNodeRule<ExprCall> for FormatExprCall {
|
||||||
fmt_func.fmt(f)
|
fmt_func.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprCall {
|
impl NeedsParentheses for ExprCall {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::{CmpOp, ExprCompare};
|
use ruff_python_ast::{CmpOp, ExprCompare};
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::binary_like::BinaryLike;
|
use crate::expression::binary_like::BinaryLike;
|
||||||
use crate::expression::has_parentheses;
|
use crate::expression::has_parentheses;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
|
@ -17,16 +16,6 @@ impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
||||||
fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, item: &ExprCompare, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
BinaryLike::Compare(item).fmt(f)
|
BinaryLike::Compare(item).fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Node can not have dangling comments
|
|
||||||
debug_assert!(dangling_comments.is_empty());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprCompare {
|
impl NeedsParentheses for ExprCompare {
|
||||||
|
|
|
@ -64,15 +64,6 @@ impl FormatNodeRule<ExprDict> for FormatExprDict {
|
||||||
.with_dangling_comments(open_parenthesis_comments)
|
.with_dangling_comments(open_parenthesis_comments)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled by `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprDict {
|
impl NeedsParentheses for ExprDict {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprDictComp;
|
use ruff_python_ast::ExprDictComp;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -58,15 +58,6 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
||||||
.with_dangling_comments(open_parenthesis_comments)]
|
.with_dangling_comments(open_parenthesis_comments)]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_node_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprDictComp {
|
impl NeedsParentheses for ExprDictComp {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_python_ast::{AnyNodeRef, ExprFString};
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -29,15 +28,6 @@ impl FormatNodeRule<ExprFString> for FormatExprFString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_node_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprFString {
|
impl NeedsParentheses for ExprFString {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{format_args, write, FormatRuleWithOptions};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprGenerator;
|
use ruff_python_ast::ExprGenerator;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -76,15 +75,6 @@ impl FormatNodeRule<ExprGenerator> for FormatExprGenerator {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprGenerator {
|
impl NeedsParentheses for ExprGenerator {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprLambda;
|
use ruff_python_ast::ExprLambda;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::other::parameters::ParametersParentheses;
|
use crate::other::parameters::ParametersParentheses;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -63,15 +63,6 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
|
|
||||||
write!(f, [body.format()])
|
write!(f, [body.format()])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Override. Dangling comments are handled in `fmt_fields`.
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprLambda {
|
impl NeedsParentheses for ExprLambda {
|
||||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprList;
|
use ruff_python_ast::ExprList;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
|
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -37,15 +36,6 @@ impl FormatNodeRule<ExprList> for FormatExprList {
|
||||||
.with_dangling_comments(dangling)
|
.with_dangling_comments(dangling)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprList {
|
impl NeedsParentheses for ExprList {
|
||||||
|
|
|
@ -2,8 +2,6 @@ use ruff_formatter::{format_args, write, FormatResult};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprListComp;
|
use ruff_python_ast::ExprListComp;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
|
|
||||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -41,15 +39,6 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
||||||
.with_dangling_comments(dangling)]
|
.with_dangling_comments(dangling)]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprListComp {
|
impl NeedsParentheses for ExprListComp {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprName;
|
use ruff_python_ast::ExprName;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -18,16 +17,6 @@ impl FormatNodeRule<ExprName> for FormatExprName {
|
||||||
} = item;
|
} = item;
|
||||||
write!(f, [source_text_slice(*range)])
|
write!(f, [source_text_slice(*range)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Node cannot have dangling comments
|
|
||||||
debug_assert!(dangling_comments.is_empty());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprName {
|
impl NeedsParentheses for ExprName {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::{format_args, write};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprNamed;
|
use ruff_python_ast::ExprNamed;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_soft_line_break_or_space, NeedsParentheses, OptionalParentheses,
|
in_parentheses_only_soft_line_break_or_space, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -42,15 +42,6 @@ impl FormatNodeRule<ExprNamed> for FormatExprNamed {
|
||||||
|
|
||||||
write!(f, [value.format()])
|
write!(f, [value.format()])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled by `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprNamed {
|
impl NeedsParentheses for ExprNamed {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprSet;
|
use ruff_python_ast::ExprSet;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -28,15 +27,6 @@ impl FormatNodeRule<ExprSet> for FormatExprSet {
|
||||||
.with_dangling_comments(dangling)
|
.with_dangling_comments(dangling)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSet {
|
impl NeedsParentheses for ExprSet {
|
||||||
|
|
|
@ -2,8 +2,6 @@ use ruff_formatter::{format_args, write, Buffer, FormatResult};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprSetComp;
|
use ruff_python_ast::ExprSetComp;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
|
|
||||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -41,15 +39,6 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
||||||
.with_dangling_comments(dangling)]
|
.with_dangling_comments(dangling)]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSetComp {
|
impl NeedsParentheses for ExprSetComp {
|
||||||
|
|
|
@ -146,15 +146,6 @@ impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_node_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// We're in a slice, so we know there's a first colon, but with have to look into the source
|
/// We're in a slice, so we know there's a first colon, but with have to look into the source
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprStarred;
|
use ruff_python_ast::ExprStarred;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
|
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -23,14 +23,6 @@ impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
||||||
|
|
||||||
write!(f, [token("*"), dangling_comments(dangling), value.format()])
|
write!(f, [token("*"), dangling_comments(dangling), value.format()])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprStarred {
|
impl NeedsParentheses for ExprStarred {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use ruff_formatter::FormatRuleWithOptions;
|
use ruff_formatter::FormatRuleWithOptions;
|
||||||
use ruff_python_ast::{AnyNodeRef, ExprStringLiteral};
|
use ruff_python_ast::{AnyNodeRef, ExprStringLiteral};
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -61,14 +60,6 @@ impl FormatNodeRule<ExprStringLiteral> for FormatExprStringLiteral {
|
||||||
.fmt(f),
|
.fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprStringLiteral {
|
impl NeedsParentheses for ExprStringLiteral {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{write, FormatRuleWithOptions};
|
||||||
use ruff_python_ast::{AnyNodeRef, AstNode};
|
use ruff_python_ast::{AnyNodeRef, AstNode};
|
||||||
use ruff_python_ast::{Expr, ExprSubscript};
|
use ruff_python_ast::{Expr, ExprSubscript};
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::expr_tuple::TupleParentheses;
|
use crate::expression::expr_tuple::TupleParentheses;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
is_expression_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
is_expression_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||||
|
@ -79,15 +78,6 @@ impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
||||||
write!(f, [format_inner])
|
write!(f, [format_inner])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled inside of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprSubscript {
|
impl NeedsParentheses for ExprSubscript {
|
||||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::ExprTuple;
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use crate::builders::parenthesize_if_expands;
|
use crate::builders::parenthesize_if_expands;
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
empty_parenthesized, optional_parentheses, parenthesized, NeedsParentheses, OptionalParentheses,
|
empty_parenthesized, optional_parentheses, parenthesized, NeedsParentheses, OptionalParentheses,
|
||||||
};
|
};
|
||||||
|
@ -203,15 +202,6 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::ExprUnaryOp;
|
use ruff_python_ast::ExprUnaryOp;
|
||||||
use ruff_python_ast::UnaryOp;
|
use ruff_python_ast::UnaryOp;
|
||||||
|
|
||||||
use crate::comments::{trailing_comments, SourceComment};
|
use crate::comments::trailing_comments;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||||
};
|
};
|
||||||
|
@ -66,14 +66,6 @@ impl FormatNodeRule<ExprUnaryOp> for FormatExprUnaryOp {
|
||||||
operand.format().fmt(f)
|
operand.format().fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for ExprUnaryOp {
|
impl NeedsParentheses for ExprUnaryOp {
|
||||||
|
|
|
@ -12,8 +12,7 @@ use ruff_python_trivia::CommentRanges;
|
||||||
use ruff_source_file::Locator;
|
use ruff_source_file::Locator;
|
||||||
|
|
||||||
use crate::comments::{
|
use crate::comments::{
|
||||||
dangling_comments, has_skip_comment, leading_comments, trailing_comments, Comments,
|
has_skip_comment, leading_comments, trailing_comments, Comments, SourceComment,
|
||||||
SourceComment,
|
|
||||||
};
|
};
|
||||||
pub use crate::context::PyFormatContext;
|
pub use crate::context::PyFormatContext;
|
||||||
pub use crate::options::{
|
pub use crate::options::{
|
||||||
|
@ -75,6 +74,8 @@ where
|
||||||
|
|
||||||
self.fmt_fields(node, f)?;
|
self.fmt_fields(node, f)?;
|
||||||
|
|
||||||
|
debug_assert!(node_comments.dangling.iter().all(SourceComment::is_formatted), "The node has dangling comments that need to be formatted manually. Add the special dangling comments handling to `fmt_fields`.");
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
[
|
[
|
||||||
|
@ -88,26 +89,6 @@ where
|
||||||
/// Formats the node's fields.
|
/// Formats the node's fields.
|
||||||
fn fmt_fields(&self, item: &N, f: &mut PyFormatter) -> FormatResult<()>;
|
fn fmt_fields(&self, item: &N, f: &mut PyFormatter) -> FormatResult<()>;
|
||||||
|
|
||||||
/// Formats the [dangling comments](comments#dangling-comments) of the node.
|
|
||||||
///
|
|
||||||
/// You should override this method if the node handled by this rule can have dangling comments because the
|
|
||||||
/// default implementation formats the dangling comments at the end of the node, which isn't ideal but ensures that
|
|
||||||
/// no comments are dropped.
|
|
||||||
///
|
|
||||||
/// A node can have dangling comments if all its children are tokens or if all node children are optional.
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
dangling_node_comments: &[SourceComment],
|
|
||||||
f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
debug_assert!(
|
|
||||||
dangling_node_comments.is_empty(),
|
|
||||||
"The node has dangling comments that need to be formatted manually. Add the special dangling comments handling to `fmt_fields` and override `fmt_dangling_comments` with an empty implementation that returns `Ok(())`."
|
|
||||||
);
|
|
||||||
|
|
||||||
dangling_comments(dangling_node_comments).fmt(f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_suppressed(
|
fn is_suppressed(
|
||||||
&self,
|
&self,
|
||||||
_trailing_comments: &[SourceComment],
|
_trailing_comments: &[SourceComment],
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::ModModule;
|
use ruff_python_ast::ModModule;
|
||||||
use ruff_python_trivia::lines_after;
|
use ruff_python_trivia::lines_after;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::statement::suite::SuiteKind;
|
use crate::statement::suite::SuiteKind;
|
||||||
use crate::FormatNodeRule;
|
use crate::FormatNodeRule;
|
||||||
|
@ -34,14 +33,4 @@ impl FormatNodeRule<ModModule> for FormatModModule {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Node can't have dangling comments.
|
|
||||||
debug_assert!(dangling_comments.is_empty());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::{ArgOrKeyword, Arguments, Expr};
|
||||||
use ruff_python_trivia::{PythonWhitespace, SimpleTokenKind, SimpleTokenizer};
|
use ruff_python_trivia::{PythonWhitespace, SimpleTokenKind, SimpleTokenizer};
|
||||||
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
use ruff_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::expr_generator::GeneratorExpParentheses;
|
use crate::expression::expr_generator::GeneratorExpParentheses;
|
||||||
use crate::expression::is_expression_huggable;
|
use crate::expression::is_expression_huggable;
|
||||||
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
||||||
|
@ -112,15 +111,6 @@ impl FormatNodeRule<Arguments> for FormatArguments {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_single_argument_parenthesized(argument: &Expr, call_end: TextSize, source: &str) -> bool {
|
fn is_single_argument_parenthesized(argument: &Expr, call_end: TextSize, source: &str) -> bool {
|
||||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::{Comprehension, Expr};
|
||||||
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
|
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
|
||||||
use ruff_text_size::{Ranged, TextRange};
|
use ruff_text_size::{Ranged, TextRange};
|
||||||
|
|
||||||
use crate::comments::{leading_comments, trailing_comments, SourceComment};
|
use crate::comments::{leading_comments, trailing_comments};
|
||||||
use crate::expression::expr_tuple::TupleParentheses;
|
use crate::expression::expr_tuple::TupleParentheses;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -115,15 +115,6 @@ impl FormatNodeRule<Comprehension> for FormatComprehension {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// dangling comments are formatted as part of fmt_fields
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExprTupleWithoutParentheses<'a>(&'a Expr);
|
struct ExprTupleWithoutParentheses<'a>(&'a Expr);
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
||||||
use ruff_formatter::FormatRuleWithOptions;
|
use ruff_formatter::FormatRuleWithOptions;
|
||||||
use ruff_python_ast::ExceptHandlerExceptHandler;
|
use ruff_python_ast::ExceptHandlerExceptHandler;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::Parenthesize;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -89,13 +88,4 @@ impl FormatNodeRule<ExceptHandlerExceptHandler> for FormatExceptHandlerExceptHan
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// dangling comments are formatted as part of fmt_fields
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AstNode;
|
||||||
use ruff_python_ast::MatchCase;
|
use ruff_python_ast::MatchCase;
|
||||||
|
|
||||||
use crate::builders::parenthesize_if_expands;
|
use crate::builders::parenthesize_if_expands;
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||||
|
@ -68,13 +67,4 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,15 +277,6 @@ impl FormatNodeRule<Parameters> for FormatParameters {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CommentsAroundText<'a> {
|
struct CommentsAroundText<'a> {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use ruff_formatter::{write, FormatRuleWithOptions};
|
use ruff_formatter::{write, FormatRuleWithOptions};
|
||||||
use ruff_python_ast::WithItem;
|
use ruff_python_ast::WithItem;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::{
|
use crate::expression::parentheses::{
|
||||||
is_expression_parenthesized, parenthesized, Parentheses, Parenthesize,
|
is_expression_parenthesized, parenthesized, Parentheses, Parenthesize,
|
||||||
|
@ -175,12 +174,4 @@ impl FormatNodeRule<WithItem> for FormatWithItem {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::{Pattern, PatternArguments};
|
||||||
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
|
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
|
||||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -72,14 +71,6 @@ impl FormatNodeRule<PatternArguments> for FormatPatternArguments {
|
||||||
.with_dangling_comments(dangling_comments)]
|
.with_dangling_comments(dangling_comments)]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the pattern (which is the only argument to a [`PatternMatchClass`]) is
|
/// Returns `true` if the pattern (which is the only argument to a [`PatternMatchClass`]) is
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::PatternMatchAs;
|
use ruff_python_ast::PatternMatchAs;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -48,14 +48,6 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
||||||
token("_").fmt(f)
|
token("_").fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for PatternMatchAs {
|
impl NeedsParentheses for PatternMatchAs {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::PatternMatchClass;
|
use ruff_python_ast::PatternMatchClass;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -29,14 +29,6 @@ impl FormatNodeRule<PatternMatchClass> for FormatPatternMatchClass {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for PatternMatchClass {
|
impl NeedsParentheses for PatternMatchClass {
|
||||||
|
|
|
@ -90,15 +90,6 @@ impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
|
||||||
.with_dangling_comments(open_parenthesis_comments)
|
.with_dangling_comments(open_parenthesis_comments)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled by `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for PatternMatchMapping {
|
impl NeedsParentheses for PatternMatchMapping {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use ruff_formatter::{format_args, Format, FormatResult};
|
use ruff_formatter::{format_args, Format, FormatResult};
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::PatternMatchSequence;
|
use ruff_python_ast::PatternMatchSequence;
|
||||||
|
@ -56,15 +55,6 @@ impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
|
||||||
SequenceType::TupleNoParens => optional_parentheses(&items).fmt(f),
|
SequenceType::TupleNoParens => optional_parentheses(&items).fmt(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_node_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for PatternMatchSequence {
|
impl NeedsParentheses for PatternMatchSequence {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
||||||
use ruff_python_ast::AnyNodeRef;
|
use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::PatternMatchStar;
|
use ruff_python_ast::PatternMatchStar;
|
||||||
|
|
||||||
use crate::comments::{dangling_comments, SourceComment};
|
use crate::comments::dangling_comments;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -23,15 +23,6 @@ impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
|
||||||
None => write!(f, [token("_")]),
|
None => write!(f, [token("_")]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled by `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NeedsParentheses for PatternMatchStar {
|
impl NeedsParentheses for PatternMatchStar {
|
||||||
|
|
|
@ -157,15 +157,6 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// handled in fmt_fields
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) struct FormatDecorators<'a> {
|
pub(super) struct FormatDecorators<'a> {
|
||||||
|
|
|
@ -54,15 +54,6 @@ impl FormatNodeRule<StmtDelete> for FormatStmtDelete {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_suppressed(
|
fn is_suppressed(
|
||||||
&self,
|
&self,
|
||||||
trailing_comments: &[SourceComment],
|
trailing_comments: &[SourceComment],
|
||||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{format_args, write};
|
||||||
use ruff_python_ast::{Expr, Stmt, StmtFor};
|
use ruff_python_ast::{Expr, Stmt, StmtFor};
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::expr_tuple::TupleParentheses;
|
use crate::expression::expr_tuple::TupleParentheses;
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::Parenthesize;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
|
@ -93,13 +92,4 @@ impl FormatNodeRule<StmtFor> for FormatStmtFor {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::{NodeKind, StmtFunctionDef};
|
||||||
use crate::comments::format::{
|
use crate::comments::format::{
|
||||||
empty_lines_after_leading_comments, empty_lines_before_trailing_comments,
|
empty_lines_after_leading_comments, empty_lines_before_trailing_comments,
|
||||||
};
|
};
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::{Parentheses, Parenthesize};
|
use crate::expression::parentheses::{Parentheses, Parenthesize};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -90,15 +89,6 @@ impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||||
empty_lines_before_trailing_comments(f, comments.trailing(item), NodeKind::StmtFunctionDef)
|
empty_lines_before_trailing_comments(f, comments.trailing(item), NodeKind::StmtFunctionDef)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_function_header(f: &mut PyFormatter, item: &StmtFunctionDef) -> FormatResult<()> {
|
fn format_function_header(f: &mut PyFormatter, item: &StmtFunctionDef) -> FormatResult<()> {
|
||||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AnyNodeRef;
|
||||||
use ruff_python_ast::{ElifElseClause, StmtIf};
|
use ruff_python_ast::{ElifElseClause, StmtIf};
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::Parenthesize;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -48,15 +47,6 @@ impl FormatNodeRule<StmtIf> for FormatStmtIf {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled by `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracted so we can implement `FormatElifElseClause` but also pass in `last_node` from
|
/// Extracted so we can implement `FormatElifElseClause` but also pass in `last_node` from
|
||||||
|
|
|
@ -73,15 +73,6 @@ impl FormatNodeRule<StmtImportFrom> for FormatStmtImportFrom {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_suppressed(
|
fn is_suppressed(
|
||||||
&self,
|
&self,
|
||||||
trailing_comments: &[SourceComment],
|
trailing_comments: &[SourceComment],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use ruff_formatter::{format_args, write};
|
use ruff_formatter::{format_args, write};
|
||||||
use ruff_python_ast::StmtMatch;
|
use ruff_python_ast::StmtMatch;
|
||||||
|
|
||||||
use crate::comments::{leading_alternate_branch_comments, SourceComment};
|
use crate::comments::leading_alternate_branch_comments;
|
||||||
use crate::context::{NodeLevel, WithNodeLevel};
|
use crate::context::{NodeLevel, WithNodeLevel};
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::Parenthesize;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
|
@ -63,13 +63,4 @@ impl FormatNodeRule<StmtMatch> for FormatStmtMatch {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled as part of `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,15 +93,6 @@ impl FormatNodeRule<StmtTry> for FormatStmtTry {
|
||||||
|
|
||||||
write!(f, [comments::dangling_comments(dangling_comments)])
|
write!(f, [comments::dangling_comments(dangling_comments)])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// dangling comments are formatted as part of AnyStatementTry::fmt
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_case<'a>(
|
fn format_case<'a>(
|
||||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AstNode;
|
||||||
use ruff_python_ast::{Stmt, StmtWhile};
|
use ruff_python_ast::{Stmt, StmtWhile};
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::maybe_parenthesize_expression;
|
use crate::expression::maybe_parenthesize_expression;
|
||||||
use crate::expression::parentheses::Parenthesize;
|
use crate::expression::parentheses::Parenthesize;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
@ -70,13 +69,4 @@ impl FormatNodeRule<StmtWhile> for FormatStmtWhile {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,15 +128,6 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
|
|
@ -218,7 +218,7 @@ fn contains_unescaped_newline(haystack: &str) -> bool {
|
||||||
let mut rest = haystack;
|
let mut rest = haystack;
|
||||||
|
|
||||||
while let Some(index) = memchr::memchr(b'\\', rest.as_bytes()) {
|
while let Some(index) = memchr::memchr(b'\\', rest.as_bytes()) {
|
||||||
rest = &rest[index + 1..].trim_whitespace_start();
|
rest = rest[index + 1..].trim_whitespace_start();
|
||||||
|
|
||||||
if rest.starts_with('\n') {
|
if rest.starts_with('\n') {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::TypeParams;
|
||||||
use ruff_text_size::Ranged;
|
use ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::builders::PyFormatterExtensions;
|
use crate::builders::PyFormatterExtensions;
|
||||||
use crate::comments::SourceComment;
|
|
||||||
use crate::expression::parentheses::parenthesized;
|
use crate::expression::parentheses::parenthesized;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -34,13 +33,4 @@ impl FormatNodeRule<TypeParams> for FormatTypeParams {
|
||||||
.with_dangling_comments(dangling_comments)
|
.with_dangling_comments(dangling_comments)
|
||||||
.fmt(f)
|
.fmt(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_dangling_comments(
|
|
||||||
&self,
|
|
||||||
_dangling_comments: &[SourceComment],
|
|
||||||
_f: &mut PyFormatter,
|
|
||||||
) -> FormatResult<()> {
|
|
||||||
// Handled in `fmt_fields`
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,7 +185,7 @@ pub enum ScopeKind<'a> {
|
||||||
Function(&'a ast::StmtFunctionDef),
|
Function(&'a ast::StmtFunctionDef),
|
||||||
Generator,
|
Generator,
|
||||||
Module,
|
Module,
|
||||||
/// A Python 3.12+ ["annotation scope"](https://docs.python.org/3/reference/executionmodel.html#annotation-scopes)
|
/// A Python 3.12+ [annotation scope](https://docs.python.org/3/reference/executionmodel.html#annotation-scopes)
|
||||||
Type,
|
Type,
|
||||||
Lambda(&'a ast::ExprLambda),
|
Lambda(&'a ast::ExprLambda),
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl Document {
|
||||||
{
|
{
|
||||||
tracing::debug!("Fast path - replacing entire document");
|
tracing::debug!("Fast path - replacing entire document");
|
||||||
self.modify(|contents, version| {
|
self.modify(|contents, version| {
|
||||||
*contents = text.clone();
|
contents.clone_from(text);
|
||||||
*version = new_version;
|
*version = new_version;
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -610,8 +610,8 @@ Options:
|
||||||
Enable preview mode; checks will include unstable rules and fixes.
|
Enable preview mode; checks will include unstable rules and fixes.
|
||||||
Use `--no-preview` to disable
|
Use `--no-preview` to disable
|
||||||
--extension <EXTENSION>
|
--extension <EXTENSION>
|
||||||
List of mappings from file extension to language (one of ["python",
|
List of mappings from file extension to language (one of `python`,
|
||||||
"ipynb", "pyi"]). For example, to treat `.ipy` files as IPython
|
`ipynb`, `pyi`). For example, to treat `.ipy` files as IPython
|
||||||
notebooks, use `--extension ipy:ipynb`
|
notebooks, use `--extension ipy:ipynb`
|
||||||
--statistics
|
--statistics
|
||||||
Show counts for every rule with at least one violation
|
Show counts for every rule with at least one violation
|
||||||
|
@ -715,8 +715,8 @@ Options:
|
||||||
status code and the difference between the current file and how the
|
status code and the difference between the current file and how the
|
||||||
formatted file would look like
|
formatted file would look like
|
||||||
--extension <EXTENSION>
|
--extension <EXTENSION>
|
||||||
List of mappings from file extension to language (one of ["python",
|
List of mappings from file extension to language (one of `python`,
|
||||||
"ipynb", "pyi"]). For example, to treat `.ipy` files as IPython
|
`ipynb`, `pyi`). For example, to treat `.ipy` files as IPython
|
||||||
notebooks, use `--extension ipy:ipynb`
|
notebooks, use `--extension ipy:ipynb`
|
||||||
--target-version <TARGET_VERSION>
|
--target-version <TARGET_VERSION>
|
||||||
The minimum Python version that should be supported [possible values:
|
The minimum Python version that should be supported [possible values:
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.77"
|
channel = "1.78"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue