mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
![]() <!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary This issue fixes the removal of empty lines between a leading comment and the previous statement: ```python a = 20 # leading comment b = 10 ``` Ruff removed the empty line between `a` and `b` because: * The leading comments formatting does not preserve leading newlines (to avoid adding new lines at the top of a body) * The `JoinNodesBuilder` counted the lines before `b`, which is 1 -> Doesn't insert a new line This is fixed by changing the `JoinNodesBuilder` to count the lines instead *after* the last node. This correctly gives 1, and the `# leading comment` will insert the empty lines between any other leading comment or the node. ## Test Plan I added a new test for empty lines. |
||
---|---|---|
.. | ||
mod.rs | ||
stmt_ann_assign.rs | ||
stmt_assert.rs | ||
stmt_assign.rs | ||
stmt_async_for.rs | ||
stmt_async_function_def.rs | ||
stmt_async_with.rs | ||
stmt_aug_assign.rs | ||
stmt_break.rs | ||
stmt_class_def.rs | ||
stmt_continue.rs | ||
stmt_delete.rs | ||
stmt_expr.rs | ||
stmt_for.rs | ||
stmt_function_def.rs | ||
stmt_global.rs | ||
stmt_if.rs | ||
stmt_import.rs | ||
stmt_import_from.rs | ||
stmt_match.rs | ||
stmt_nonlocal.rs | ||
stmt_pass.rs | ||
stmt_raise.rs | ||
stmt_return.rs | ||
stmt_try.rs | ||
stmt_try_star.rs | ||
stmt_while.rs | ||
stmt_with.rs | ||
suite.rs |