From e2a01c977a26d149747ea12f462963746a121e3d Mon Sep 17 00:00:00 2001 From: Nicolas BACQUEY Date: Thu, 9 Jan 2025 12:38:50 +0100 Subject: [PATCH] lint --- topiary-core/src/atom_collection.rs | 18 ++++++++++++++---- topiary-core/src/comments.rs | 8 ++++---- topiary-core/tests/comment_tests.rs | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/topiary-core/src/atom_collection.rs b/topiary-core/src/atom_collection.rs index 02feacd9..872da2fd 100644 --- a/topiary-core/src/atom_collection.rs +++ b/topiary-core/src/atom_collection.rs @@ -959,17 +959,22 @@ impl AtomCollection { single_line_no_indent: false, multi_line_indent_all: true, }; - comments_queue_with_context.push_front(CommentWithContext{ + comments_queue_with_context.push_front(CommentWithContext { comment: comment_atom, blank_line_after, - blank_line_before + blank_line_before, }); } atoms_with_comments_before.push_front(atom); } else if Atom::Hardline == atom || Atom::Blankline == atom { let mut blank_line_before_first_comment = false; // Prepend the comments, each one followed by a newline - while let Some(CommentWithContext{comment, blank_line_after, blank_line_before}) = comments_queue_with_context.pop_back() { + while let Some(CommentWithContext { + comment, + blank_line_after, + blank_line_before, + }) = comments_queue_with_context.pop_back() + { if blank_line_after { atoms_with_comments_before.push_front(Atom::Blankline) } else { @@ -989,7 +994,12 @@ impl AtomCollection { } let mut blank_line_before_first_comment = false; // If we still have comments left, add them at the beginning of the file - while let Some(CommentWithContext{comment, blank_line_after, blank_line_before}) = comments_queue_with_context.pop_back() { + while let Some(CommentWithContext { + comment, + blank_line_after, + blank_line_before, + }) = comments_queue_with_context.pop_back() + { if blank_line_after { atoms_with_comments_before.push_front(Atom::Blankline) } else { diff --git a/topiary-core/src/comments.rs b/topiary-core/src/comments.rs index 61264b34..82257583 100644 --- a/topiary-core/src/comments.rs +++ b/topiary-core/src/comments.rs @@ -378,8 +378,8 @@ fn find_anchor<'tree>(node: &'tree Node<'tree>, input: &str) -> FormatterResult< })?; if prefix.trim_start() == "" { if let Some(anchor) = next_non_comment_leaf(node.clone()) { - let prev = previous_disjoint_node(&node); - let next = next_disjoint_node(&node); + let prev = previous_disjoint_node(node); + let next = next_disjoint_node(node); Ok(Commented::CommentedAfter { section: (&anchor).into(), blank_line_after: next @@ -400,8 +400,8 @@ fn find_anchor<'tree>(node: &'tree Node<'tree>, input: &str) -> FormatterResult< if let Some(anchor) = previous_non_comment_leaf(node.clone()) { Ok(Commented::CommentedBefore((&anchor).into())) } else if let Some(anchor) = next_non_comment_leaf(node.clone()) { - let prev = previous_disjoint_node(&node); - let next = next_disjoint_node(&node); + let prev = previous_disjoint_node(node); + let next = next_disjoint_node(node); Ok(Commented::CommentedAfter { section: (&anchor).into(), blank_line_after: next diff --git a/topiary-core/tests/comment_tests.rs b/topiary-core/tests/comment_tests.rs index 7dee998a..f28a2c83 100644 --- a/topiary-core/tests/comment_tests.rs +++ b/topiary-core/tests/comment_tests.rs @@ -55,10 +55,10 @@ fn test_extract_comments() { let mut expected_comments: Vec = vec![ AnchoredComment { comment_text: "(* starting comment *)".into(), - commented: CommentedAfter{ + commented: CommentedAfter { section: FUN_SECTION, blank_line_after: false, - blank_line_before: false + blank_line_before: false, }, original_column: 0, }, @@ -74,7 +74,7 @@ fn test_extract_comments() { }, AnchoredComment { comment_text: "(** multi-lined\n * body comment\n *)".into(), - commented: CommentedAfter{ + commented: CommentedAfter { section: BODY_SECTION, blank_line_after: false, blank_line_before: false,