Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print_diff / diff does not include new line at the end of the file #1008

Open
masad-frost opened this issue Jun 2, 2022 · 0 comments
Open

Comments

@masad-frost
Copy link

Using normal mode in yapf adds new lines to the formatted code, but when using the diff option new lines at the end of file are not included in the patch. Maybe the diff is generated based on unformatted code that has EOF newline added.

You can try it here https://replit.com/@replitfaris/yapf-newline-patch

source:
from yapf.yapflib.yapf_api import FormatCode


unformatted_code = "f(a=1, b=2)"
print("unformatted code")
print(repr(unformatted_code))
print("")

formatted_code, _ = FormatCode(unformatted_code)

print("formatted code:")
print(repr(formatted_code))
print("")

diff, _ = FormatCode(unformatted_code, print_diff=True)

"""
This is empty but should be:

--- <unknown>   (original)
+++ <unknown>   (reformatted)
@@ -1 +1 @@
-f(a=1, b=2)
\ No newline at end of file
+f(a=1, b=2)
"""
print("diff:")
print(diff)
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant