allow_empty_first_line_before_new_block_or_comment
can lead to inconsistent formatting
#4121
Labels
C: preview style
Issues with the preview and unstable style. Add the name of the responsible feature in the title.
T: style
What do we want Blackened code to look like?
Describe the style change
I am working on Ruff's formatter and implementing Black's preview styles. We reviewed the
allow_empty_first_line_before_new_block_or_comment
preview style and decided not to implement it because it leads to inconsistent formatting after moving or deleting code or requires more manual intervention.Examples when
allow_empty_first_line_before_new_block_or_comment
is enabledI work on a refactoring and start with the following code:
And I delete the
no_longer_needed
branch:Black removes the empty line above the comment when the
allow_empty_first_line_before_new_block_or_comment
style is disabled.Black doesn't remove the empty line when enabling
allow_empty_first_line_before_new_block_or_comment,
which either results in an unintended empty line above the comment (inconsistency) or that I have to intervene and remove the empty line manually. This feels like something I would expect a formatter to do for me (at the cost that having empty lines before comments isn't possible)Desired style
To keep the non-preview formatting for comments at the start of a block.
Additional context
The text was updated successfully, but these errors were encountered: