Formatter: request for a Rule Similar to ESLint’s padding-line-between-statements
Hey, guys!
I’d like to propose a new rule for Ruff formatter, that mirrors ESLint’s padding-line-between-statements rule. This rule would add blank lines between specific statements in Python code, making it easier to read and understand.
The rule could enforce adding a blank line after an if/while/for/etc statement block. This would help to visually separate different sections of code, improving clarity.
Before:
def process_data(value: int, data: dict) -> None:
if data["some_key"] and value != 0:
print("blah-blah-blah")
...
print("blah-blah-blah")
key = data["key"]
...After:
def process_data(value: int, data: dict) -> None:
if data["some_key"] and value != 0:
print("blah-blah-blah")
....
print("blah-blah-blah")
key = data["key"]
...In the second example, the blank line after the if block makes the code structure clearer.
Is it possible to implement such a rule in Ruff? I believe this could be a useful feature for enhancing code readability in Python projects.
I’m not sure if this behavior should be enabled by default, but it would be great to have the option to configure these padding rules flexibly. For example, similar to how Ruff currently handles import groupings, it would be useful to allow developers to specify where these blank lines should or should not appear.
Source: astral-sh/ruff