Skip to content

tooling: Enable ruff preview rules E302 and E303 for blank line enforcement. #400

@nedseb

Description

@nedseb

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions