Format the comment content (#4786)

This commit is contained in:
Micha Reiser 2023-06-02 13:22:34 +02:00 committed by GitHub
parent 602b4b3519
commit 4cd4b37e74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 94 deletions

View file

@ -349,7 +349,7 @@ instruction()#comment with bad spacing
# yup
for element in collection.select_elements()
# right
@@ -140,34 +132,26 @@
@@ -140,28 +132,20 @@
# and round and round we go
# and round and round we go
@ -386,13 +386,6 @@ instruction()#comment with bad spacing
#######################
### SECTION COMMENT ###
#######################
-instruction() # comment with bad spacing
+instruction() #comment with bad spacing
# END COMMENTS
# MORE END COMMENTS
```
## Ruff Output
@ -551,7 +544,7 @@ class Test:
#######################
instruction() #comment with bad spacing
instruction() # comment with bad spacing
# END COMMENTS
# MORE END COMMENTS

View file

@ -1,53 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py
---
## Input
```py
# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
#%%
# %%
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -2,5 +2,5 @@
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
-# %%
+#%%
# %%
```
## Ruff Output
```py
# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
#%%
# %%
```
## Black Output
```py
# The percent-percent comments are Spyder IDE cells.
# Both `#%%`` and `# %%` are accepted, so `black` standardises
# to the latter.
# %%
# %%
```

View file

@ -42,23 +42,19 @@ def function(a:int=42):
+ # DEFAULT_TYPE_ATTRIBUTES,
)
-
-result = 1 # A simple comment
result = 1 # A simple comment
-result = (1,) # Another one
-
-result = 1 #  type: ignore
-result = 1 # This comment is talking about type: ignore
-square = Square(4) #  type: Optional[Square]
+result = ( 1, ) # Another one
result = 1 #  type: ignore
result = 1 # This comment is talking about type: ignore
square = Square(4) #  type: Optional[Square]
-
-
-def function(a: int = 42):
- """This docstring is already formatted
- a
- b
+result = 1 # A simple comment
+result = ( 1, ) # Another one
+result = 1 # type: ignore
+result = 1 # This comment is talking about type: ignore
+square = Square(4) # type: Optional[Square]
+def function(a:int=42):
+ """ This docstring is already formatted
+ a
@ -76,11 +72,11 @@ def function(a:int=42):
from .config import ( ConfigTypeAttributes, Int, Path, # String,
# DEFAULT_TYPE_ATTRIBUTES,
)
result = 1 # A simple comment
result = ( 1, ) # Another one
result = 1 # type: ignore
result = 1 # This comment is talking about type: ignore
square = Square(4) # type: Optional[Square]
result = 1 # A simple comment
result = ( 1, ) # Another one
result = 1 #  type: ignore
result = 1 # This comment is talking about type: ignore
square = Square(4) #  type: Optional[Square]
def function(a:int=42):
""" This docstring is already formatted
a

View file

@ -19,22 +19,19 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu
+++ Ruff
@@ -1,4 +1,4 @@
-a = "this is some code"
-b = 5 # fmt:skip
-c = 9 # fmt: skip
-d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
+a = "this is some code"
+b = 5 #fmt:skip
+c = 9 #fmt: skip
+d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #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
b = 5 # fmt:skip
c = 9 # fmt: skip
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
```
## Black Output