mirror of https://github.com/astral-sh/ruff
add preview function taking a PreviewMode
This commit is contained in:
parent
9f9b76b035
commit
a8bebaa681
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue