From b2fc41dcccf54c60bb1d08ad618589b9cf85d453 Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Mon, 15 Dec 2025 08:36:04 -0600 Subject: [PATCH] add dedicated small fixtures for fluent formatting --- .../test/fixtures/ruff/fluent.options.json | 1 + .../resources/test/fixtures/ruff/fluent.py | 35 ++++ .../tests/snapshots/format@fluent.py.snap | 163 ++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.options.json create mode 100644 crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py create mode 100644 crates/ruff_python_formatter/tests/snapshots/format@fluent.py.snap diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.options.json b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.options.json new file mode 100644 index 0000000000..f69dec6066 --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.options.json @@ -0,0 +1 @@ +[{"line_width":8}] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py new file mode 100644 index 0000000000..0b0b76f1dd --- /dev/null +++ b/crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py @@ -0,0 +1,35 @@ +# Fixtures for fluent formatting of call chains +# Note that `fluent.options.json` sets line width to 8 + + +x = a.b() + +x = a.b().c() + +x = a.b().c().d + +x = a.b.c.d().e() + +x = a.b.c().d.e().f.g() + +# Consecutive calls/subscripts are grouped together +# for the purposes of fluent formatting (though, as 2025.12.15, +# there may be a break inside of one of these +# calls/subscripts, but that is unrelated to the fluent format.) + +x = a()[0]().b().c() + +x = a.b()[0].c.d()[1]().e + +# Parentheses affect both where the root of the call +# chain is and how many calls we require before applying +# fluent formatting (just 1, in the presence of a parenthesized +# root, as of 2025.12.15.) + +x = (a).b() + +x = (a()).b() + +x = (a.b()).d.e() + +x = (a.b().d).e() diff --git a/crates/ruff_python_formatter/tests/snapshots/format@fluent.py.snap b/crates/ruff_python_formatter/tests/snapshots/format@fluent.py.snap new file mode 100644 index 0000000000..73213398d5 --- /dev/null +++ b/crates/ruff_python_formatter/tests/snapshots/format@fluent.py.snap @@ -0,0 +1,163 @@ +--- +source: crates/ruff_python_formatter/tests/fixtures.rs +input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fluent.py +--- +## Input +```python +# Fixtures for fluent formatting of call chains +# Note that `fluent.options.json` sets line width to 8 + + +x = a.b() + +x = a.b().c() + +x = a.b().c().d + +x = a.b.c.d().e() + +x = a.b.c().d.e().f.g() + +# Consecutive calls/subscripts are grouped together +# for the purposes of fluent formatting (though, as 2025.12.15, +# there may be a break inside of one of these +# calls/subscripts, but that is unrelated to the fluent format.) + +x = a()[0]().b().c() + +x = a.b()[0].c.d()[1]().e + +# Parentheses affect both where the root of the call +# chain is and how many calls we require before applying +# fluent formatting (just 1, in the presence of a parenthesized +# root, as of 2025.12.15.) + +x = (a).b() + +x = (a()).b() + +x = (a.b()).d.e() + +x = (a.b().d).e() +``` + +## Outputs +### Output 1 +``` +indent-style = space +line-width = 8 +indent-width = 4 +quote-style = Double +line-ending = LineFeed +magic-trailing-comma = Respect +docstring-code = Disabled +docstring-code-line-width = "dynamic" +preview = Disabled +target_version = 3.10 +source_type = Python +``` + +```python +# Fixtures for fluent formatting of call chains +# Note that `fluent.options.json` sets line width to 8 + + +x = a.b() + +x = a.b().c() + +x = ( + a.b() + .c() + .d +) + +x = a.b.c.d().e() + +x = ( + a.b.c() + .d.e() + .f.g() +) + +# Consecutive calls/subscripts are grouped together +# for the purposes of fluent formatting (though, as 2025.12.15, +# there may be a break inside of one of these +# calls/subscripts, but that is unrelated to the fluent format.) + +x = ( + a()[ + 0 + ]() + .b() + .c() +) + +x = ( + a.b()[ + 0 + ] + .c.d()[ + 1 + ]() + .e +) + +# Parentheses affect both where the root of the call +# chain is and how many calls we require before applying +# fluent formatting (just 1, in the presence of a parenthesized +# root, as of 2025.12.15.) + +x = ( + a +).b() + +x = ( + a() +).b() + +x = ( + a.b() +).d.e() + +x = ( + a.b().d +).e() +``` + + +#### Preview changes +```diff +--- Stable ++++ Preview +@@ -7,7 +7,8 @@ + x = a.b().c() + + x = ( +- a.b() ++ a ++ .b() + .c() + .d + ) +@@ -15,7 +16,8 @@ + x = a.b.c.d().e() + + x = ( +- a.b.c() ++ a.b ++ .c() + .d.e() + .f.g() + ) +@@ -34,7 +36,8 @@ + ) + + x = ( +- a.b()[ ++ a ++ .b()[ + 0 + ] + .c.d()[ +```