ruff/crates/ruff_python_formatter/src
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
..
comments Update Rust crate rustc-hash to v2 (#12001) 2024-06-23 20:46:42 -04:00
expression Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
module Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
other Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
pattern Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
snapshots Remove exception-handler lexing from unused-bound-exception fix (#5851) 2023-07-18 18:27:46 +00:00
statement Insert empty line between suite and alternative branch after def/class (#12294) 2024-07-15 12:59:33 +02:00
string Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
type_param Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
builders.rs Avoid multiline expression if format specifier is present (#11123) 2024-04-26 13:34:38 +00:00
cli.rs Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
context.rs Maintain synchronicity between the lexer and the parser (#11457) 2024-06-03 18:23:50 +05:30
generated.rs Remove Expr postfix from ExprNamed, ExprIf, and ExprGenerator (#10229) 2024-03-04 12:55:01 +01:00
lib.rs Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
main.rs Formatter and parser refactoring (#7569) 2023-09-26 15:29:43 +02:00
options.rs Add Python 3.13 to list of allowed Python versions (#11411) 2024-05-13 16:35:41 +00:00
prelude.rs Accept any Into<AnyNodeRef> as Comments arguments (#5205) 2023-06-20 16:49:21 +00:00
preview.rs Use space separator before parenthesiszed expressions in comprehensions with leading comments. (#12282) 2024-07-11 22:38:12 +02:00
range.rs Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
shared_traits.rs ruff_python_formatter: copy and inline shared traits (#8656) 2023-11-13 12:16:04 -05:00
verbatim.rs Fix formatter instability for lines only consisting of zero-width characters (#11748) 2024-06-05 17:55:14 +02:00