From 689ac43c4db76b67e3400aaf7307fe916b02f9c8 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 16 Apr 2026 01:04:50 +0200 Subject: [PATCH 1/3] tests: Added formatting test for leaving empty line when removing empty comment(s) Signed-off-by: Ole Herman Schumacher Elgesem --- tests/format/005_bundle_comments.expected.cf | 5 +++++ tests/format/005_bundle_comments.input.cf | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/format/005_bundle_comments.expected.cf b/tests/format/005_bundle_comments.expected.cf index 9d3b8ab..519d7a9 100644 --- a/tests/format/005_bundle_comments.expected.cf +++ b/tests/format/005_bundle_comments.expected.cf @@ -47,3 +47,8 @@ bundle agent f(s, d, o, p) reports: "Hello, world!"; } + +bundle agent g +{ + # comment +} diff --git a/tests/format/005_bundle_comments.input.cf b/tests/format/005_bundle_comments.input.cf index f2d600d..c08366f 100644 --- a/tests/format/005_bundle_comments.input.cf +++ b/tests/format/005_bundle_comments.input.cf @@ -45,3 +45,8 @@ bundle agent f( reports: "Hello, world!"; } +# +bundle agent g +{ + # comment +} From 4a8254a607040a358b768f83885094b91906ba80 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 16 Apr 2026 01:15:50 +0200 Subject: [PATCH 2/3] cfengine format: Fixed indentation of comments inside empty blocks Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index 1ded1d7..5c524b1 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -25,6 +25,8 @@ BLOCK_TYPES = {"bundle_block", "promise_block", "body_block"} +BLOCK_BODY_TYPES = {"bundle_block_body", "promise_block_body", "body_block_body"} + PROMISER_PARTS = {"promiser", "->", "stakeholder"} @@ -643,6 +645,10 @@ def _comment_indent(node: Node, indent: int) -> int: nearest = _skip_comments(node.prev_named_sibling, "prev") if nearest and nearest.type in INDENTED_TYPES: return indent + 2 + # No indented sibling found — if we're directly inside a block body, + # indent so the comment lines up with where promises/attributes would. + if nearest is None and node.parent and node.parent.type in BLOCK_BODY_TYPES: + return indent + 2 return indent From 808784e88e5531c8b1e8d2d27511b5ab7bfd935f Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 16 Apr 2026 01:17:18 +0200 Subject: [PATCH 3/3] cfengine format: Fixed case where removed empty comments would cause no empty line between bundles Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index 5c524b1..48539fa 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -561,6 +561,9 @@ def _format_block_header(node: Node, fmt: Formatter) -> list[Node]: line = " ".join(header_parts) if not fmt.empty: prev_sib = node.prev_named_sibling + # Skip over preceding empty comments since they will be removed + while prev_sib and prev_sib.type == "comment" and _is_empty_comment(prev_sib): + prev_sib = prev_sib.prev_named_sibling if not (prev_sib and prev_sib.type == "comment"): fmt.blank_line() fmt.print(line, 0)