Black formatting leaves an extra line at the end of the file
See original GitHub issueEnvironment data
- VS Code version: 1.23.1
- Extension version (available under the Extensions sidebar): 2018.5.0
- OS and version: macOs High Sierra
- Python version (& distribution if applicable, e.g. Anaconda): CPython 3.6.5
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
- Relevant/affected Python packages and their versions: black-18.6b1
Actual behavior
Formatting using black leaves two empty lines at the end of the file, if the file has more than 1 empty line already.
Expected behavior
Formatting should leave just one line, and this is what happens when I run black manually from the terminal.
Steps to reproduce:
- Open Python file
- Insert 10 empty lines at the end
- Activate “Format document” with black set as the formatter
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
##########Linting Output - flake8##########
20,1,W,W391:blank line at end of file
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:10 (4 by maintainers)
Top Results From Across the Web
The Black code style - Black 22.12.0 documentation
The coding style used by Black can be viewed as a strict subset of PEP 8. Black reformats entire files in place. It...
Read more >black formatter: How can I place one newline before and after ...
I want one newline before and one newline after function definition. Can i do it using black config file black --config FILE ....
Read more >Line breaks are removed in posts made in plain text format
Method 1 - Disable the feature that removes extra line breaks · Open Outlook. · On the File tab, select Options. · In...
Read more >Chapter 3 - Code Formatting with Black - Invent with Python
This chapter introduces you to Black, a code formatting tool that can ... If you never use space characters, your line can end...
Read more >“Where did that line come from (and how do I get rid of it ...
Go to the File tab (versions 2010 and up) or or the Office Button in Word 2007, then go to Proofing (along the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.{ "files.trimFinalNewlines": true }
in settings.json seems to fix this.