mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-04 01:36:46 +00:00
Add tests for skip magic trailing comma
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This PR adds tests that verify that the magic trailing comma is not respected if disabled in the formatter options. Our test setup now allows to create a `<fixture-name>.options.json` file that contains an array of configurations that should be tested. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan It's all about tests :) <!-- How was it tested? -->
This commit is contained in:
parent
dd0d1afb66
commit
f18a1f70de
27 changed files with 268 additions and 79 deletions
|
|
@ -109,8 +109,6 @@ x53 = (
|
|||
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
|
|
@ -196,3 +194,4 @@ x53 = a.askjdfahdlskjflsajfadhsaf.akjdsf.aksjdlfadhaljsashdfljaf.askjdflhasfdlas
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -200,8 +200,6 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}:
|
|||
updates.append(UserPresenceState.default(user_id))
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
(
|
||||
|
|
@ -447,3 +445,4 @@ for (
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -70,8 +70,6 @@ if (
|
|||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if (
|
||||
|
|
@ -141,3 +139,4 @@ if (
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -67,8 +67,6 @@ return 1 == 2 and (
|
|||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
a == b
|
||||
|
|
@ -187,3 +185,4 @@ return (
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ a = {
|
|||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# before
|
||||
|
|
@ -131,3 +129,4 @@ a = {
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ a3 = [
|
|||
]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Dangling comment placement in empty lists
|
||||
|
|
@ -33,3 +31,4 @@ a3 = [
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -88,8 +88,6 @@ e202 = "e"[a() :: a()]
|
|||
e210 = "e"[a() : 1 :]
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Handle comments both when lower and upper exist and when they don't
|
||||
|
|
@ -175,3 +173,4 @@ e210 = "e"[NOT_IMPLEMENTED_call() : 1 :]
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -58,8 +58,6 @@ String \"\"\"
|
|||
'''
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
"' test"
|
||||
|
|
@ -117,3 +115,4 @@ String \"\"\"
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ h2 = ((((1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurp
|
|||
h3 = 1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq"
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Non-wrapping parentheses checks
|
||||
|
|
@ -264,3 +262,4 @@ h3 = (
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -144,8 +144,6 @@ if not \
|
|||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if (
|
||||
|
|
@ -300,3 +298,4 @@ if not a:
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/skip_magic_trailing_comma.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"last with trailing comma",
|
||||
)
|
||||
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"last without trailing comma"
|
||||
)
|
||||
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"third entry",
|
||||
"fourth entry",
|
||||
"fifth entry",
|
||||
"sixt entry",
|
||||
"seventh entry",
|
||||
"eigth entry",
|
||||
)
|
||||
```
|
||||
|
||||
## Outputs
|
||||
### Output 1
|
||||
```
|
||||
indent-style = Spaces, size: 4
|
||||
line-width = 88
|
||||
quote-style = Double
|
||||
magic-trailing-comma = Respect
|
||||
```
|
||||
|
||||
```py
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"last with trailing comma",
|
||||
)
|
||||
|
||||
("First entry", "Second entry", "last without trailing comma")
|
||||
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"third entry",
|
||||
"fourth entry",
|
||||
"fifth entry",
|
||||
"sixt entry",
|
||||
"seventh entry",
|
||||
"eigth entry",
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
### Output 2
|
||||
```
|
||||
indent-style = Spaces, size: 4
|
||||
line-width = 88
|
||||
quote-style = Double
|
||||
magic-trailing-comma = Ignore
|
||||
```
|
||||
|
||||
```py
|
||||
("First entry", "Second entry", "last with trailing comma")
|
||||
|
||||
("First entry", "Second entry", "last without trailing comma")
|
||||
|
||||
(
|
||||
"First entry",
|
||||
"Second entry",
|
||||
"third entry",
|
||||
"fourth entry",
|
||||
"fifth entry",
|
||||
"sixt entry",
|
||||
"seventh entry",
|
||||
"eigth entry",
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
@ -16,8 +16,6 @@ a2 = (
|
|||
a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfal = 1
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# break left hand side
|
||||
|
|
@ -31,3 +29,4 @@ a = asdf = fjhalsdljfalflaflapamsakjsdhflakjdslfjhalsdljfalflaflapamsakjsdhflakj
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ while True: # block comment
|
|||
# post comment
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# leading comment
|
||||
|
|
@ -23,3 +21,4 @@ while True: # block comment
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ class Test(Aaaa): # trailing comment
|
|||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
class Test(
|
||||
|
|
@ -95,3 +93,4 @@ class Test(Aaaa): # trailing comment
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ for x in (): # type: int
|
|||
...
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
for x in y: # trailing test comment
|
||||
|
|
@ -85,3 +83,4 @@ for x in (): # type: int
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -239,8 +239,6 @@ def f42(
|
|||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Dangling comments
|
||||
|
|
@ -516,3 +514,4 @@ def f42(
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79,8 +79,6 @@ else: # Comment
|
|||
pass
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
if x == y: # trailing if condition
|
||||
|
|
@ -158,3 +156,4 @@ else: # Comment
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ while (
|
|||
print("Do something")
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
while 34: # trailing test comment
|
||||
|
|
@ -74,3 +72,4 @@ while (
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ while b == 20:
|
|||
e = 50 # one empty line before
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Output
|
||||
```py
|
||||
# Removes the line above
|
||||
|
|
@ -79,3 +77,4 @@ e = 50 # one empty line before
|
|||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue