mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
Introduce Token element (#7048)
This commit is contained in:
parent
2f3a950f6f
commit
c05e4628b1
78 changed files with 733 additions and 723 deletions
|
@ -12,6 +12,6 @@ impl FormatNodeRule<PatternKeyword> for FormatPatternKeyword {
|
|||
attr,
|
||||
pattern,
|
||||
} = item;
|
||||
write!(f, [attr.format(), text("="), pattern.format()])
|
||||
write!(f, [attr.format(), token("="), pattern.format()])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
|||
write!(f, [space()])?;
|
||||
}
|
||||
|
||||
write!(f, [text("as")])?;
|
||||
write!(f, [token("as")])?;
|
||||
|
||||
let trailing_as_comments = comments.dangling(item);
|
||||
if trailing_as_comments.is_empty() {
|
||||
|
@ -45,7 +45,7 @@ impl FormatNodeRule<PatternMatchAs> for FormatPatternMatchAs {
|
|||
name.format().fmt(f)
|
||||
} else {
|
||||
debug_assert!(pattern.is_none());
|
||||
text("_").fmt(f)
|
||||
token("_").fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ impl Format<PyFormatContext<'_>> for RestPattern<'_> {
|
|||
f,
|
||||
[
|
||||
leading_comments(self.comments),
|
||||
text("**"),
|
||||
token("**"),
|
||||
self.identifier.format()
|
||||
]
|
||||
)
|
||||
|
@ -156,7 +156,7 @@ impl Format<PyFormatContext<'_>> for KeyPatternPair<'_> {
|
|||
f,
|
||||
[group(&format_args![
|
||||
self.key.format(),
|
||||
text(":"),
|
||||
token(":"),
|
||||
space(),
|
||||
self.pattern.format()
|
||||
])]
|
||||
|
|
|
@ -35,7 +35,7 @@ impl FormatNodeRule<PatternMatchOr> for FormatPatternMatchOr {
|
|||
[hard_line_break(), leading_comments(leading_value_comments)]
|
||||
)?;
|
||||
}
|
||||
write!(f, [text("|"), space(), pattern.format()])?;
|
||||
write!(f, [token("|"), space(), pattern.format()])?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -10,9 +10,9 @@ pub struct FormatPatternMatchSingleton;
|
|||
impl FormatNodeRule<PatternMatchSingleton> for FormatPatternMatchSingleton {
|
||||
fn fmt_fields(&self, item: &PatternMatchSingleton, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
match item.value {
|
||||
Constant::None => text("None").fmt(f),
|
||||
Constant::Bool(true) => text("True").fmt(f),
|
||||
Constant::Bool(false) => text("False").fmt(f),
|
||||
Constant::None => token("None").fmt(f),
|
||||
Constant::Bool(true) => token("True").fmt(f),
|
||||
Constant::Bool(false) => token("False").fmt(f),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar {
|
|||
let comments = f.context().comments().clone();
|
||||
let dangling = comments.dangling(item);
|
||||
|
||||
write!(f, [text("*"), dangling_comments(dangling)])?;
|
||||
write!(f, [token("*"), dangling_comments(dangling)])?;
|
||||
|
||||
match name {
|
||||
Some(name) => write!(f, [name.format()]),
|
||||
None => write!(f, [text("_")]),
|
||||
None => write!(f, [token("_")]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue