mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
format StmtBreak (#5158)
## Summary format `StmtBreak` trying to learn how to help out with the formatter. starting simple ## Test Plan new snapshot test
This commit is contained in:
parent
be107dad64
commit
4b9b6829dc
3 changed files with 35 additions and 4 deletions
5
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py
vendored
Normal file
5
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# leading comment
|
||||||
|
while True: # block comment
|
||||||
|
# inside comment
|
||||||
|
break # break comment
|
||||||
|
# post comment
|
|
@ -0,0 +1,25 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff_python_formatter/src/lib.rs
|
||||||
|
expression: snapshot
|
||||||
|
---
|
||||||
|
## Input
|
||||||
|
```py
|
||||||
|
# leading comment
|
||||||
|
while True: # block comment
|
||||||
|
# inside comment
|
||||||
|
break # break comment
|
||||||
|
# post comment
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Output
|
||||||
|
```py
|
||||||
|
# leading comment
|
||||||
|
while True: # block comment
|
||||||
|
# inside comment
|
||||||
|
break # break comment
|
||||||
|
# post comment
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter};
|
use crate::{FormatNodeRule, PyFormatter};
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::prelude::text;
|
||||||
|
use ruff_formatter::{Format, FormatResult};
|
||||||
use rustpython_parser::ast::StmtBreak;
|
use rustpython_parser::ast::StmtBreak;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct FormatStmtBreak;
|
pub struct FormatStmtBreak;
|
||||||
|
|
||||||
impl FormatNodeRule<StmtBreak> for FormatStmtBreak {
|
impl FormatNodeRule<StmtBreak> for FormatStmtBreak {
|
||||||
fn fmt_fields(&self, item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> {
|
fn fmt_fields(&self, _item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> {
|
||||||
write!(f, [not_yet_implemented(item)])
|
text("break").fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue