From a8bebaa681432ed81a7c6fb79f5945b21ec56586 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Wed, 10 Dec 2025 12:19:55 -0500 Subject: [PATCH] add preview function taking a PreviewMode --- crates/ruff_python_formatter/src/comments/placement.rs | 5 +++-- crates/ruff_python_formatter/src/preview.rs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index 8f8121f1b6..8a01e274c1 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -19,6 +19,7 @@ use crate::other::parameters::{ assign_argument_separator_comment_placement, find_parameter_separators, }; use crate::pattern::pattern_match_sequence::SequenceType; +use crate::preview::is_parenthesize_lambda_bodies_enabled_preview; /// Manually attach comments to nodes that the default placement gets wrong. pub(super) fn place_comment<'a>( @@ -1885,7 +1886,7 @@ fn handle_lambda_comment<'a>( return CommentPlacement::Default(comment); } - return if preview.is_enabled() { + return if is_parenthesize_lambda_bodies_enabled_preview(preview) { CommentPlacement::leading(&*lambda.body, comment) } else { CommentPlacement::dangling(comment.enclosing_node(), comment) @@ -1918,7 +1919,7 @@ fn handle_lambda_comment<'a>( return CommentPlacement::Default(comment); } - return if preview.is_enabled() { + return if is_parenthesize_lambda_bodies_enabled_preview(preview) { CommentPlacement::leading(&*lambda.body, comment) } else { CommentPlacement::dangling(comment.enclosing_node(), comment) diff --git a/crates/ruff_python_formatter/src/preview.rs b/crates/ruff_python_formatter/src/preview.rs index 62b6b90033..86738daa1a 100644 --- a/crates/ruff_python_formatter/src/preview.rs +++ b/crates/ruff_python_formatter/src/preview.rs @@ -5,7 +5,7 @@ //! for which specific feature this preview check is for. Having named functions simplifies the promotion: //! Simply delete the function and let Rust tell you which checks you have to remove. -use crate::PyFormatContext; +use crate::{PreviewMode, PyFormatContext}; /// Returns `true` if the [`hug_parens_with_braces_and_square_brackets`](https://github.com/astral-sh/ruff/issues/8279) preview style is enabled. pub(crate) const fn is_hug_parens_with_braces_and_square_brackets_enabled( @@ -59,3 +59,6 @@ pub(crate) const fn is_avoid_parens_for_long_as_captures_enabled( pub(crate) const fn is_parenthesize_lambda_bodies_enabled(context: &PyFormatContext) -> bool { context.is_preview() } +pub(crate) const fn is_parenthesize_lambda_bodies_enabled_preview(preview: PreviewMode) -> bool { + preview.is_enabled() +}