mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-27 22:04:45 +00:00
Add empty lines before nested functions and classes (#6206)
## Summary This PR ensures that if a function or class is the first statement in a nested suite that _isn't_ a function or class body, we insert a leading newline. For example, given: ```python def f(): if True: def register_type(): pass ``` We _want_ to preserve the newline, whereas today, we remove it. Note that this only applies when the function or class doesn't have any leading comments. Closes https://github.com/astral-sh/ruff/issues/6066.
This commit is contained in:
parent
b68f76f0d9
commit
928ab63a64
8 changed files with 64 additions and 43 deletions
|
@ -1,4 +1,4 @@
|
|||
use crate::statement::suite::SuiteLevel;
|
||||
use crate::statement::suite::SuiteKind;
|
||||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::hard_line_break;
|
||||
use ruff_formatter::{write, Buffer, FormatResult};
|
||||
|
@ -13,7 +13,7 @@ impl FormatNodeRule<ModModule> for FormatModModule {
|
|||
write!(
|
||||
f,
|
||||
[
|
||||
body.format().with_options(SuiteLevel::TopLevel),
|
||||
body.format().with_options(SuiteKind::TopLevel),
|
||||
// Trailing newline at the end of the file
|
||||
hard_line_break()
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue