From bef24c2dc7c59f328de8adffa494f04d75128136 Mon Sep 17 00:00:00 2001 From: Glyphack Date: Tue, 30 Jan 2024 23:54:05 +0100 Subject: [PATCH] Format module level docstring --- crates/ruff_python_formatter/src/statement/suite.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index efcf6eff3d75b3..42756894763434 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -140,7 +140,13 @@ impl FormatRule> for FormatSuite { SuiteChildStatement::Other(first) } } - SuiteKind::TopLevel => SuiteChildStatement::Other(first), + SuiteKind::TopLevel => { + if let Some(docstring) = DocstringStmt::try_from_statement(first, self.kind) { + SuiteChildStatement::Docstring(docstring) + } else { + SuiteChildStatement::Other(first) + } + } }; let first_comments = comments.leading_dangling_trailing(first);