factor out parameters_have_comments

This commit is contained in:
Brent Westbrook 2025-12-05 14:57:54 -05:00
parent 3c481ba0ed
commit 4d76cd7b15
No known key found for this signature in database
1 changed files with 3 additions and 1 deletions

View File

@ -31,6 +31,8 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
write!(f, [token("lambda")])?; write!(f, [token("lambda")])?;
if let Some(parameters) = parameters { if let Some(parameters) = parameters {
let parameters_have_comments = comments.contains_comments(parameters.as_ref().into());
// In this context, a dangling comment can either be a comment between the `lambda` and the // In this context, a dangling comment can either be a comment between the `lambda` and the
// parameters, or a comment between the parameters and the body. // parameters, or a comment between the parameters and the body.
let (dangling_before_parameters, dangling_after_parameters) = dangling let (dangling_before_parameters, dangling_after_parameters) = dangling
@ -43,7 +45,7 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
} }
// Try to keep the parameters on a single line, unless there are intervening comments. // Try to keep the parameters on a single line, unless there are intervening comments.
if preview && !comments.contains_comments(parameters.as_ref().into()) { if preview && !parameters_have_comments {
let mut buffer = RemoveSoftLinesBuffer::new(f); let mut buffer = RemoveSoftLinesBuffer::new(f);
write!( write!(
buffer, buffer,