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
7 changes: 3 additions & 4 deletions src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,14 +747,13 @@ def _needs_blank_line_before(child: Node, indent: int, line_length: int) -> bool
if prev.type in BLOCK_TYPES:
return True
parent = child.parent
# Trailing comment at the end of a bundle body lands deeply
# indented (aligned with the deepest attribute); insert a blank
# line so it doesn't run into the preceding section.
# Comment at bundle_block_body level after a bundle_section —
# either a trailing comment for the previous section or a leading
# comment for the next one. Either way, visually separate it.
if (
prev.type == "bundle_section"
and parent
and parent.type == "bundle_block_body"
and _skip_comments(child.next_named_sibling, "next") is None
):
return True
if parent and parent.type in {"bundle_section", "class_guarded_promises"}:
Expand Down
24 changes: 24 additions & 0 deletions tests/format/005_bundle_comments.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,27 @@ bundle agent trailing_example_3

# Trailing
}

bundle agent before_promise_types
{
# Reports promises:
reports:
"Hello, world!";

# Classes:
classes:
"myclass" if => "foo";

# Variables:
# Multi line
vars:
"myvar"
string => "bar",
if => "foo";

# More reports:
reports:
"Lorem ipsum";

# Trailing comment
}
20 changes: 20 additions & 0 deletions tests/format/005_bundle_comments.input.cf
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,23 @@ if => "bar";

# Trailing
}

bundle agent before_promise_types
{
# Reports promises:
reports:
"Hello, world!";
# Classes:
classes:
"myclass" if => "foo";
# Variables:
# Multi line
vars:
"myvar"
string => "bar",
if => "foo";
# More reports:
reports:
"Lorem ipsum";
# Trailing comment
}
1 change: 1 addition & 0 deletions tests/format/011_promises.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ bundle common services_autorun
services_autorun|services_autorun_inputs|services_autorun_bundles::
"inputs" slist => { "$(sys.local_libdir)/autorun.cf" };
"bundles" slist => { "autorun" };

# run loaded bundles
reports:
DEBUG|DEBUG_services_autorun::
Expand Down
Loading