Skip to content

Allow one empty newline after class header #21380

@laymonage

Description

@laymonage

Summary

Ref: #8566, #9745 (comment), #9745 (comment), #9745 (comment), #9745 (comment).

Description

Black's 2022 style removes empty newlines after code block open. However, as of the 2024 style, it now allows one empty first line at the beginning of most blocks (psf/black#3967).

For class headers, Ruff still follows the 2022 style, producing the following result:

Input file

class Migration(migrations.Migration):

    dependencies = []

black

class Migration(migrations.Migration):

    dependencies = []

ruff

class Migration(migrations.Migration):
    dependencies = []

Use case

For us, this is a blocker when migrating from black to ruff for formatting Django migrations, as it would produce noisy diffs that are otherwise avoidable.

As of #21110 (v0.14.4), one empty newline is now allowed after function headers. I'd like to make a case for class headers as well.

Thanks for all the great work!

Version

0.14.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatterstyleHow should formatted code look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions