Context
While reviewing PR #376, a missing blank line before a top-level function definition (PEP 8 E302) and an extra blank line inside a block (E303) were caught manually but not by ruff.
Root cause
In ruff 0.11.6, E302 and E303 are preview rules:
$ ruff rule E302 | grep preview
This rule is in preview and is not stable. The --preview flag is required for use.
Our pyproject.toml enables preview mode but with explicit-preview-rules = true, which means only preview rules explicitly listed in select are active. We already list E225, E261, E262, E265 as explicit preview rules, but not E302/E303.
preview = true
explicit-preview-rules = true
select = [
"E", # pycodestyle — but E302/E303 are preview, so not active
"E225", # (preview) ← explicitly enabled
"E261", # (preview)
"E262", # (preview)
"E265", # (preview)
...
]
Fix
Add E302 and E303 to the explicit select list:
"E302", # (preview) expected 2 blank lines before function/class definition
"E303", # (preview) too many blank lines
Verification
After the fix, running ruff check on a file with a single blank line before a top-level def should trigger E302.
Related
Context
While reviewing PR #376, a missing blank line before a top-level function definition (PEP 8 E302) and an extra blank line inside a block (E303) were caught manually but not by ruff.
Root cause
In ruff 0.11.6, E302 and E303 are preview rules:
Our
pyproject.tomlenables preview mode but withexplicit-preview-rules = true, which means only preview rules explicitly listed inselectare active. We already listE225,E261,E262,E265as explicit preview rules, but not E302/E303.Fix
Add
E302andE303to the explicit select list:Verification
After the fix, running
ruff checkon a file with a single blank line before a top-leveldefshould trigger E302.Related