mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Support fmt: skip
for simple-statements and decorators (#6561)
This commit is contained in:
parent
e3ecbe660e
commit
4dc32a00d0
40 changed files with 545 additions and 316 deletions
|
@ -238,7 +238,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
|
||||
|
||||
@@ -178,7 +180,7 @@
|
||||
@@ -178,14 +180,18 @@
|
||||
$
|
||||
""",
|
||||
# fmt: off
|
||||
|
@ -247,6 +247,18 @@ d={'a':1,
|
|||
# fmt: on
|
||||
)
|
||||
|
||||
|
||||
def single_literal_yapf_disable():
|
||||
"""Black does not support this."""
|
||||
- BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||
+ BAZ = {
|
||||
+ (1, 2, 3, 4),
|
||||
+ (5, 6, 7, 8),
|
||||
+ (9, 10, 11, 12)
|
||||
+ } # yapf: disable
|
||||
|
||||
|
||||
cfg.rule(
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -441,7 +453,11 @@ def long_lines():
|
|||
|
||||
def single_literal_yapf_disable():
|
||||
"""Black does not support this."""
|
||||
BAZ = {(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12)} # yapf: disable
|
||||
BAZ = {
|
||||
(1, 2, 3, 4),
|
||||
(5, 6, 7, 8),
|
||||
(9, 10, 11, 12)
|
||||
} # yapf: disable
|
||||
|
||||
|
||||
cfg.rule(
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,3 +1,3 @@
|
||||
a, b = 1, 2
|
||||
-c = 6 # fmt: skip
|
||||
+c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a, b = 1, 2
|
||||
c = 6 # fmt: skip
|
||||
d = 5
|
||||
```
|
||||
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
l3 = ["I have", "trailing comma", "so I should be braked",]
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -3,7 +3,11 @@
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
-l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
+l2 = [
|
||||
+ "But this list shouldn't",
|
||||
+ "even though it also has",
|
||||
+ "way too many characters in it",
|
||||
+] # fmt: skip
|
||||
l3 = [
|
||||
"I have",
|
||||
"trailing comma",
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
l1 = [
|
||||
"This list should be broken up",
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
l2 = [
|
||||
"But this list shouldn't",
|
||||
"even though it also has",
|
||||
"way too many characters in it",
|
||||
] # fmt: skip
|
||||
l3 = [
|
||||
"I have",
|
||||
"trailing comma",
|
||||
"so I should be braked",
|
||||
]
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
l1 = [
|
||||
"This list should be broken up",
|
||||
"into multiple lines",
|
||||
"because it is way too long",
|
||||
]
|
||||
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
|
||||
l3 = [
|
||||
"I have",
|
||||
"trailing comma",
|
||||
"so I should be braked",
|
||||
]
|
||||
```
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 #fmt:skip
|
||||
c = 9 #fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,4 +1,4 @@
|
||||
a = "this is some code"
|
||||
-b = 5 # fmt:skip
|
||||
+b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
a = "this is some code"
|
||||
b = 5 # fmt:skip
|
||||
c = 9 # fmt: skip
|
||||
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
|
||||
```
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/decorators.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
|
||||
@FormattedDecorator(a =b)
|
||||
# leading comment
|
||||
@MyDecorator( # dangling comment
|
||||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip
|
||||
# leading class comment
|
||||
class Test:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@FormattedDecorator(a =b)
|
||||
# leading comment
|
||||
@MyDecorator( # dangling comment
|
||||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip
|
||||
# leading class comment
|
||||
def test():
|
||||
pass
|
||||
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
@FormattedDecorator(a=b)
|
||||
# leading comment
|
||||
@MyDecorator( # dangling comment
|
||||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip
|
||||
# leading class comment
|
||||
class Test:
|
||||
pass
|
||||
|
||||
|
||||
@FormattedDecorator(a=b)
|
||||
# leading comment
|
||||
@MyDecorator( # dangling comment
|
||||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip
|
||||
# leading class comment
|
||||
def test():
|
||||
pass
|
||||
```
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/docstrings.py
|
||||
---
|
||||
## Input
|
||||
```py
|
||||
def test():
|
||||
# leading comment
|
||||
""" This docstring does not
|
||||
get formatted
|
||||
""" # fmt: skip
|
||||
# trailing comment
|
||||
|
||||
def test():
|
||||
# leading comment
|
||||
""" This docstring gets formatted
|
||||
""" # trailing comment
|
||||
|
||||
and_this + gets + formatted + too
|
||||
```
|
||||
|
||||
## Output
|
||||
```py
|
||||
def test():
|
||||
# leading comment
|
||||
""" This docstring does not
|
||||
get formatted
|
||||
""" # fmt: skip
|
||||
# trailing comment
|
||||
|
||||
|
||||
def test():
|
||||
# leading comment
|
||||
"""This docstring gets formatted""" # trailing comment
|
||||
|
||||
and_this + gets + formatted + too
|
||||
```
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue