BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF allows adding a blank line before nested classes or methods.
Ideally, a knob would allow setting a specified amount of blank lines near:
Alternatively, offer a knob can allow "maximum blank lines", thus allowing blank lines after imports (for example). Right now they get formatted away.
This is possible. I'll mark it as an "enhancement". Thanks!
yapf and isort currently handle blank lines near Top-level imports and comments differently. isort is happy with this:
from foo import bar
# Public
def baz():
pass
but yapf wants to remove a line between the import and the comment.
from foo import bar
# Public
def baz():
pass
Irrespective of isort's behaviour, it would be nice to control the number of spaces here so there's 2 (ideally configurable) both above and below the comment. Should behave the same when there's a constant too.
from foo import bar
QUX = 'quux'
# Public
def baz():
pass
I have the same "infinite formatting loop" in PyCharm.
In the JavaScript world, you have eslint --fix and you have WebStorm following your .eslintrc file - so there's no such issue.
This is one of the reasons I don't actually use yapf but rather a series of unify, autopep8, flake8 and pylint. I guess I'll add isort too. :)
Adding the knobs shouldn't be too hard. I'll bump up the priority here.
I would also add a request knobs around number of blank lines inside functions (currently always exactly 1) and inside dictionaries (always exactly 0).
Kinda like eslint's no-multiple-empty-lines's max option.
Inside a function I'd like to have the ability to use 2 lines to break up different sections, and inside long dictionaries, I'd like to be able to group logical sets of key/values.
A knob BLANK_LINES_BETWEEN_TOP_LEVEL_IMPORTS_AND_VARIABLES will be available in version 0.31.0 of YAPF
Most helpful comment
Adding the knobs shouldn't be too hard. I'll bump up the priority here.