mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-14 15:40:51 +00:00
Add new with
and match
sequence test cases (#9128)
## Summary Add new test cases for `with_item` and `match` sequence that demonstrate how long headers break. Removes one use of `optional_parentheses` in a position where it is know that the parentheses always need to be added. ## Test Plan cargo test
This commit is contained in:
parent
25b2361411
commit
c8d6958d15
5 changed files with 34 additions and 5 deletions
|
@ -6,9 +6,7 @@ use ruff_text_size::{Ranged, TextRange};
|
|||
|
||||
use crate::builders::parenthesize_if_expands;
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::{
|
||||
in_parentheses_only_soft_line_break_or_space, optional_parentheses, parenthesized,
|
||||
};
|
||||
use crate::expression::parentheses::parenthesized;
|
||||
use crate::other::commas;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||
|
@ -77,7 +75,7 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
|||
joiner.entry_with_line_separator(
|
||||
item,
|
||||
&item.format(),
|
||||
in_parentheses_only_soft_line_break_or_space(),
|
||||
soft_line_break_or_space(),
|
||||
);
|
||||
}
|
||||
joiner.finish()
|
||||
|
@ -87,7 +85,7 @@ impl FormatNodeRule<StmtWith> for FormatStmtWith {
|
|||
// This is similar to `maybe_parenthesize_expression`, but we're not
|
||||
// dealing with an expression here, it's a `WithItem`.
|
||||
if comments.has_leading(item) || comments.has_trailing(item) {
|
||||
optional_parentheses(&item.format()).fmt(f)?;
|
||||
parenthesized("(", &item.format(), ")").fmt(f)?;
|
||||
} else {
|
||||
item.format().fmt(f)?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue