Giter Site home page Giter Site logo

blank line at end of file about pycodestyle HOT 16 CLOSED

DXist avatar DXist commented on May 12, 2024
blank line at end of file

from pycodestyle.

Comments (16)

DXist avatar DXist commented on May 12, 2024 1

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

from pycodestyle.

florentx avatar florentx commented on May 12, 2024

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.

from pycodestyle.

DXist avatar DXist commented on May 12, 2024

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

from pycodestyle.

florentx avatar florentx commented on May 12, 2024

You did not do the right test.

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

from pycodestyle.

DXist avatar DXist commented on May 12, 2024

Right. So I close the issue.

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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.

from pycodestyle.

DXist avatar DXist commented on May 12, 2024

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 :-)

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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.

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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

from pycodestyle.

florentx avatar florentx commented on May 12, 2024

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.

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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

from pycodestyle.

jorgesumle avatar jorgesumle commented on May 12, 2024

W391 is annoying.

from pycodestyle.

The-Compiler avatar The-Compiler commented on May 12, 2024

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

from pycodestyle.

techtonik avatar techtonik commented on May 12, 2024

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. =)

from pycodestyle.

DXist avatar DXist commented on May 12, 2024

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.

from pycodestyle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.