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

blank line at end of file #40

Closed
DXist opened this issue Nov 2, 2011 · 16 comments
Closed

blank line at end of file #40

DXist opened this issue Nov 2, 2011 · 16 comments

Comments

@DXist
Copy link

DXist commented Nov 2, 2011

What is more 'pythonic' - to leave blank line at end of file or not? Most tools require blank line at end of file. There is no ugly message "\ No newline at end of file" in diff output. Why does pep8 tool require no blank lines at end of file?

@florentx
Copy link
Contributor

pep8.py correctly detects '\n\n' at end of file with warning W391.
It does not find any error if the file ends with '\n' only.
I don't see any misbehaviour here.

@DXist
Copy link
Author

DXist commented Mar 26, 2012

I've installed pep8 0.7.0 from PyPI.

Then I did:

$ echo -en '\n' > /tmp/test.py
$ pep8 /tmp/test.py
/tmp/test.py:1:1: W391 blank line at end of file

So pep8 from PyPI still has this problem

@florentx
Copy link
Contributor

You did not do the right test.

echo -en 'a\n' > /tmp/test.py
pep8.py /tmp/test.py

@DXist
Copy link
Author

DXist commented Mar 26, 2012

Right. So I close the issue.

@DXist DXist closed this as completed Mar 26, 2012
@techtonik
Copy link

PEP8 doesn't require that files are ending with blank lines - http://www.python.org/dev/peps/pep-0008/
Actually it is convenient to have \n\n at the end of file at least in Vim, and not \n\n\n.

@DXist
Copy link
Author

DXist commented May 22, 2012

Yes, Vim treats \n as end of line, not as carriage return like in many editors. So I may type one symbol less - less typing - less work :-)

@techtonik
Copy link

Actually it is more typing, because without \n\n in Vim you can not just go to the end of file an press enter. You enter will at the start of the last line. It suxx that PEP8 validator forces everybody to this annoyance.

@DXist
Copy link
Author

DXist commented May 22, 2012

You can type o command to start new line after you go to the end of file

@techtonik
Copy link

Yes, I can, but I forget all the time.

@techtonik
Copy link

And still PEP8 doesn't require that files should not end with blank lines.

@florentx
Copy link
Contributor

I understand each developer has its habits.
I use Vim, and I regularly check my code with pep8.py. I don't see a problem with the default settings.

If you like, you can pass --ignore W29 argument to disable the three warnings which are not strictly PEP8: trailing spaces and new lines at end of file.

@techtonik
Copy link

Of course developers have habits. Why make it more harder for other people if doesn't make any difference for yourself? Will the presence of \n\n endspace instead of \n bug you more than absence of \n\n bugs me, DXist and other people? You still can apply your rule to count('\n') > 2

@jorgesumle
Copy link

W391 is annoying.

@The-Compiler
Copy link
Member

@jorgesumle So turn it off? I find it useful.

@techtonik
Copy link

I remember there was some unix story about those linefeeds at the end of file, so this must be some unix kludge from the past and now is a cargo ritual. =)

@DXist
Copy link
Author

DXist commented Sep 7, 2016

Nice point from http://stackoverflow.com/questions/5813311/no-newline-at-end-of-file

The message is displayed because otherwise there is no way to tell the difference between a file where there is a newline at the end and one where is not. Diff has to output a newline anyway, or the result would be harder to read or process automatically.

Note that it is a good style to always put the newline as a last character if it is allowed by the file format. Furthermore, for example, for C and C++ header files it is required by the language standard.

So the last new line is important for diff tools (including Github) and must have for C/C++. I guess early C development toolchain incorrectly handled the last line without line terminator symbols.

I think new line at the end of file is a part of best practices and I dislike editors/IDEs that don't put last new line by default. Rituals support common and clear coding style.

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

5 participants