Skip to content

Commit 53aa7dc

Browse files
authored
Merge pull request #152 from olehermanse/main
cfengine format: Fixed issue causing no empty line before comment + promise types
2 parents 72a8bac + b234cc2 commit 53aa7dc

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/cfengine_cli/format.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,14 +747,13 @@ def _needs_blank_line_before(child: Node, indent: int, line_length: int) -> bool
747747
if prev.type in BLOCK_TYPES:
748748
return True
749749
parent = child.parent
750-
# Trailing comment at the end of a bundle body lands deeply
751-
# indented (aligned with the deepest attribute); insert a blank
752-
# line so it doesn't run into the preceding section.
750+
# Comment at bundle_block_body level after a bundle_section —
751+
# either a trailing comment for the previous section or a leading
752+
# comment for the next one. Either way, visually separate it.
753753
if (
754754
prev.type == "bundle_section"
755755
and parent
756756
and parent.type == "bundle_block_body"
757-
and _skip_comments(child.next_named_sibling, "next") is None
758757
):
759758
return True
760759
if parent and parent.type in {"bundle_section", "class_guarded_promises"}:

tests/format/005_bundle_comments.expected.cf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,27 @@ bundle agent trailing_example_3
104104

105105
# Trailing
106106
}
107+
108+
bundle agent before_promise_types
109+
{
110+
# Reports promises:
111+
reports:
112+
"Hello, world!";
113+
114+
# Classes:
115+
classes:
116+
"myclass" if => "foo";
117+
118+
# Variables:
119+
# Multi line
120+
vars:
121+
"myvar"
122+
string => "bar",
123+
if => "foo";
124+
125+
# More reports:
126+
reports:
127+
"Lorem ipsum";
128+
129+
# Trailing comment
130+
}

tests/format/005_bundle_comments.input.cf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,23 @@ if => "bar";
101101

102102
# Trailing
103103
}
104+
105+
bundle agent before_promise_types
106+
{
107+
# Reports promises:
108+
reports:
109+
"Hello, world!";
110+
# Classes:
111+
classes:
112+
"myclass" if => "foo";
113+
# Variables:
114+
# Multi line
115+
vars:
116+
"myvar"
117+
string => "bar",
118+
if => "foo";
119+
# More reports:
120+
reports:
121+
"Lorem ipsum";
122+
# Trailing comment
123+
}

tests/format/011_promises.expected.cf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ bundle common services_autorun
505505
services_autorun|services_autorun_inputs|services_autorun_bundles::
506506
"inputs" slist => { "$(sys.local_libdir)/autorun.cf" };
507507
"bundles" slist => { "autorun" };
508+
508509
# run loaded bundles
509510
reports:
510511
DEBUG|DEBUG_services_autorun::

0 commit comments

Comments
 (0)