Make Pylint care about blank lines
Asked Answered
G

1

18

I am not a stickler for most things pep-8, but certain things I personally prefer when writing code (as opposed to for work, where I would adhere to the style or lack thereof of the existing code base).

One thing I personally tend to follow is pep-8's suggestion about blank lines:

Surround top-level function and class definitions with two blank lines.

Method definitions inside a class are surrounded by a single blank line.

However, I have not been able to get Pylint to warn me when I violate this. I don't see anything that seems relevant disabled in my .pylintrc, and I have not been able to figure out if this is possible in Pylint, and if so, how to enable it.

Based on this answer, it looks like there are certain aspects of pep-8 that Pylint does not (or did not at the time) cover, but I have not been able to ascertain whether this is the case for blank lines.

Is it possible to have Pylint warn about blank lines (too many/not enough) without writing custom extensions?

Gil answered 10/11, 2016 at 3:28 Comment(3)
I don't know for sure, but I searched for "line" in what I think is the best documentation of pylint's features, and I didn't find anything: pylint.readthedocs.io/en/latest/reference_guide/…Reber
@Reber haha, yeah. That is the first thing I tried too...Seems like it is not a current feature unfortunately.Gil
If a different solution is acceptable: PyCharm flags it.Dement
S
3

As mentioned in this other answer, E301 and E303 doesn't seem to be a thing in pylint (yet?).

One alternative would be to use the pycodestyle (previously: pep8) tool directly, which would allow you to check for blank lines.

Hopefully you'll like it as much as pylint, despite maybe being a little bit less configurable.

Skipton answered 11/5, 2017 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.