You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Black formatting leaves an extra line at the end of the file #1877
Don Jayamanne (@DonJayamanne) so when I tested this I added the blank lines, we just weren't stripping them out. So I don't think it's a case of adding as much as not removing.
FYI, I've also come across cases where this will add an extra newline (and not just fail to remove it):
If there's no newline at the end of the file yet and the last line contains something that will be reformatted by black then auto-formatting will add two blank lines.
example:
a=0
will be reformatted to:
a=0
Reacted by Jason Williams, Poiappoi and alextat120
Dror Atariah (@drorata) not specifically. Other bugs have taken precedence. As always, if the 👍 gets high enough we will prioritize fixing this appropriately (this issue currently sits at #23on that list).
Otherwise we will happily review a PR that tries to fix this if someone is motivated enough to provide one.
I have just run into this issue. From the cli, black will change the file correctly. When saving, It will format the rest of the document, and leaves the extra blank line/ I even see the same flake8 picking this up as a formatting error.
If I have no blank lines, it adds one, if I have multiple it removes all but 2. I tried this out with a new file and found the same result.
This caught me out, as our CI pipeline runs black --check and fails. Which it did.
Reacted by Wei Zhang, Diego Alloza González, Spencer Tollefson, Holger Hoefling, Norm Ross and roberthubblehq
Activity
brettcannon commentedon Jun 6, 2018
I can reproduce and the expected behaviour that Tin Tvrtković (@Tinche) found and I can verify that using
black --diffdoes what is expected:brettcannon commentedon Jun 13, 2018
Don Jayamanne (@DonJayamanne) so when I tested this I added the blank lines, we just weren't stripping them out. So I don't think it's a case of adding as much as not removing.
DonJayamanne commentedon Jun 13, 2018
I think its best to use an npm package (e.g. https://www.npmjs.com/package/diff) rather than parsing diff patches manually.
Moving to July
This will need to be done as part of #1950 as parsing of diff patches is a shared block of code (used by refactoring and sorting of imports).
marko-knoebl commentedon Aug 6, 2018
FYI, I've also come across cases where this will add an extra newline (and not just fail to remove it):
If there's no newline at the end of the file yet and the last line contains something that will be reformatted by black then auto-formatting will add two blank lines.
example:
will be reformatted to:
jaswilli commentedon Oct 6, 2018
Since #1950 has been closed is there another issue that can be tracked to see progress on this?
brettcannon commentedon Oct 9, 2018
Jason Williams (@jaswilli) this issue is tracking the overall issue. If you're curious about the work in the language server to potentially take this functionality over, then microsoft/python-language-server#143 has that request.
drorata commentedon Aug 22, 2019
Is there any update on this issue? I am still having it with Vscode 1.37.1 and vscode-python 2019.8.30787.
brettcannon commentedon Aug 22, 2019
Dror Atariah (@drorata) not specifically. Other bugs have taken precedence. As always, if the 👍 gets high enough we will prioritize fixing this appropriately (this issue currently sits at #23 on that list).
Otherwise we will happily review a PR that tries to fix this if someone is motivated enough to provide one.
ashleybartlett commentedon Aug 28, 2019
I have just run into this issue. From the cli, black will change the file correctly. When saving, It will format the rest of the document, and leaves the extra blank line/ I even see the same flake8 picking this up as a formatting error.
If I have no blank lines, it adds one, if I have multiple it removes all but 2. I tried this out with a new file and found the same result.
This caught me out, as our CI pipeline runs
black --checkand fails. Which it did.roberthubblehq commentedon Jan 10, 2020
{ "files.trimFinalNewlines": true }in settings.json seems to fix this.