From 88cab2961c6dbcefaeadf2fdb9e6c94163d5b5d0 Mon Sep 17 00:00:00 2001 From: Jon Egeland Date: Fri, 15 Dec 2023 19:52:44 +0000 Subject: [PATCH] feedback --- crates/biome_formatter/src/comments.rs | 6 ++++++ crates/biome_formatter/src/trivia.rs | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/biome_formatter/src/comments.rs b/crates/biome_formatter/src/comments.rs index dd2030a765ac..789281adc106 100644 --- a/crates/biome_formatter/src/comments.rs +++ b/crates/biome_formatter/src/comments.rs @@ -1220,6 +1220,12 @@ pub fn is_alignable_comment(comment: &SyntaxTriviaPieceComments) }) } +/// **TODO:** This is really JS-specific logic, both in syntax and semantics. +/// It should probably be moved to `biome_js_formatter` when possible, but is +/// currently tied to other behavior about formatting sets of comments (which +/// might also be best to move as well, since it relates to the same specific +/// behavior). +/// /// Returns `true` if `comment` is a documentation-style comment, specifically /// matching the JSDoc format where the comment: /// - spans over multiple lines diff --git a/crates/biome_formatter/src/trivia.rs b/crates/biome_formatter/src/trivia.rs index b10221120f58..714c195b6693 100644 --- a/crates/biome_formatter/src/trivia.rs +++ b/crates/biome_formatter/src/trivia.rs @@ -66,7 +66,8 @@ where FormatLeadingComments::Comments(comments) => comments, }; - for (index, comment) in leading_comments.iter().enumerate() { + let mut leading_comments_iter = leading_comments.iter().peekable(); + while let Some(comment) = leading_comments_iter.next() { let format_comment = FormatRefWithRule::new(comment, Context::CommentRule::default()); write!(f, [format_comment])?; @@ -75,11 +76,9 @@ where match comment.lines_after() { 0 => { let should_nestle = - leading_comments - .get(index + 1) - .map_or(false, |next_comment| { - should_nestle_adjacent_doc_comments(comment, next_comment) - }); + leading_comments_iter.peek().map_or(false, |next_comment| { + should_nestle_adjacent_doc_comments(comment, next_comment) + }); write!(f, [maybe_space(!should_nestle)])?; }