ruff/crates/ruff_python_formatter/src/statement
konsti 9a817a2922
Insert empty line between suite and alternative branch after def/class (#12294)
When there is a function or class definition at the end of a suite
followed by the beginning of an alternative block, we have to insert a
single empty line between them.

In the if-else-statement example below, we insert an empty line after
the `foo` in the if-block, but none after the else-block `foo`, since in
the latter case the enclosing suite already adds empty lines.

```python
if sys.version_info >= (3, 10):
    def foo():
        return "new"
else:
    def foo():
        return "old"
class Bar:
    pass
```

To do so, we track whether the current suite is the last one in the
current statement with a new option on the suite kind.

Fixes #12199

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
2024-07-15 12:59:33 +02:00
..
clause.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
mod.rs Preserve trailing statement semicolons when using fmt: skip (#8273) 2023-10-30 00:07:14 +00:00
stmt_ann_assign.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_assert.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_assign.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_aug_assign.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_break.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_class_def.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_continue.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_delete.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
stmt_expr.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_for.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_function_def.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_global.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_if.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_import.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_import_from.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
stmt_ipy_escape_command.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_match.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_nonlocal.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_pass.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_raise.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_return.rs Implement RUF028 to detect useless formatter suppression comments (#9899) 2024-02-28 19:21:06 +00:00
stmt_try.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_type_alias.rs Ruff 2024.2 style (#9639) 2024-02-29 09:30:54 +01:00
stmt_while.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
stmt_with.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
suite.rs Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00