From bc92627e5400f86e9639f8913dcd90990663548f Mon Sep 17 00:00:00 2001 From: David Szotten Date: Sat, 17 Jun 2023 08:47:51 +0100 Subject: [PATCH] format StmtBreak --- .../test/fixtures/ruff/statement/break.py | 5 ++++ ...tests__ruff_test__statement__break_py.snap | 25 +++++++++++++++++++ .../src/statement/stmt_break.rs | 9 ++++--- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py create mode 100644 crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py new file mode 100644 index 0000000000000..c171873a02b24 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/break.py @@ -0,0 +1,5 @@ +# leading comment +while True: # block comment + # inside comment + break # break comment + # post comment diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap new file mode 100644 index 0000000000000..3087672f754b8 --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__ruff_test__statement__break_py.snap @@ -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 +``` + + diff --git a/crates/ruff_python_formatter/src/statement/stmt_break.rs b/crates/ruff_python_formatter/src/statement/stmt_break.rs index f3e9af3ca22ba..53cb75f6ccb09 100644 --- a/crates/ruff_python_formatter/src/statement/stmt_break.rs +++ b/crates/ruff_python_formatter/src/statement/stmt_break.rs @@ -1,12 +1,13 @@ -use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; -use ruff_formatter::{write, Buffer, FormatResult}; +use crate::{FormatNodeRule, PyFormatter}; +use ruff_formatter::prelude::text; +use ruff_formatter::{Format, FormatResult}; use rustpython_parser::ast::StmtBreak; #[derive(Default)] pub struct FormatStmtBreak; impl FormatNodeRule for FormatStmtBreak { - fn fmt_fields(&self, item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> { - write!(f, [not_yet_implemented(item)]) + fn fmt_fields(&self, _item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> { + text("break").fmt(f) } }