-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 24 additions & 9 deletions
33
crates/ruff_python_formatter/src/pattern/pattern_match_star.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
use ruff_formatter::{prelude::text, write, Buffer, FormatResult}; | ||
use ruff_python_ast::PatternMatchStar; | ||
|
||
use crate::{not_yet_implemented_custom_text, FormatNodeRule, PyFormatter}; | ||
use crate::comments::{dangling_comments, SourceComment}; | ||
use crate::AsFormat; | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
|
||
#[derive(Default)] | ||
pub struct FormatPatternMatchStar; | ||
|
||
impl FormatNodeRule<PatternMatchStar> for FormatPatternMatchStar { | ||
fn fmt_fields(&self, item: &PatternMatchStar, f: &mut PyFormatter) -> FormatResult<()> { | ||
write!( | ||
f, | ||
[not_yet_implemented_custom_text( | ||
"*NOT_YET_IMPLEMENTED_PatternMatchStar", | ||
item | ||
)] | ||
) | ||
let PatternMatchStar { name, .. } = item; | ||
|
||
let comments = f.context().comments().clone(); | ||
let dangling = comments.dangling(item); | ||
|
||
write!(f, [text("*"), dangling_comments(dangling)])?; | ||
|
||
match name { | ||
Some(name) => write!(f, [name.format()]), | ||
None => write!(f, [text("_")]), | ||
} | ||
} | ||
|
||
fn fmt_dangling_comments( | ||
&self, | ||
_dangling_comments: &[SourceComment], | ||
_f: &mut PyFormatter, | ||
) -> FormatResult<()> { | ||
// Handled by `fmt_fields` | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.