-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test and basic implementation for formatter preview mode #8044
Changes from all commits
9d05306
a368883
b137e2a
72d7c82
4c38a01
a6ae408
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,45 @@ | ||
--- | ||
source: crates/ruff_python_formatter/tests/fixtures.rs | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/assign_breaking.py | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/preview.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we instead run every test under preview and non-preview? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the cost is not too high that seems ideal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Having both versions makes it hard to see what actually changed given our large snapshots, so i opted for instead adding the diff as separate code block if there is one. I also changed all non-function/class tests to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep |
||
--- | ||
## Input | ||
```py | ||
# Below is black stable style | ||
# In preview style, black always breaks the right side first | ||
""" | ||
Black's `Preview.module_docstring_newlines` | ||
""" | ||
first_stmt_after_module_level_docstring = 1 | ||
|
||
if True: | ||
|
||
class CachedRepository: | ||
# Black's `Preview.dummy_implementations` | ||
def get_release_info(self): ... | ||
|
||
|
||
def raw_docstring(): | ||
|
||
r"""Black's `Preview.accept_raw_docstrings` | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
|
||
def reference_docstring_newlines(): | ||
|
||
"""A regular docstring for comparison | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
|
||
class RemoveNewlineBeforeClassDocstring: | ||
|
||
"""Black's `Preview.no_blank_line_before_class_docstring`""" | ||
|
||
|
||
def f(): | ||
"""Black's `Preview.prefer_splitting_right_hand_side_of_assignments`""" | ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ | ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | ||
] = cccccccc.ccccccccccccc.cccccccc | ||
|
@@ -52,10 +84,41 @@ preview = Disabled | |
``` | ||
|
||
```py | ||
# Below is black stable style | ||
# In preview style, black always breaks the right side first | ||
""" | ||
Black's `Preview.module_docstring_newlines` | ||
""" | ||
first_stmt_after_module_level_docstring = 1 | ||
|
||
|
||
class CachedRepository: | ||
# Black's `Preview.dummy_implementations` | ||
def get_release_info(self): | ||
... | ||
|
||
|
||
def raw_docstring(): | ||
r"""Black's `Preview.accept_raw_docstrings` | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
if True: | ||
|
||
def reference_docstring_newlines(): | ||
"""A regular docstring for comparison | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
|
||
class RemoveNewlineBeforeClassDocstring: | ||
|
||
"""Black's `Preview.no_blank_line_before_class_docstring`""" | ||
|
||
|
||
def f(): | ||
"""Black's `Preview.prefer_splitting_right_hand_side_of_assignments`""" | ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ | ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | ||
] = cccccccc.ccccccccccccc.cccccccc | ||
|
@@ -100,10 +163,40 @@ preview = Enabled | |
``` | ||
|
||
```py | ||
# Below is black stable style | ||
# In preview style, black always breaks the right side first | ||
""" | ||
Black's `Preview.module_docstring_newlines` | ||
""" | ||
first_stmt_after_module_level_docstring = 1 | ||
|
||
|
||
class CachedRepository: | ||
# Black's `Preview.dummy_implementations` | ||
def get_release_info(self): ... | ||
|
||
|
||
def raw_docstring(): | ||
r"""Black's `Preview.accept_raw_docstrings` | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
|
||
def reference_docstring_newlines(): | ||
"""A regular docstring for comparison | ||
a | ||
b | ||
""" | ||
pass | ||
|
||
|
||
class RemoveNewlineBeforeClassDocstring: | ||
|
||
"""Black's `Preview.no_blank_line_before_class_docstring`""" | ||
|
||
|
||
if True: | ||
def f(): | ||
"""Black's `Preview.prefer_splitting_right_hand_side_of_assignments`""" | ||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ | ||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | ||
] = cccccccc.ccccccccccccc.cccccccc | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we skip this if
options.preview == Enabled
when using a test specific options file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the no-options-file branch; i think it's better to not mix them to avoid combinatorial explosion