Reusable Fixit rules for blank-line and statement-cuddling policy checks.
pip install "git+https://github.com/zigai/flake8-blank-lines.git"uv add "git+https://github.com/zigai/flake8-blank-lines.git"Add the rule pack to your project configuration:
[tool.fixit]
root = true
enable = ["fixit_blank_lines.rules"]
disable = [
"fixit_blank_lines.rules:BlockHeaderCuddleStrict",
]Run linting and autofix:
fixit lint <path>
fixit lint --diff <path>
fixit fix --automatic <path>For in-file suppressions, use Fixit comments:
# lint-ignore: RuleName# lint-fixme: RuleName
Removes leading and trailing blank lines at suite boundaries.
Before:
def f() -> int:
value = 1
return valueAfter:
def f() -> int:
value = 1
return valueIn suites larger than 2 non-empty lines, requires a blank line before return/raise/break/continue.
Before:
def f(value: int) -> int:
x = value + 1
y = x + 1
z = y + 1
return zAfter:
def f(value: int) -> int:
x = value + 1
y = x + 1
z = y + 1
return zAllows assignment-before-block cuddling only when the final prep assignment feeds the block header or first body statement.
The first statement after a suite docstring is exempt (Ruff D202 compatibility).
Before:
def f(value: int) -> int:
prepared = value + 1
if value > 0:
return value
return 0After:
def f(value: int) -> int:
prepared = value + 1
if value > 0:
return value
return 0Stricter cuddle mode: only the immediately previous assignment may feed the block header.
The first statement after a suite docstring is exempt (Ruff D202 compatibility).
Before:
def f(value: int) -> int:
header_value = value + 1
trailing = value + 2
if header_value > 0:
return header_value
return 0After:
def f(value: int) -> int:
header_value = value + 1
trailing = value + 2
if header_value > 0:
return header_value
return 0Requires a separator after multiline control-flow blocks.
Before:
def f(value: int) -> int:
if value > 0:
value += 1
return valueAfter:
def f(value: int) -> int:
if value > 0:
value += 1
return valueRequires a separator before an assignment when it follows a non-assignment statement, except when the assignment directly follows a suite docstring.
Before:
def f() -> int:
log_start()
value = compute()
return valueAfter:
def f() -> int:
log_start()
value = compute()
return valueRequires a separator before the next case when a case body is larger than 2 non-empty lines.
Before:
def f(value: int) -> int:
match value:
case 1:
a = 1
b = 2
c = 3
case _:
return 0After:
def f(value: int) -> int:
match value:
case 1:
a = 1
b = 2
c = 3
case _:
return 0