Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,12 @@ def _needs_blank_line_before(child: Node, indent: int, line_length: int) -> bool
if child.type == "comment":
if _is_empty_comment(child):
return False
# Empty comments preceding this one will be dropped — look past them
# so we treat the comment as following the real prior content.
while prev and prev.type == "comment" and _is_empty_comment(prev):
prev = prev.prev_named_sibling
if prev is None:
return False
# Top-level comment after a complete block — visually separates them
if prev.type in BLOCK_TYPES:
return True
Expand Down
7 changes: 7 additions & 0 deletions tests/format/004_comments.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,10 @@ body package_method cgcacgcac
# bar
package_changes => "bulk";
}

# Example here:
bundle agent stigs
{
vars:
"foo" string => "bar";
}
10 changes: 10 additions & 0 deletions tests/format/004_comments.input.cf
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,13 @@ package_changes => "bulk";
# bar
package_changes => "bulk";
}

#
# Example here:
#

bundle agent stigs
{
vars:
"foo" string => "bar";
}
Loading