diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py.expect index 3ada815d85..f9140384d5 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/attribute_access_on_number_literals.py.expect @@ -19,4 +19,4 @@ if (10).real: ... y = 100[no] -y = 100(no) \ No newline at end of file +y = 100(no) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py.expect index bc63dc6882..9f69d32873 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/beginning_backslash.py.expect @@ -1 +1 @@ -print("hello, world") \ No newline at end of file +print("hello, world") diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py.expect index c0cac519f3..e626bbbf73 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/bracketmatch.py.expect @@ -1,4 +1,4 @@ for ((x in {}) or {})["a"] in x: pass pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip()) -lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x \ No newline at end of file +lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py.expect index 1adfe6d16a..0c4c3c96e7 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py.expect @@ -27,4 +27,4 @@ def class_under_the_func_with_blank_parentheses(): class NormalClass: def func_for_testing(self, first, second): sum = first + second - return sum \ No newline at end of file + return sum diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py.expect index b39ac3f13e..b7f6ed401f 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py.expect @@ -162,4 +162,4 @@ class ClassWithDecoInitAndVarsAndDocstringWithInner2: @deco def __init__(self): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py.expect index 3a895ca55d..96d238ff15 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/collections.py.expect @@ -96,4 +96,4 @@ if True: WaiterConfig={ "Delay": 5, }, - ) \ No newline at end of file + ) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py.expect index 80f4ae11fd..209204f0b6 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comment_after_escaped_newline.py.expect @@ -3,4 +3,4 @@ def bob(): # pylint: disable=W9016 def bobtwo(): # some comment here - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py.expect index d4bd0e0f13..c3957a8a0c 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments2.py.expect @@ -170,4 +170,4 @@ class Test: instruction() # comment with bad spacing # END COMMENTS -# MORE END COMMENTS \ No newline at end of file +# MORE END COMMENTS diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py.expect index f964bee665..c81958dc11 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments3.py.expect @@ -45,4 +45,4 @@ def func(): ) -# %% \ No newline at end of file +# %% diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py.expect index 073d1e36f9..2147d41c9d 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments4.py.expect @@ -91,4 +91,4 @@ def foo3(list_a, list_b): db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) ) .filter(User.xyz.is_(None)) - ) \ No newline at end of file + ) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py.expect index 23a56e5679..bda40619f6 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments5.py.expect @@ -70,4 +70,4 @@ def g(): if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py.expect index 2b9b6eda6d..735c6aa6d7 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments6.py.expect @@ -115,4 +115,4 @@ call_to_some_function_asdf( [AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, AAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBB], # type: ignore ) -aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] \ No newline at end of file +aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py.expect index 672dca0c03..c0f135206a 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments8.py.expect @@ -3,4 +3,4 @@ # to the latter. # %% -# %% \ No newline at end of file +# %% diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py.expect index 1071bc2a23..a36048ab1b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments9.py.expect @@ -158,4 +158,4 @@ def foo(): @decorator1 # A standalone comment def bar(): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py.expect index c3b90247f8..9cf3fbcc85 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/comments_non_breaking_space.py.expect @@ -20,4 +20,4 @@ def function(a: int = 42): """ # There's a NBSP + 3 spaces before # And 4 spaces on the next line - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py.expect index 0f590039a8..e429f15e66 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition.py.expect @@ -178,4 +178,4 @@ class C: key8: value8, key9: value9, } - ) \ No newline at end of file + ) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py.expect index 0f590039a8..e429f15e66 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/composition_no_trailing_comma.py.expect @@ -178,4 +178,4 @@ class C: key8: value8, key9: value9, } - ) \ No newline at end of file + ) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py.expect index be9808041e..a8f12a5b51 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring.py.expect @@ -216,4 +216,4 @@ def stable_quote_normalization_with_immediate_inner_single_quote(self): """' - """ \ No newline at end of file + """ diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py.expect index 0afda15012..6fea860adf 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py.expect @@ -1,4 +1,4 @@ # Make sure when the file ends with class's docstring, # It doesn't add extra blank lines. class ClassWithDocstring: - """A docstring.""" \ No newline at end of file + """A docstring.""" diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py.expect index 94efd7b60d..dc453dcc76 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_preview.py.expect @@ -45,4 +45,4 @@ def single_quote_docstring_over_line_limit(): def single_quote_docstring_over_line_limit2(): - "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)." \ No newline at end of file + "We do not want to put the closing quote on a new line as that is invalid (see GH-3141)." diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py.expect index a4f759b379..346226178e 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/empty_lines.py.expect @@ -86,4 +86,4 @@ def g(): syms.arglist, syms.argument, }: - return NO \ No newline at end of file + return NO diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.py.expect index ac24fdc41a..08be5ea501 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/expression.py.expect @@ -114,7 +114,7 @@ call( arg, another, kwarg="hey", - **kwargs + **kwargs, ) # note: no trailing comma pre-3.6 call(*gidgets[:2]) call(a, *gidgets[:2]) @@ -367,4 +367,4 @@ bbbb >> bbbb * bbbb ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) last_call() -# standalone comment at ENDMARKER \ No newline at end of file +# standalone comment at ENDMARKER diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py.expect index a0ccf5d2b7..8631f8eaaa 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff.py.expect @@ -221,4 +221,4 @@ yield 'hello' # No formatting to the end of the file l=[1,2,3] d={'a':1, - 'b':2} \ No newline at end of file + 'b':2} diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py.expect index aa116f636a..e8657c749b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff2.py.expect @@ -37,4 +37,4 @@ def test_calculate_fades(): (None, 4, 0, 0, 10, 0, 0, 6, 10), ] -# fmt: on \ No newline at end of file +# fmt: on diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py.expect index 3cbffdbc3c..4b84351a81 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff3.py.expect @@ -12,4 +12,4 @@ x = [ ] # fmt: on -x = [1, 2, 3, 4] \ No newline at end of file +x = [1, 2, 3, 4] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py.expect index 4ec8bf850d..237fde0fdb 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff4.py.expect @@ -17,4 +17,4 @@ def f(): ] ) def f(): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py.expect index 4a26d3b8ee..69b5430b8b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtonoff5.py.expect @@ -84,4 +84,4 @@ if x: # fmt: off elif unformatted: # fmt: on - will_be_formatted() \ No newline at end of file + will_be_formatted() diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py.expect index cd89a7d48a..1d5836fc03 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip.py.expect @@ -1,3 +1,3 @@ a, b = 1, 2 c = 6 # fmt: skip -d = 5 \ No newline at end of file +d = 5 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py.expect index 1b3b0956f8..76072ba215 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip2.py.expect @@ -8,4 +8,4 @@ l3 = [ "I have", "trailing comma", "so I should be braked", -] \ No newline at end of file +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py.expect index e6591cd8c0..60a07afcfd 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip3.py.expect @@ -7,4 +7,4 @@ e = 5 f = [ "This is a very long line that should be formatted into a clearer line ", "by rearranging.", -] \ No newline at end of file +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py.expect index d70353026c..b083eccdf1 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip4.py.expect @@ -4,4 +4,4 @@ l = [ 1, 2, 3, -] \ No newline at end of file +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py.expect index b4e502a68c..43ff1ed0ea 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip5.py.expect @@ -6,4 +6,4 @@ if ( ): print("I'm good!") else: - print("I'm bad") \ No newline at end of file + print("I'm bad") diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py.expect index c7e65f5378..cf829dbdb1 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip6.py.expect @@ -2,4 +2,4 @@ class A: def f(self): for line in range(10): if True: - pass # fmt: skip \ No newline at end of file + pass # fmt: skip diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py.expect index 72ded7d7dc..349575deb5 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip7.py.expect @@ -1,4 +1,4 @@ a = "this is some code" b = 5 # fmt:skip c = 9 # fmt: skip -d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip \ No newline at end of file +d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py.expect index e2b0a87ce0..38e9c2a9f4 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py.expect @@ -59,4 +59,4 @@ with give_me_context( unformatted, args ): # fmt: skip async def test_async_with(): async with give_me_async_context( unformatted, args ): # fmt: skip - print("Do something") \ No newline at end of file + print("Do something") diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py.expect index 6ad85cf259..0c6538c5bf 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fstring.py.expect @@ -6,4 +6,4 @@ f'some f-string with {a} {few(""):.2f} {formatted.values!r}' f"{f'''{'nested'} inner'''} outer" f"\"{f'{nested} inner'}\" outer" f"space between opening braces: { {a for a in (1, 2, 3)}}" -f'Hello \'{tricky + "example"}\'' \ No newline at end of file +f'Hello \'{tricky + "example"}\'' diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py.expect index 51c20d8c28..1c26d01cb2 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function.py.expect @@ -145,4 +145,4 @@ def f( def __await__(): - return (yield) \ No newline at end of file + return (yield) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py.expect index 9e53dd323b..f85930c364 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py.expect @@ -63,4 +63,4 @@ else: with hmm_but_this_should_get_two_preceding_newlines(): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py.expect index e6324cc78b..2411226eb4 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function_trailing_comma.py.expect @@ -111,4 +111,4 @@ some_module.some_function( argument4, argument5, argument6, -) \ No newline at end of file +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py.expect index aa82662d27..3254f604fc 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/import_spacing.py.expect @@ -61,4 +61,4 @@ __all__ = ( + queues.__all__ + streams.__all__ + tasks.__all__ -) \ No newline at end of file +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py.expect index 2ba01ee747..e816134f1f 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/one_element_subscript.py.expect @@ -19,4 +19,4 @@ small_list = [ ] list_of_types = [ tuple[int,], -] \ No newline at end of file +] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py.expect index 72fa4d14b6..ffc2be7e78 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/power_op_spacing.py.expect @@ -60,4 +60,4 @@ if hasattr(view, "sum_of_weights"): return np.divide( where=view.sum_of_weights_of_weight_long**2 > view.sum_of_weights_squared, # type: ignore -) \ No newline at end of file +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py.expect index d60abb5ff3..9a9ef1356e 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/prefer_rhs_split_reformatted.py.expect @@ -18,4 +18,4 @@ # exactly line length limit + 1, it won't be split like that. xxxxxxxxx_yyy_zzzzzzzz[ xx.xxxxxx(x_yyy_zzzzzz.xxxxx[0]), x_yyy_zzzzzz.xxxxxx(xxxx=1) -] = 1 \ No newline at end of file +] = 1 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py.expect index bb4e3f1a61..91e7eb39e1 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_await_parens.py.expect @@ -90,4 +90,4 @@ async def main(): async def main(): - await (yield) \ No newline at end of file + await (yield) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py.expect index 3faee3dc72..9d2d4a4445 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_except_parens.py.expect @@ -39,4 +39,4 @@ except ( some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, ) as err: - raise err \ No newline at end of file + raise err diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py.expect index c30502a90c..8f347f71bd 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_for_brackets.py.expect @@ -24,4 +24,4 @@ for ( # Test deeply nested brackets for k, v in d.items(): - print(k, v) \ No newline at end of file + print(k, v) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py.expect index 47134235e6..dff03aa7fe 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py.expect @@ -75,4 +75,4 @@ with open("/path/to/file.txt", mode="w") as file: with open("/path/to/file.txt", mode="r") as read_file: with open("/path/to/output_file.txt", mode="w") as write_file: - write_file.writelines(read_file.readlines()) \ No newline at end of file + write_file.writelines(read_file.readlines()) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py.expect index e63581778b..a84f4c319b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_parens.py.expect @@ -82,4 +82,4 @@ def example7(): def example8(): - return None \ No newline at end of file + return None diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py.expect index b78d1ed37f..06880ecbe0 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/return_annotation_brackets.py.expect @@ -117,4 +117,4 @@ def foo() -> ( int, ] ): - return 2 \ No newline at end of file + return 2 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py.expect index 855b0d5b3b..74143d2b55 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/skip_magic_trailing_comma.py.expect @@ -22,4 +22,4 @@ func1(arg1).func2(arg2).func3(arg3).func4(arg4).func5(arg5) (a, b, c, d) = func1(arg1) and func2(arg2) -func(argument1, (one, two), argument4, argument5, argument6) \ No newline at end of file +func(argument1, (one, two), argument4, argument5, argument6) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py.expect index 8bdfd398d6..165117cdcb 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/slices.py.expect @@ -28,4 +28,4 @@ ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:] ham[lower:upper], ham[lower:upper:], ham[lower::step] # ham[lower+offset : upper+offset] ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)] -ham[lower + offset : upper + offset] \ No newline at end of file +ham[lower + offset : upper + offset] diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py.expect index 83e95c5d76..43a57736fb 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/string_prefixes.py.expect @@ -17,4 +17,4 @@ def docstring_singleline(): def docstring_multiline(): R""" clear out all of the issues opened in that time :p - """ \ No newline at end of file + """ diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py.expect index 36e9ea3515..60890ee97b 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/torture.py.expect @@ -55,4 +55,4 @@ def test(self, othr): assert a_function( very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more, -) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} \ No newline at end of file +) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py.expect index dd945eb330..a05a8243fa 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens1.py.expect @@ -31,4 +31,4 @@ class A: 4, 3, ) < self.connection.mysql_version < (10, 5, 2): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py.expect index eefadeb59b..59cad5ec26 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens2.py.expect @@ -3,4 +3,4 @@ if e123456.get_tk_patchlevel() >= (8, 6, 0, "final") or ( 5, 8, ) <= get_tk_patchlevel() < (8, 6): - pass \ No newline at end of file + pass diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py.expect index e6a673ec53..e5b4b7c4dc 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_comma_optional_parens3.py.expect @@ -5,4 +5,4 @@ if True: "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweas " + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", - ) % {"reported_username": reported_username, "report_reason": report_reason} \ No newline at end of file + ) % {"reported_username": reported_username, "report_reason": report_reason} diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py.expect index a34cef7a69..7b05b233a3 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/trailing_commas_in_leading_parts.py.expect @@ -47,4 +47,4 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( xxxxxxxxx ).xxxxxxxxxxxxxxxxxx(), ( "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -) \ No newline at end of file +) diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tricky_unicode_symbols.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tricky_unicode_symbols.py.expect index 1225df1a2b..ad8b610859 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tricky_unicode_symbols.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tricky_unicode_symbols.py.expect @@ -6,4 +6,4 @@ x󠄀 = 4 Q̇_per_meter = 4 A᧚ = 3 -A፩ = 8 \ No newline at end of file +A፩ = 8 diff --git a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py.expect b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py.expect index 16505cf05e..06ada05bef 100644 --- a/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py.expect +++ b/crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py.expect @@ -4,9 +4,13 @@ sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf, -) = 1, 2, 3 +) = ( + 1, + 2, + 3, +) # This is as well. (this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") -(a,) = call() \ No newline at end of file +(a,) = call() diff --git a/crates/ruff_python_formatter/src/format/stmt.rs b/crates/ruff_python_formatter/src/format/stmt.rs index 15720d3fd7..e2393a0a46 100644 --- a/crates/ruff_python_formatter/src/format/stmt.rs +++ b/crates/ruff_python_formatter/src/format/stmt.rs @@ -882,6 +882,8 @@ impl Format> for FormatStmt<'_> { } }?; + write!(f, [hard_line_break()])?; + // Any trailing comments come on the lines after. for trivia in &self.item.trivia { if matches!(trivia.relationship, Relationship::Trailing) { diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 5c0a249899..a960c60b32 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -208,7 +208,7 @@ mod tests { impl std::fmt::Display for CodeFrame<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { writeln!(f, "```{}", self.language)?; - writeln!(f, "{}", self.code)?; + write!(f, "{}", self.code)?; writeln!(f, "```")?; writeln!(f) } diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap index 699222ef9d..b16631a1c1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__attribute_access_on_number_literals_py.snap @@ -28,7 +28,6 @@ if 10 .real: y = 100[no] y = 100(no) - ``` ## Black Differences @@ -75,10 +74,7 @@ y = 100(no) y = 100[no] -y = 100(no) -\ No newline at end of file +y = 100((no)) -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap index 8e94a9725a..c142929ea6 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__bracketmatch_py.snap @@ -12,7 +12,6 @@ pem_spam = lambda l, spam = { "x": 3 }: not spam.get(l.strip()) lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x - ``` ## Black Differences @@ -26,10 +25,7 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x pass pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip()) -lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x -\ No newline at end of file +lambda x=lambda y={1: 3}: y['x' : lambda y: {1: 2}]: x -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap deleted file mode 100644 index 9891c18a81..0000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_blank_parentheses_py.snap +++ /dev/null @@ -1,121 +0,0 @@ ---- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py ---- -## Input - -```py -class SimpleClassWithBlankParentheses(): - pass -class ClassWithSpaceParentheses ( ): - first_test_data = 90 - second_test_data = 100 - def test_func(self): - return None -class ClassWithEmptyFunc(object): - - def func_with_blank_parentheses(): - return 5 - - -def public_func_with_blank_parentheses(): - return None -def class_under_the_func_with_blank_parentheses(): - class InsideFunc(): - pass -class NormalClass ( -): - def func_for_testing(self, first, second): - sum = first + second - return sum - -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -27,4 +27,4 @@ - class NormalClass: - def func_for_testing(self, first, second): - sum = first + second -- return sum -\ No newline at end of file -+ return sum - -``` - -## Ruff Output - -```py -class SimpleClassWithBlankParentheses: - pass - - -class ClassWithSpaceParentheses: - first_test_data = 90 - second_test_data = 100 - - def test_func(self): - return None - - -class ClassWithEmptyFunc(object): - def func_with_blank_parentheses(): - return 5 - - -def public_func_with_blank_parentheses(): - return None - - -def class_under_the_func_with_blank_parentheses(): - class InsideFunc: - pass - - -class NormalClass: - def func_for_testing(self, first, second): - sum = first + second - return sum - -``` - -## Black Output - -```py -class SimpleClassWithBlankParentheses: - pass - - -class ClassWithSpaceParentheses: - first_test_data = 90 - second_test_data = 100 - - def test_func(self): - return None - - -class ClassWithEmptyFunc(object): - def func_with_blank_parentheses(): - return 5 - - -def public_func_with_blank_parentheses(): - return None - - -def class_under_the_func_with_blank_parentheses(): - class InsideFunc: - pass - - -class NormalClass: - def func_for_testing(self, first, second): - sum = first + second - return sum -``` - - diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap deleted file mode 100644 index 74c6800373..0000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__class_methods_new_line_py.snap +++ /dev/null @@ -1,468 +0,0 @@ ---- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py ---- -## Input - -```py -class ClassSimplest: - pass -class ClassWithSingleField: - a = 1 -class ClassWithJustTheDocstring: - """Just a docstring.""" -class ClassWithInit: - def __init__(self): - pass -class ClassWithTheDocstringAndInit: - """Just a docstring.""" - def __init__(self): - pass -class ClassWithInitAndVars: - cls_var = 100 - def __init__(self): - pass -class ClassWithInitAndVarsAndDocstring: - """Test class""" - cls_var = 100 - def __init__(self): - pass -class ClassWithDecoInit: - @deco - def __init__(self): - pass -class ClassWithDecoInitAndVars: - cls_var = 100 - @deco - def __init__(self): - pass -class ClassWithDecoInitAndVarsAndDocstring: - """Test class""" - cls_var = 100 - @deco - def __init__(self): - pass -class ClassSimplestWithInner: - class Inner: - pass -class ClassSimplestWithInnerWithDocstring: - class Inner: - """Just a docstring.""" - def __init__(self): - pass -class ClassWithSingleFieldWithInner: - a = 1 - class Inner: - pass -class ClassWithJustTheDocstringWithInner: - """Just a docstring.""" - class Inner: - pass -class ClassWithInitWithInner: - class Inner: - pass - def __init__(self): - pass -class ClassWithInitAndVarsWithInner: - cls_var = 100 - class Inner: - pass - def __init__(self): - pass -class ClassWithInitAndVarsAndDocstringWithInner: - """Test class""" - cls_var = 100 - class Inner: - pass - def __init__(self): - pass -class ClassWithDecoInitWithInner: - class Inner: - pass - @deco - def __init__(self): - pass -class ClassWithDecoInitAndVarsWithInner: - cls_var = 100 - class Inner: - pass - @deco - def __init__(self): - pass -class ClassWithDecoInitAndVarsAndDocstringWithInner: - """Test class""" - cls_var = 100 - class Inner: - pass - @deco - def __init__(self): - pass -class ClassWithDecoInitAndVarsAndDocstringWithInner2: - """Test class""" - class Inner: - pass - cls_var = 100 - @deco - def __init__(self): - pass - -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -162,4 +162,4 @@ - - @deco - def __init__(self): -- pass -\ No newline at end of file -+ pass - -``` - -## Ruff Output - -```py -class ClassSimplest: - pass - - -class ClassWithSingleField: - a = 1 - - -class ClassWithJustTheDocstring: - """Just a docstring.""" - - -class ClassWithInit: - def __init__(self): - pass - - -class ClassWithTheDocstringAndInit: - """Just a docstring.""" - - def __init__(self): - pass - - -class ClassWithInitAndVars: - cls_var = 100 - - def __init__(self): - pass - - -class ClassWithInitAndVarsAndDocstring: - """Test class""" - - cls_var = 100 - - def __init__(self): - pass - - -class ClassWithDecoInit: - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVars: - cls_var = 100 - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstring: - """Test class""" - - cls_var = 100 - - @deco - def __init__(self): - pass - - -class ClassSimplestWithInner: - class Inner: - pass - - -class ClassSimplestWithInnerWithDocstring: - class Inner: - """Just a docstring.""" - - def __init__(self): - pass - - -class ClassWithSingleFieldWithInner: - a = 1 - - class Inner: - pass - - -class ClassWithJustTheDocstringWithInner: - """Just a docstring.""" - - class Inner: - pass - - -class ClassWithInitWithInner: - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithInitAndVarsWithInner: - cls_var = 100 - - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithInitAndVarsAndDocstringWithInner: - """Test class""" - - cls_var = 100 - - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithDecoInitWithInner: - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsWithInner: - cls_var = 100 - - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstringWithInner: - """Test class""" - - cls_var = 100 - - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstringWithInner2: - """Test class""" - - class Inner: - pass - - cls_var = 100 - - @deco - def __init__(self): - pass - -``` - -## Black Output - -```py -class ClassSimplest: - pass - - -class ClassWithSingleField: - a = 1 - - -class ClassWithJustTheDocstring: - """Just a docstring.""" - - -class ClassWithInit: - def __init__(self): - pass - - -class ClassWithTheDocstringAndInit: - """Just a docstring.""" - - def __init__(self): - pass - - -class ClassWithInitAndVars: - cls_var = 100 - - def __init__(self): - pass - - -class ClassWithInitAndVarsAndDocstring: - """Test class""" - - cls_var = 100 - - def __init__(self): - pass - - -class ClassWithDecoInit: - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVars: - cls_var = 100 - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstring: - """Test class""" - - cls_var = 100 - - @deco - def __init__(self): - pass - - -class ClassSimplestWithInner: - class Inner: - pass - - -class ClassSimplestWithInnerWithDocstring: - class Inner: - """Just a docstring.""" - - def __init__(self): - pass - - -class ClassWithSingleFieldWithInner: - a = 1 - - class Inner: - pass - - -class ClassWithJustTheDocstringWithInner: - """Just a docstring.""" - - class Inner: - pass - - -class ClassWithInitWithInner: - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithInitAndVarsWithInner: - cls_var = 100 - - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithInitAndVarsAndDocstringWithInner: - """Test class""" - - cls_var = 100 - - class Inner: - pass - - def __init__(self): - pass - - -class ClassWithDecoInitWithInner: - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsWithInner: - cls_var = 100 - - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstringWithInner: - """Test class""" - - cls_var = 100 - - class Inner: - pass - - @deco - def __init__(self): - pass - - -class ClassWithDecoInitAndVarsAndDocstringWithInner2: - """Test class""" - - class Inner: - pass - - cls_var = 100 - - @deco - def __init__(self): - pass -``` - - diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap index 6039fa6b91..d35a56bb0e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__collections_py.snap @@ -77,7 +77,6 @@ if True: ec2client.get_waiter("instance_stopped").wait( InstanceIds=[instance.id], WaiterConfig={"Delay": 5,}, ) - ``` ## Black Differences @@ -107,14 +106,6 @@ if True: }, ) ec2client.get_waiter("instance_stopped").wait( -@@ -96,4 +96,4 @@ - WaiterConfig={ - "Delay": 5, - }, -- ) -\ No newline at end of file -+ ) - ``` ## Ruff Output @@ -219,7 +210,6 @@ if True: "Delay": 5, }, ) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap index 5971e9cdb4..92e670eafa 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comment_after_escaped_newline_py.snap @@ -15,7 +15,6 @@ def bobtwo(): \ \ # some comment here pass - ``` ## Black Differences @@ -31,12 +30,9 @@ def bobtwo(): \ -def bobtwo(): # some comment here -- pass -\ No newline at end of file +def bobtwo(): + # some comment here -+ pass - + pass ``` ## Ruff Output @@ -50,7 +46,6 @@ def bob(): def bobtwo(): # some comment here pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap index 66361d7926..8d6d0a4434 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments2_py.snap @@ -171,7 +171,6 @@ instruction()#comment with bad spacing # END COMMENTS # MORE END COMMENTS - ``` ## Black Differences @@ -361,10 +360,7 @@ instruction()#comment with bad spacing +instruction() #comment with bad spacing # END COMMENTS --# MORE END COMMENTS -\ No newline at end of file -+# MORE END COMMENTS - + # MORE END COMMENTS ``` ## Ruff Output @@ -550,7 +546,6 @@ instruction() #comment with bad spacing # END COMMENTS # MORE END COMMENTS - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap index 04ec4febde..c5e260faf6 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments4_py.snap @@ -100,7 +100,6 @@ def foo3(list_a, list_b): ) .filter(User.xyz.is_(None)) ) - ``` ## Black Differences @@ -240,12 +239,10 @@ def foo3(list_a, list_b): - ) - .filter(User.xyz.is_(None)) - ) -\ No newline at end of file + return # Standlone comment but weirdly placed. + User.query.filter(User.foo == "bar").filter( + db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) + ).filter(User.xyz.is_(None)) - ``` ## Ruff Output @@ -345,7 +342,6 @@ def foo3(list_a, list_b): User.query.filter(User.foo == "bar").filter( db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b)) ).filter(User.xyz.is_(None)) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap index 575a740eb1..e25a53fb03 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments6_py.snap @@ -124,7 +124,6 @@ call_to_some_function_asdf( ) aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] - ``` ## Black Differences @@ -289,8 +288,6 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite ) aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type] -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap index eb50a64000..5572327616 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__comments9_py.snap @@ -145,7 +145,6 @@ def foo(): # A standalone comment def bar(): pass - ``` ## Black Differences @@ -280,11 +279,8 @@ def bar(): @decorator1 -# A standalone comment def bar(): -- pass -\ No newline at end of file + # A standalone comment -+ pass - + pass ``` ## Ruff Output @@ -457,7 +453,6 @@ def foo(): def bar(): # A standalone comment pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap index 8c690d7bba..ef60ad17b4 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_no_trailing_comma_py.snap @@ -187,7 +187,6 @@ class C: key9: value9 } ) - ``` ## Black Differences @@ -473,14 +472,6 @@ class C: assert ( expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect -@@ -178,4 +201,4 @@ - key8: value8, - key9: value9, - } -- ) -\ No newline at end of file -+ ) - ``` ## Ruff Output @@ -690,7 +681,6 @@ class C: key9: value9, } ) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap index 4dc8f2b30d..8841f50a16 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__composition_py.snap @@ -187,7 +187,6 @@ class C: key9: value9, } ) - ``` ## Black Differences @@ -473,14 +472,6 @@ class C: assert ( expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect -@@ -178,4 +201,4 @@ - key8: value8, - key9: value9, - } -- ) -\ No newline at end of file -+ ) - ``` ## Ruff Output @@ -690,7 +681,6 @@ class C: key9: value9, } ) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap deleted file mode 100644 index 0f3da70a1b..0000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__docstring_no_extra_empty_line_before_eof_py.snap +++ /dev/null @@ -1,50 +0,0 @@ ---- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py ---- -## Input - -```py -# Make sure when the file ends with class's docstring, -# It doesn't add extra blank lines. -class ClassWithDocstring: - """A docstring.""" - -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -1,4 +1,4 @@ - # Make sure when the file ends with class's docstring, - # It doesn't add extra blank lines. - class ClassWithDocstring: -- """A docstring.""" -\ No newline at end of file -+ """A docstring.""" - -``` - -## Ruff Output - -```py -# Make sure when the file ends with class's docstring, -# It doesn't add extra blank lines. -class ClassWithDocstring: - """A docstring.""" - -``` - -## Black Output - -```py -# Make sure when the file ends with class's docstring, -# It doesn't add extra blank lines. -class ClassWithDocstring: - """A docstring.""" -``` - - diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap index 34ebdc1be9..64f776a402 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__empty_lines_py.snap @@ -98,7 +98,6 @@ def g(): syms.argument, }: return NO - ``` ## Black Differences @@ -119,7 +118,7 @@ def g(): t = leaf.type p = leaf.parent # trailing comment -@@ -25,23 +25,30 @@ +@@ -25,35 +25,41 @@ return NO if prevp.type == token.EQUAL: @@ -165,11 +164,11 @@ def g(): return NO -@@ -49,11 +56,10 @@ + ############################################################################### # SECTION BECAUSE SECTIONS ############################################################################### - - + def g(): - NO = "" - SPACE = " " @@ -200,8 +199,6 @@ def g(): - syms.arglist, - syms.argument, - }: -- return NO -\ No newline at end of file + if ( + prevp.parent + and prevp.parent.type @@ -213,8 +210,7 @@ def g(): + syms.argument, + } + ): -+ return NO - + return NO ``` ## Ruff Output @@ -319,7 +315,6 @@ def g(): } ): return NO - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap index 9a6bfdee10..22949e554f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__expression_py.snap @@ -260,7 +260,6 @@ bbbb >> bbbb * bbbb aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa last_call() # standalone comment at ENDMARKER - ``` ## Black Differences @@ -308,7 +307,7 @@ last_call() () (1,) (1, 2) -@@ -88,33 +90,34 @@ +@@ -88,32 +90,33 @@ ] {i for i in (1, 2, 3)} {(i**2) for i in (1, 2, 3)} @@ -346,12 +345,10 @@ last_call() arg, another, - kwarg="hey", -- **kwargs + kwarg='hey', -+ **kwargs, + **kwargs, ) # note: no trailing comma pre-3.6 call(*gidgets[:2]) - call(a, *gidgets[:2]) @@ -122,8 +125,8 @@ call(b, **self.screen_kwargs) lukasz.langa.pl @@ -370,19 +367,19 @@ last_call() -xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) +xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = ( -+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore -+) -+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = ( + classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore ) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) +xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = ( -+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) ++ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore ) -xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( - sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__) -) # type: ignore ++xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = ( ++ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) ++) slice[0] slice[0:1] slice[0:1:2] @@ -436,10 +433,18 @@ last_call() g = 1, *"ten" -what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set( - vars_to_remove --) ++what_is_up_with_those_new_coord_names = ( ++ (coord_names ++ + set(vars_to_create)) ++ + set(vars_to_remove) + ) -what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set( - vars_to_remove --) ++what_is_up_with_those_new_coord_names = ( ++ (coord_names ++ | set(vars_to_create)) ++ - set(vars_to_remove) + ) -result = ( - session.query(models.Customer.id) - .filter( @@ -447,11 +452,7 @@ last_call() - ) - .order_by(models.Customer.id.asc()) - .all() -+what_is_up_with_those_new_coord_names = ( -+ (coord_names -+ + set(vars_to_create)) -+ + set(vars_to_remove) - ) +-) -result = ( - session.query(models.Customer.id) - .filter( @@ -461,11 +462,7 @@ last_call() - models.Customer.id.asc(), - ) - .all() -+what_is_up_with_those_new_coord_names = ( -+ (coord_names -+ | set(vars_to_create)) -+ - set(vars_to_remove) - ) +-) +result = session.query(models.Customer.id).filter( + models.Customer.account_id == account_id, + models.Customer.email == email_address, @@ -533,15 +530,6 @@ last_call() ^ aaaaaaaaaaaaaaaa.i << aaaaaaaaaaaaaaaa.k >> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n -@@ -366,5 +371,4 @@ - ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - ) --last_call() --# standalone comment at ENDMARKER -\ No newline at end of file -+last_call()# standalone comment at ENDMARKER - ``` ## Ruff Output @@ -920,8 +908,8 @@ bbbb >> bbbb * bbbb ^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ) -last_call()# standalone comment at ENDMARKER - +last_call() +# standalone comment at ENDMARKER ``` ## Black Output @@ -1043,7 +1031,7 @@ call( arg, another, kwarg="hey", - **kwargs + **kwargs, ) # note: no trailing comma pre-3.6 call(*gidgets[:2]) call(a, *gidgets[:2]) diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap index 0549e77881..32bb882d20 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff2_py.snap @@ -46,7 +46,6 @@ def test_calculate_fades(): ] # fmt: on - ``` ## Black Differences @@ -63,9 +62,9 @@ def test_calculate_fades(): # Test data: # Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]] -- --@pytest.mark.parametrize('test', [ +-@pytest.mark.parametrize('test', [ +- - # Test don't manage the volume +@pytest.mark.parametrize( + 'test', @@ -106,10 +105,7 @@ def test_calculate_fades(): + (None, 4, 0, 0, 10, 0, 0, 6, 10), ] --# fmt: on -\ No newline at end of file -+# fmt: on - + # fmt: on ``` ## Ruff Output @@ -159,7 +155,6 @@ def test_calculate_fades(): ] # fmt: on - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap index 20c59c16e0..44a115b964 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff3_py.snap @@ -23,7 +23,6 @@ x = [ x = [ 1, 2, 3, 4 ] - ``` ## Black Differences @@ -54,7 +53,6 @@ x = [ ] # fmt: on - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap index 8fe64114cd..50daa356bc 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff4_py.snap @@ -19,7 +19,6 @@ def f(): pass 3, 4, ]) def f(): pass - ``` ## Black Differences @@ -47,14 +46,6 @@ def f(): pass pass -@@ -17,4 +21,4 @@ - ] - ) - def f(): -- pass -\ No newline at end of file -+ pass - ``` ## Ruff Output @@ -84,7 +75,6 @@ def f(): ) def f(): pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap index 624f6aa5ff..1af351739c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtonoff5_py.snap @@ -90,7 +90,6 @@ if x: elif unformatted: # fmt: on will_be_formatted () - ``` ## Black Differences @@ -188,10 +187,7 @@ elif unformatted: -elif unformatted: +elif unformatted: # fmt: on -- will_be_formatted() -\ No newline at end of file -+ will_be_formatted() - + will_be_formatted() ``` ## Ruff Output @@ -280,7 +276,6 @@ if x: elif unformatted: # fmt: on will_be_formatted() - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap index 86efc9430f..2bd8d5bf4f 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip2_py.snap @@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca 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 @@ -30,7 +29,6 @@ l3 = ["I have", "trailing comma", "so I should be braked",] l3 = [ "I have", "trailing comma", - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap index 5cbf4112dd..2e54d4b721 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip3_py.snap @@ -13,7 +13,6 @@ d = 6 # fmt: skip e = 5 # fmt: on f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."] - ``` ## Black Differences @@ -31,7 +30,6 @@ f = ["This is a very long line that should be formatted into a clearer line ", " e = 5 # fmt: on f = [ - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap index a82a9470a2..9671076211 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip5_py.snap @@ -15,7 +15,6 @@ if ( print("I'm good!") else: print("I'm bad") - ``` ## Black Differences @@ -33,10 +32,7 @@ else: +if a == 3 and b != 9 and c is not None: # fmt: skip print("I'm good!") else: -- print("I'm bad") -\ No newline at end of file -+ print("I'm bad") - + print("I'm bad") ``` ## Ruff Output @@ -47,7 +43,6 @@ if a == 3 and b != 9 and c is not None: # fmt: skip print("I'm good!") else: print("I'm bad") - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap index 03ecfe5c8c..46b8920531 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip6_py.snap @@ -11,7 +11,6 @@ class A: for line in range(10): if True: pass # fmt: skip - ``` ## Black Differences @@ -24,9 +23,7 @@ class A: for line in range(10): if True: - pass # fmt: skip -\ No newline at end of file + pass - ``` ## Ruff Output @@ -37,7 +34,6 @@ class A: for line in range(10): if True: pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap index f470fd7332..caacad9a0e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip7_py.snap @@ -10,7 +10,6 @@ a = "this is some code" b = 5 #fmt:skip c = 9 #fmt: skip d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip - ``` ## Black Differences @@ -23,12 +22,9 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu -b = 5 # fmt:skip -c = 9 # fmt: skip -d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip -\ No newline at end of file +b = 5 #fmt:skip +c = 9 #fmt: skip +d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap index ba9c9f7837..c4deeaed9c 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fmtskip_py.snap @@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca a, b = 1, 2 c = 6 # fmt: skip d = 5 - ``` ## Black Differences @@ -22,8 +21,6 @@ d = 5 -c = 6 # fmt: skip +c = 6 # fmt: skip d = 5 -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap index a7da17e03c..7dd7584af5 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__fstring_py.snap @@ -15,7 +15,6 @@ f"{f'''{'nested'} inner'''} outer" f"\"{f'{nested} inner'}\" outer" f"space between opening braces: { {a for a in (1, 2, 3)}}" f'Hello \'{tricky + "example"}\'' - ``` ## Black Differences @@ -31,7 +30,6 @@ f'Hello \'{tricky + "example"}\'' f"some f-string with {a} {few():.2f} {formatted.values!r}" f'some f-string with {a} {few(""):.2f} {formatted.values!r}' f"{f'''{'nested'} inner'''} outer" - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap deleted file mode 100644 index 0a878dbab0..0000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function2_py.snap +++ /dev/null @@ -1,223 +0,0 @@ ---- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py ---- -## Input - -```py -def f( - a, - **kwargs, -) -> A: - with cache_dir(): - if something: - result = ( - CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"]) - ) - limited.append(-limited.pop()) # negate top - return A( - very_long_argument_name1=very_long_value_for_the_argument, - very_long_argument_name2=-very.long.value.for_the_argument, - **kwargs, - ) -def g(): - "Docstring." - def inner(): - pass - print("Inner defs should breathe a little.") -def h(): - def inner(): - pass - print("Inner defs should breathe a little.") - - -if os.name == "posix": - import termios - def i_should_be_followed_by_only_one_newline(): - pass -elif os.name == "nt": - try: - import msvcrt - def i_should_be_followed_by_only_one_newline(): - pass - - except ImportError: - - def i_should_be_followed_by_only_one_newline(): - pass - -elif False: - - class IHopeYouAreHavingALovelyDay: - def __call__(self): - print("i_should_be_followed_by_only_one_newline") -else: - - def foo(): - pass - -with hmm_but_this_should_get_two_preceding_newlines(): - pass - -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -63,4 +63,4 @@ - - - with hmm_but_this_should_get_two_preceding_newlines(): -- pass -\ No newline at end of file -+ pass - -``` - -## Ruff Output - -```py -def f( - a, - **kwargs, -) -> A: - with cache_dir(): - if something: - result = CliRunner().invoke( - black.main, - [str(src1), str(src2), "--diff", "--check"], - ) - limited.append(-limited.pop()) # negate top - return A( - very_long_argument_name1=very_long_value_for_the_argument, - very_long_argument_name2=-very.long.value.for_the_argument, - **kwargs, - ) - - -def g(): - "Docstring." - - def inner(): - pass - - print("Inner defs should breathe a little.") - - -def h(): - def inner(): - pass - - print("Inner defs should breathe a little.") - - -if os.name == "posix": - import termios - - def i_should_be_followed_by_only_one_newline(): - pass - -elif os.name == "nt": - try: - import msvcrt - - def i_should_be_followed_by_only_one_newline(): - pass - - except ImportError: - - def i_should_be_followed_by_only_one_newline(): - pass - -elif False: - - class IHopeYouAreHavingALovelyDay: - def __call__(self): - print("i_should_be_followed_by_only_one_newline") - -else: - - def foo(): - pass - - -with hmm_but_this_should_get_two_preceding_newlines(): - pass - -``` - -## Black Output - -```py -def f( - a, - **kwargs, -) -> A: - with cache_dir(): - if something: - result = CliRunner().invoke( - black.main, - [str(src1), str(src2), "--diff", "--check"], - ) - limited.append(-limited.pop()) # negate top - return A( - very_long_argument_name1=very_long_value_for_the_argument, - very_long_argument_name2=-very.long.value.for_the_argument, - **kwargs, - ) - - -def g(): - "Docstring." - - def inner(): - pass - - print("Inner defs should breathe a little.") - - -def h(): - def inner(): - pass - - print("Inner defs should breathe a little.") - - -if os.name == "posix": - import termios - - def i_should_be_followed_by_only_one_newline(): - pass - -elif os.name == "nt": - try: - import msvcrt - - def i_should_be_followed_by_only_one_newline(): - pass - - except ImportError: - - def i_should_be_followed_by_only_one_newline(): - pass - -elif False: - - class IHopeYouAreHavingALovelyDay: - def __call__(self): - print("i_should_be_followed_by_only_one_newline") - -else: - - def foo(): - pass - - -with hmm_but_this_should_get_two_preceding_newlines(): - pass -``` - - diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap index 0c12901b77..e7ad2eb55d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_py.snap @@ -101,7 +101,6 @@ def f( ) ) def __await__(): return (yield) - ``` ## Black Differences @@ -184,9 +183,7 @@ def __await__(): return (yield) def __await__(): - return (yield) -\ No newline at end of file + return yield - ``` ## Ruff Output @@ -334,7 +331,6 @@ def f( def __await__(): return yield - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap index 578d604fbb..1ffca41f0d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__function_trailing_comma_py.snap @@ -67,7 +67,6 @@ some_module.some_function( some_module.some_function( argument1, (one, two,), argument4, argument5, argument6 ) - ``` ## Black Differences @@ -176,7 +175,6 @@ some_module.some_function( ) # Inner trailing comma causes outer to explode - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap index 9c96d7df54..e074631133 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_await_parens_py.snap @@ -87,7 +87,6 @@ async def main(): async def main(): await (yield) - ``` ## Black Differences @@ -183,7 +182,7 @@ async def main(): # Keep brackets around non power operations and nested awaits -@@ -82,12 +86,12 @@ +@@ -82,11 +86,11 @@ async def main(): @@ -197,10 +196,6 @@ async def main(): async def main(): -- await (yield) -\ No newline at end of file -+ await (yield) - ``` ## Ruff Output @@ -303,7 +298,6 @@ async def main(): async def main(): await (yield) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap index 75c880d728..2d8aa71163 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_except_parens_py.snap @@ -41,7 +41,6 @@ try: a.something except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err: raise err - ``` ## Black Differences @@ -69,14 +68,6 @@ except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.ov raise err try: -@@ -39,4 +37,4 @@ - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, - some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, - ) as err: -- raise err -\ No newline at end of file -+ raise err - ``` ## Ruff Output @@ -122,7 +113,6 @@ except ( some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, ) as err: raise err - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap index 19687a4bc8..1753040f6b 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_for_brackets_py.snap @@ -25,7 +25,6 @@ for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfuds # Test deeply nested brackets for (((((k, v))))) in d.items(): print(k, v) - ``` ## Black Differences @@ -42,7 +41,7 @@ for (((((k, v))))) in d.items(): if hasattr(module, "_verify_python3_env"): module._verify_python3_env = lambda: None -@@ -17,11 +17,9 @@ +@@ -17,9 +17,7 @@ for ( k, v, @@ -53,11 +52,6 @@ for (((((k, v))))) in d.items(): print(k, v) # Test deeply nested brackets - for k, v in d.items(): -- print(k, v) -\ No newline at end of file -+ print(k, v) - ``` ## Ruff Output @@ -88,7 +82,6 @@ for ( # Test deeply nested brackets for k, v in d.items(): print(k, v) - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap deleted file mode 100644 index 682a891c50..0000000000 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_newline_after_code_block_open_py.snap +++ /dev/null @@ -1,302 +0,0 @@ ---- -source: crates/ruff_python_formatter/src/lib.rs -expression: snapshot -input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py ---- -## Input - -```py -import random - - -def foo1(): - - print("The newline above me should be deleted!") - - -def foo2(): - - - - print("All the newlines above me should be deleted!") - - -def foo3(): - - print("No newline above me!") - - print("There is a newline above me, and that's OK!") - - -def foo4(): - - # There is a comment here - - print("The newline above me should not be deleted!") - - -class Foo: - def bar(self): - - print("The newline above me should be deleted!") - - -for i in range(5): - - print(f"{i}) The line above me should be removed!") - - -for i in range(5): - - - - print(f"{i}) The lines above me should be removed!") - - -for i in range(5): - - for j in range(7): - - print(f"{i}) The lines above me should be removed!") - - -if random.randint(0, 3) == 0: - - print("The new line above me is about to be removed!") - - -if random.randint(0, 3) == 0: - - - - - print("The new lines above me is about to be removed!") - - -if random.randint(0, 3) == 0: - if random.uniform(0, 1) > 0.5: - print("Two lines above me are about to be removed!") - - -while True: - - print("The newline above me should be deleted!") - - -while True: - - - - print("The newlines above me should be deleted!") - - -while True: - - while False: - - print("The newlines above me should be deleted!") - - -with open("/path/to/file.txt", mode="w") as file: - - file.write("The new line above me is about to be removed!") - - -with open("/path/to/file.txt", mode="w") as file: - - - - file.write("The new lines above me is about to be removed!") - - -with open("/path/to/file.txt", mode="r") as read_file: - - with open("/path/to/output_file.txt", mode="w") as write_file: - - write_file.writelines(read_file.readlines()) - -``` - -## Black Differences - -```diff ---- Black -+++ Ruff -@@ -75,4 +75,4 @@ - - with open("/path/to/file.txt", mode="r") as read_file: - with open("/path/to/output_file.txt", mode="w") as write_file: -- write_file.writelines(read_file.readlines()) -\ No newline at end of file -+ write_file.writelines(read_file.readlines()) - -``` - -## Ruff Output - -```py -import random - - -def foo1(): - print("The newline above me should be deleted!") - - -def foo2(): - print("All the newlines above me should be deleted!") - - -def foo3(): - print("No newline above me!") - - print("There is a newline above me, and that's OK!") - - -def foo4(): - # There is a comment here - - print("The newline above me should not be deleted!") - - -class Foo: - def bar(self): - print("The newline above me should be deleted!") - - -for i in range(5): - print(f"{i}) The line above me should be removed!") - - -for i in range(5): - print(f"{i}) The lines above me should be removed!") - - -for i in range(5): - for j in range(7): - print(f"{i}) The lines above me should be removed!") - - -if random.randint(0, 3) == 0: - print("The new line above me is about to be removed!") - - -if random.randint(0, 3) == 0: - print("The new lines above me is about to be removed!") - - -if random.randint(0, 3) == 0: - if random.uniform(0, 1) > 0.5: - print("Two lines above me are about to be removed!") - - -while True: - print("The newline above me should be deleted!") - - -while True: - print("The newlines above me should be deleted!") - - -while True: - while False: - print("The newlines above me should be deleted!") - - -with open("/path/to/file.txt", mode="w") as file: - file.write("The new line above me is about to be removed!") - - -with open("/path/to/file.txt", mode="w") as file: - file.write("The new lines above me is about to be removed!") - - -with open("/path/to/file.txt", mode="r") as read_file: - with open("/path/to/output_file.txt", mode="w") as write_file: - write_file.writelines(read_file.readlines()) - -``` - -## Black Output - -```py -import random - - -def foo1(): - print("The newline above me should be deleted!") - - -def foo2(): - print("All the newlines above me should be deleted!") - - -def foo3(): - print("No newline above me!") - - print("There is a newline above me, and that's OK!") - - -def foo4(): - # There is a comment here - - print("The newline above me should not be deleted!") - - -class Foo: - def bar(self): - print("The newline above me should be deleted!") - - -for i in range(5): - print(f"{i}) The line above me should be removed!") - - -for i in range(5): - print(f"{i}) The lines above me should be removed!") - - -for i in range(5): - for j in range(7): - print(f"{i}) The lines above me should be removed!") - - -if random.randint(0, 3) == 0: - print("The new line above me is about to be removed!") - - -if random.randint(0, 3) == 0: - print("The new lines above me is about to be removed!") - - -if random.randint(0, 3) == 0: - if random.uniform(0, 1) > 0.5: - print("Two lines above me are about to be removed!") - - -while True: - print("The newline above me should be deleted!") - - -while True: - print("The newlines above me should be deleted!") - - -while True: - while False: - print("The newlines above me should be deleted!") - - -with open("/path/to/file.txt", mode="w") as file: - file.write("The new line above me is about to be removed!") - - -with open("/path/to/file.txt", mode="w") as file: - file.write("The new lines above me is about to be removed!") - - -with open("/path/to/file.txt", mode="r") as read_file: - with open("/path/to/output_file.txt", mode="w") as write_file: - write_file.writelines(read_file.readlines()) -``` - - diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap index f376829eca..b17e75d81d 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__remove_parens_py.snap @@ -61,7 +61,6 @@ def example7(): def example8(): return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) - ``` ## Black Differences @@ -108,14 +107,6 @@ def example8(): def example4(): -@@ -82,4 +74,4 @@ - - - def example8(): -- return None -\ No newline at end of file -+ return None - ``` ## Ruff Output @@ -198,7 +189,6 @@ def example7(): def example8(): return None - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap index dd42deff39..0fc4f9dadc 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__return_annotation_brackets_py.snap @@ -94,7 +94,6 @@ def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo # Magic trailing comma example def foo() -> tuple[int, int, int,]: return 2 - ``` ## Black Differences @@ -237,15 +236,12 @@ def foo() -> tuple[int, int, int,]: - int, - ] -): -- return 2 -\ No newline at end of file +def foo() -> tuple[ + int, + int, + int, +]: -+ return 2 - + return 2 ``` ## Ruff Output @@ -366,7 +362,6 @@ def foo() -> tuple[ int, ]: return 2 - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap index 2fbeae7ea0..8bd41e4df1 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__skip_magic_trailing_comma_py.snap @@ -53,7 +53,6 @@ func( argument5, argument6, ) - ``` ## Black Differences @@ -123,7 +122,6 @@ func( +) = func1(arg1) and func2(arg2) -func(argument1, (one, two), argument4, argument5, argument6) -\ No newline at end of file +func( + argument1, + ( @@ -134,8 +132,6 @@ func( + argument5, + argument6, +) -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap index 575db53147..07e263b90e 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__string_prefixes_py.snap @@ -26,7 +26,6 @@ def docstring_multiline(): R""" clear out all of the issues opened in that time :p """ - ``` ## Black Differences @@ -53,14 +52,6 @@ def docstring_multiline(): def docstring_singleline(): -@@ -17,4 +17,4 @@ - def docstring_multiline(): - R""" - clear out all of the issues opened in that time :p -- """ -\ No newline at end of file -+ """ - ``` ## Ruff Output @@ -86,7 +77,6 @@ def docstring_multiline(): R""" clear out all of the issues opened in that time :p """ - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap index 824a9bf55d..f59b077951 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__torture_py.snap @@ -35,7 +35,6 @@ assert ( a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} ) - ``` ## Black Differences @@ -115,7 +114,6 @@ assert ( - very_long_arguments_that_surpass_the_limit, - which_is_eighty_eight_in_this_case_plus_a_bit_more, -) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"} -\ No newline at end of file +assert ( + a_function( + very_long_arguments_that_surpass_the_limit, @@ -126,8 +124,6 @@ assert ( + "b": "but only by a little bit", + } +) -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap index 2ace4efb68..47ea12c704 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens1_py.snap @@ -31,7 +31,6 @@ class A: 3, ) < self.connection.mysql_version < (10, 5, 2): pass - ``` ## Black Differences @@ -76,8 +75,6 @@ class A: - 4, - 3, - ) < self.connection.mysql_version < (10, 5, 2): -- pass -\ No newline at end of file + if ( + self.connection.mysql_is_mariadb + and ( @@ -88,8 +85,7 @@ class A: + < self.connection.mysql_version + < (10, 5, 2) + ): -+ pass - + pass ``` ## Ruff Output @@ -134,7 +130,6 @@ class A: < (10, 5, 2) ): pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap index 72dac4affc..85eed38625 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens2_py.snap @@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)): pass - ``` ## Black Differences @@ -23,14 +22,11 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or - 5, - 8, -) <= get_tk_patchlevel() < (8, 6): -- pass -\ No newline at end of file +if ( + e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') + or (8, 5, 8) <= get_tk_patchlevel() < (8, 6) +): -+ pass - + pass ``` ## Ruff Output @@ -41,7 +37,6 @@ if ( or (8, 5, 8) <= get_tk_patchlevel() < (8, 6) ): pass - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap index 24be9e641a..c7af64f403 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_comma_optional_parens3_py.snap @@ -14,7 +14,6 @@ if True: + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", ) % {"reported_username": reported_username, "report_reason": report_reason} - ``` ## Black Differences @@ -27,10 +26,8 @@ if True: + "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.", "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", - ) % {"reported_username": reported_username, "report_reason": report_reason} -\ No newline at end of file + ) + % {"reported_username": reported_username, "report_reason": report_reason} - ``` ## Ruff Output @@ -45,7 +42,6 @@ if True: "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe", ) % {"reported_username": reported_username, "report_reason": report_reason} - ``` ## Black Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap index 629074de44..c32d073085 100644 --- a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__trailing_commas_in_leading_parts_py.snap @@ -39,7 +39,6 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( ).xxxxxxxxxxxxxxxxxx(), ( "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) - ``` ## Black Differences @@ -68,8 +67,6 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx( +assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(xxxxxxxxx).xxxxxxxxxxxxxxxxxx(), ( "xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ) -\ No newline at end of file - ``` ## Ruff Output diff --git a/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap new file mode 100644 index 0000000000..c70fc5da1f --- /dev/null +++ b/crates/ruff_python_formatter/src/snapshots/ruff_python_formatter__tests__black_test__tupleassign_py.snap @@ -0,0 +1,76 @@ +--- +source: crates/ruff_python_formatter/src/lib.rs +expression: snapshot +input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py +--- +## Input + +```py +# This is a standalone comment. +sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3 + +# This is as well. +this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890") + +(a,) = call() +``` + +## Black Differences + +```diff +--- Black ++++ Ruff +@@ -4,11 +4,7 @@ + sdfjsdfjlksdljkfsdlkf, + sdfsdjfklsdfjlksdljkf, + sdsfsdfjskdflsfsdf, +-) = ( +- 1, +- 2, +- 3, +-) ++) = 1, 2, 3 + + # This is as well. + (this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") +``` + +## Ruff Output + +```py +# This is a standalone comment. +( + sdfjklsdfsjldkflkjsf, + sdfjsdfjlksdljkfsdlkf, + sdfsdjfklsdfjlksdljkf, + sdsfsdfjskdflsfsdf, +) = 1, 2, 3 + +# This is as well. +(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") + +(a,) = call() +``` + +## Black Output + +```py +# This is a standalone comment. +( + sdfjklsdfsjldkflkjsf, + sdfjsdfjlksdljkfsdlkf, + sdfsdjfklsdfjlksdljkf, + sdsfsdfjskdflsfsdf, +) = ( + 1, + 2, + 3, +) + +# This is as well. +(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890") + +(a,) = call() +``` + +