mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +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
|
@ -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.
|
||||
#[allow(unused)]
|
||||
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`.
|
||||
|
@ -382,16 +382,16 @@ where
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
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,
|
||||
|
||||
/// 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,
|
||||
|
||||
/// 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>,
|
||||
|
||||
/// 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>,
|
||||
|
||||
_count: Count<InOrderEntry>,
|
||||
|
@ -505,7 +505,7 @@ impl InOrderEntry {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
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,
|
||||
_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.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Comments<'a> {
|
||||
/// 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]
|
||||
/// iterates over all comments, and writes them into the [crate::Formatter] (mutably borrowing the [crate::Formatter] and in turn its context).
|
||||
/// 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`]
|
||||
/// iterates over all comments, and writes them into the [`crate::Formatter`] (mutably borrowing the [`crate::Formatter`] and in turn its context).
|
||||
///
|
||||
/// ```block
|
||||
/// 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_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||
};
|
||||
|
@ -123,15 +123,6 @@ impl FormatNodeRule<ExprAttribute> for FormatExprAttribute {
|
|||
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 {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprBinOp;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::binary_like::BinaryLike;
|
||||
use crate::expression::has_parentheses;
|
||||
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<()> {
|
||||
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 {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprBytesLiteral;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||
};
|
||||
|
@ -21,15 +20,6 @@ impl FormatNodeRule<ExprBytesLiteral> for FormatExprBytesLiteral {
|
|||
.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 {
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::FormatRuleWithOptions;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{Expr, ExprCall};
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||
};
|
||||
|
@ -74,14 +74,6 @@ impl FormatNodeRule<ExprCall> for FormatExprCall {
|
|||
fmt_func.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprCall {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule};
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{CmpOp, ExprCompare};
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::binary_like::BinaryLike;
|
||||
use crate::expression::has_parentheses;
|
||||
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<()> {
|
||||
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 {
|
||||
|
|
|
@ -64,15 +64,6 @@ impl FormatNodeRule<ExprDict> for FormatExprDict {
|
|||
.with_dangling_comments(open_parenthesis_comments)
|
||||
.fmt(f)
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
// Handled by `fmt_fields`
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprDict {
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::ExprDictComp;
|
||||
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::prelude::*;
|
||||
|
||||
|
@ -58,15 +58,6 @@ impl FormatNodeRule<ExprDictComp> for FormatExprDictComp {
|
|||
.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 {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_python_ast::{AnyNodeRef, ExprFString};
|
|||
use ruff_source_file::Locator;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
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 {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{format_args, write, FormatRuleWithOptions};
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprGenerator;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||
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 {
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::ExprLambda;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::other::parameters::ParametersParentheses;
|
||||
use crate::prelude::*;
|
||||
|
@ -63,15 +63,6 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::ExprList;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
empty_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses,
|
||||
};
|
||||
|
@ -37,15 +36,6 @@ impl FormatNodeRule<ExprList> for FormatExprList {
|
|||
.with_dangling_comments(dangling)
|
||||
.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 {
|
||||
|
|
|
@ -2,8 +2,6 @@ use ruff_formatter::{format_args, write, FormatResult};
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprListComp;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
|
||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -41,15 +39,6 @@ impl FormatNodeRule<ExprListComp> for FormatExprListComp {
|
|||
.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 {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprName;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -18,16 +17,6 @@ impl FormatNodeRule<ExprName> for FormatExprName {
|
|||
} = item;
|
||||
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 {
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::{format_args, write};
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprNamed;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{
|
||||
in_parentheses_only_soft_line_break_or_space, NeedsParentheses, OptionalParentheses,
|
||||
};
|
||||
|
@ -42,15 +42,6 @@ impl FormatNodeRule<ExprNamed> for FormatExprNamed {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::ExprSet;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -28,15 +27,6 @@ impl FormatNodeRule<ExprSet> for FormatExprSet {
|
|||
.with_dangling_comments(dangling)
|
||||
.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 {
|
||||
|
|
|
@ -2,8 +2,6 @@ use ruff_formatter::{format_args, write, Buffer, FormatResult};
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprSetComp;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
|
||||
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -41,15 +39,6 @@ impl FormatNodeRule<ExprSetComp> for FormatExprSetComp {
|
|||
.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 {
|
||||
|
|
|
@ -146,15 +146,6 @@ impl FormatNodeRule<ExprSlice> for FormatExprSlice {
|
|||
}
|
||||
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
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::ExprStarred;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
@ -23,14 +23,6 @@ impl FormatNodeRule<ExprStarred> for FormatExprStarred {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use ruff_formatter::FormatRuleWithOptions;
|
||||
use ruff_python_ast::{AnyNodeRef, ExprStringLiteral};
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
in_parentheses_only_group, NeedsParentheses, OptionalParentheses,
|
||||
};
|
||||
|
@ -61,14 +60,6 @@ impl FormatNodeRule<ExprStringLiteral> for FormatExprStringLiteral {
|
|||
.fmt(f),
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprStringLiteral {
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{write, FormatRuleWithOptions};
|
|||
use ruff_python_ast::{AnyNodeRef, AstNode};
|
||||
use ruff_python_ast::{Expr, ExprSubscript};
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::expr_tuple::TupleParentheses;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||
|
@ -79,15 +78,6 @@ impl FormatNodeRule<ExprSubscript> for FormatExprSubscript {
|
|||
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 {
|
||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::ExprTuple;
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::builders::parenthesize_if_expands;
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
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)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::ExprUnaryOp;
|
||||
use ruff_python_ast::UnaryOp;
|
||||
|
||||
use crate::comments::{trailing_comments, SourceComment};
|
||||
use crate::comments::trailing_comments;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, NeedsParentheses, OptionalParentheses, Parentheses,
|
||||
};
|
||||
|
@ -66,14 +66,6 @@ impl FormatNodeRule<ExprUnaryOp> for FormatExprUnaryOp {
|
|||
operand.format().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprUnaryOp {
|
||||
|
|
|
@ -12,8 +12,7 @@ use ruff_python_trivia::CommentRanges;
|
|||
use ruff_source_file::Locator;
|
||||
|
||||
use crate::comments::{
|
||||
dangling_comments, has_skip_comment, leading_comments, trailing_comments, Comments,
|
||||
SourceComment,
|
||||
has_skip_comment, leading_comments, trailing_comments, Comments, SourceComment,
|
||||
};
|
||||
pub use crate::context::PyFormatContext;
|
||||
pub use crate::options::{
|
||||
|
@ -75,6 +74,8 @@ where
|
|||
|
||||
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!(
|
||||
f,
|
||||
[
|
||||
|
@ -88,26 +89,6 @@ where
|
|||
/// Formats the node's fields.
|
||||
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(
|
||||
&self,
|
||||
_trailing_comments: &[SourceComment],
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::ModModule;
|
||||
use ruff_python_trivia::lines_after;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::suite::SuiteKind;
|
||||
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_text_size::{Ranged, TextLen, TextRange, TextSize};
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::expr_generator::GeneratorExpParentheses;
|
||||
use crate::expression::is_expression_huggable;
|
||||
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 {
|
||||
|
|
|
@ -3,7 +3,7 @@ use ruff_python_ast::{Comprehension, Expr};
|
|||
use ruff_python_trivia::{find_only_token_in_range, SimpleTokenKind};
|
||||
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::prelude::*;
|
||||
|
||||
|
@ -115,15 +115,6 @@ impl FormatNodeRule<Comprehension> for FormatComprehension {
|
|||
}
|
||||
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);
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::write;
|
|||
use ruff_formatter::FormatRuleWithOptions;
|
||||
use ruff_python_ast::ExceptHandlerExceptHandler;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
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 crate::builders::parenthesize_if_expands;
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses, Parentheses};
|
||||
use crate::prelude::*;
|
||||
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> {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use ruff_formatter::{write, FormatRuleWithOptions};
|
||||
use ruff_python_ast::WithItem;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, parenthesized, Parentheses, Parenthesize,
|
||||
|
@ -175,12 +174,4 @@ impl FormatNodeRule<WithItem> for FormatWithItem {
|
|||
|
||||
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_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{empty_parenthesized, parenthesized, Parentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -72,14 +71,6 @@ impl FormatNodeRule<PatternArguments> for FormatPatternArguments {
|
|||
.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
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::PatternMatchAs;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -48,14 +48,6 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
|||
token("_").fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for PatternMatchAs {
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::PatternMatchClass;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
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 {
|
||||
|
|
|
@ -90,15 +90,6 @@ impl FormatNodeRule<PatternMatchMapping> for FormatPatternMatchMapping {
|
|||
.with_dangling_comments(open_parenthesis_comments)
|
||||
.fmt(f)
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
// Handled by `fmt_fields`
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for PatternMatchMapping {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::comments::SourceComment;
|
||||
use ruff_formatter::{format_args, Format, FormatResult};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::PatternMatchSequence;
|
||||
|
@ -56,15 +55,6 @@ impl FormatNodeRule<PatternMatchSequence> for FormatPatternMatchSequence {
|
|||
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 {
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::PatternMatchStar;
|
||||
|
||||
use crate::comments::{dangling_comments, SourceComment};
|
||||
use crate::comments::dangling_comments;
|
||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -23,15 +23,6 @@ impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
|
|||
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 {
|
||||
|
|
|
@ -157,15 +157,6 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
// handled in fmt_fields
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
&self,
|
||||
trailing_comments: &[SourceComment],
|
||||
|
|
|
@ -2,7 +2,6 @@ use ruff_formatter::{format_args, write};
|
|||
use ruff_python_ast::{Expr, Stmt, StmtFor};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::expr_tuple::TupleParentheses;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
|
@ -93,13 +92,4 @@ impl FormatNodeRule<StmtFor> for FormatStmtFor {
|
|||
|
||||
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::{
|
||||
empty_lines_after_leading_comments, empty_lines_before_trailing_comments,
|
||||
};
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::{Parentheses, Parenthesize};
|
||||
use crate::prelude::*;
|
||||
|
@ -90,15 +89,6 @@ impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
|||
empty_lines_before_trailing_comments(f, comments.trailing(item), NodeKind::StmtFunctionDef)
|
||||
.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<()> {
|
||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AnyNodeRef;
|
|||
use ruff_python_ast::{ElifElseClause, StmtIf};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
|
@ -48,15 +47,6 @@ impl FormatNodeRule<StmtIf> for FormatStmtIf {
|
|||
|
||||
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
|
||||
|
|
|
@ -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(
|
||||
&self,
|
||||
trailing_comments: &[SourceComment],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use ruff_formatter::{format_args, write};
|
||||
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::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
|
@ -63,13 +63,4 @@ impl FormatNodeRule<StmtMatch> for FormatStmtMatch {
|
|||
|
||||
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)])
|
||||
}
|
||||
|
||||
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>(
|
||||
|
|
|
@ -3,7 +3,6 @@ use ruff_python_ast::AstNode;
|
|||
use ruff_python_ast::{Stmt, StmtWhile};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
|
@ -70,13 +69,4 @@ impl FormatNodeRule<StmtWhile> for FormatStmtWhile {
|
|||
|
||||
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)]
|
||||
|
|
|
@ -218,7 +218,7 @@ fn contains_unescaped_newline(haystack: &str) -> bool {
|
|||
let mut rest = haystack;
|
||||
|
||||
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') {
|
||||
return true;
|
||||
|
|
|
@ -4,7 +4,6 @@ use ruff_python_ast::TypeParams;
|
|||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::builders::PyFormatterExtensions;
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::parenthesized;
|
||||
use crate::prelude::*;
|
||||
|
||||
|
@ -34,13 +33,4 @@ impl FormatNodeRule<TypeParams> for FormatTypeParams {
|
|||
.with_dangling_comments(dangling_comments)
|
||||
.fmt(f)
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(
|
||||
&self,
|
||||
_dangling_comments: &[SourceComment],
|
||||
_f: &mut PyFormatter,
|
||||
) -> FormatResult<()> {
|
||||
// Handled in `fmt_fields`
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue