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

empty lines at end of file trimmed even with fmt: off #496

Open
matejcik opened this issue Sep 3, 2018 · 4 comments
Open

empty lines at end of file trimmed even with fmt: off #496

matejcik opened this issue Sep 3, 2018 · 4 comments
Labels
F: empty lines Wasting vertical space efficiently. F: fmtoff fmt: off implementation T: bug Something isn't working

Comments

@matejcik
Copy link

matejcik commented Sep 3, 2018

Operating system: Linux Mint
Python version: 3.6.6
Black version: latest
Does also happen on master: yes

The following file:

# fmt: off

print("hello")

gets trimmed to:

# fmt: off

print("hello")

IOW, if the file ends with empty lines, they are removed.

@zsol zsol added the T: bug Something isn't working label Sep 7, 2018
@zsol
Copy link
Collaborator

zsol commented Sep 7, 2018

Sounds like a bug. Want to take a look at fixing it?

@scolby33
Copy link

The problem here appears to happen in convert_one_fmt_off_pair, where the node enters as # fmt: off\n\nprint("hello")\n\n and exits as # fmt: off\n\nprint("hello")\n. I am continuing to investigate.

@scolby33
Copy link

scolby33 commented Dec 17, 2018

The function generate_ignored_nodes creates a list of nodes that is just # fmt: off\n\nprint("hello")\n. This is where the final newline is lost.

Unfortunately, I've reached the end of my experience/time to look at this today. I hope this has given someone more versed in the project a better starting place for fixing this bug.

EDIT: also, because of how test files are read in read_data in test_black.py, it will be difficult to write a test for this since the final \n will be removed.

@JelleZijlstra JelleZijlstra added F: empty lines Wasting vertical space efficiently. F: fmtoff fmt: off implementation labels May 30, 2021
@felix-hilden
Copy link
Collaborator

At least our documentation states that fmt: off should be followed by a fmt: on, but supporting a single off switch is a reasonable request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: empty lines Wasting vertical space efficiently. F: fmtoff fmt: off implementation T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants