mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Fix dangling module comments (#7456)
This commit is contained in:
parent
959338d39d
commit
26ae0a6e8d
8 changed files with 58 additions and 32 deletions
|
@ -1,10 +1,10 @@
|
|||
use ruff_formatter::prelude::hard_line_break;
|
||||
use ruff_formatter::{Buffer, FormatResult};
|
||||
use ruff_formatter::write;
|
||||
use ruff_python_ast::ModModule;
|
||||
|
||||
use crate::comments::{trailing_comments, SourceComment};
|
||||
use crate::comments::SourceComment;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::suite::SuiteKind;
|
||||
use crate::{write, AsFormat, FormatNodeRule, PyFormatter};
|
||||
use crate::FormatNodeRule;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatModModule;
|
||||
|
@ -12,13 +12,11 @@ pub struct FormatModModule;
|
|||
impl FormatNodeRule<ModModule> for FormatModModule {
|
||||
fn fmt_fields(&self, item: &ModModule, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
let ModModule { range: _, body } = item;
|
||||
let comments = f.context().comments().clone();
|
||||
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
body.format().with_options(SuiteKind::TopLevel),
|
||||
trailing_comments(comments.dangling(item)),
|
||||
// Trailing newline at the end of the file
|
||||
hard_line_break()
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue