Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nbacquey committed Jan 9, 2025
1 parent 0e1d3a1 commit e2a01c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
18 changes: 14 additions & 4 deletions topiary-core/src/atom_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions topiary-core/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions topiary-core/tests/comment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ fn test_extract_comments() {
let mut expected_comments: Vec<AnchoredComment> = 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,
},
Expand All @@ -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,
Expand Down

0 comments on commit e2a01c9

Please sign in to comment.