mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Track formatting all comments
We currently don't format all comments as match statements are not yet implemented. We can work around this for the top level match statement by setting them manually formatted but the mocked-out top level match doesn't call into its children so they would still have unformatted comments
This commit is contained in:
parent
e2f7862404
commit
39beeb61f7
4 changed files with 91 additions and 25 deletions
|
@ -14,7 +14,7 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
|||
fn fmt_fields(&self, item: &MatchCase, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let MatchCase {
|
||||
range: _,
|
||||
pattern: _,
|
||||
pattern,
|
||||
guard,
|
||||
body,
|
||||
} = item;
|
||||
|
@ -24,7 +24,17 @@ impl FormatNodeRule<MatchCase> for FormatMatchCase {
|
|||
[
|
||||
text("case"),
|
||||
space(),
|
||||
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern"),
|
||||
format_with(|f: &mut PyFormatter| {
|
||||
let comments = f.context().comments();
|
||||
|
||||
for comment in comments.leading_trailing_comments(pattern) {
|
||||
// This is a lie, but let's go with it.
|
||||
comment.mark_formatted();
|
||||
}
|
||||
|
||||
// Replace the whole `format_with` with `pattern.format()` once pattern formatting is implemented.
|
||||
not_yet_implemented_custom_text("NOT_YET_IMPLEMENTED_Pattern", pattern).fmt(f)
|
||||
}),
|
||||
]
|
||||
)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue