mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Override fmt_dangling_comments for frequent nodes (#6551)
This commit is contained in:
parent
680d171ae5
commit
fc0c9507d0
3 changed files with 12 additions and 1 deletions
|
@ -780,7 +780,8 @@ where
|
|||
Context: FormatContext,
|
||||
{
|
||||
let mut state = FormatState::new(context);
|
||||
let mut buffer = VecBuffer::with_capacity(arguments.items().len(), &mut state);
|
||||
let mut buffer =
|
||||
VecBuffer::with_capacity(state.context().source_code().as_str().len(), &mut state);
|
||||
|
||||
buffer.write_fmt(arguments)?;
|
||||
|
||||
|
|
|
@ -69,6 +69,11 @@ impl FormatNodeRule<ExprCompare> for FormatExprCompare {
|
|||
|
||||
in_parentheses_only_group(&inner).fmt(f)
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(&self, _node: &ExprCompare, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
// Node can not have dangling comments
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprCompare {
|
||||
|
|
|
@ -22,6 +22,11 @@ impl FormatNodeRule<ExprName> for FormatExprName {
|
|||
|
||||
write!(f, [source_text_slice(*range, ContainsNewlines::No)])
|
||||
}
|
||||
|
||||
fn fmt_dangling_comments(&self, _node: &ExprName, _f: &mut PyFormatter) -> FormatResult<()> {
|
||||
// Node cannot have dangling comments
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl NeedsParentheses for ExprName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue