From 4ce942c5ddeab509369b76e9d54d1fc6e63b1d1f Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 9 Apr 2026 03:00:46 +0200 Subject: [PATCH 1/2] Expanded formatting tests for comments Signed-off-by: Ole Herman Schumacher Elgesem --- tests/format/004_comments.expected.cf | 9 +++++++++ tests/format/004_comments.input.cf | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/format/004_comments.expected.cf b/tests/format/004_comments.expected.cf index f192acd..9b9e4e2 100644 --- a/tests/format/004_comments.expected.cf +++ b/tests/format/004_comments.expected.cf @@ -9,6 +9,7 @@ bundle agent main # Inside promise, next to attributes string => "value"; + # Before next promise "some_list" slist => { "Strings that go in a list which would be long", @@ -24,4 +25,12 @@ bundle agent main if => "something", # Inside promise, next to attributes string => "value"; + + # A class guard shifts everything over 2 spaces: + class_guard:: + # Inside promise type + "some_var" + if => "something", + # Inside promise, next to attributes + string => "value"; } diff --git a/tests/format/004_comments.input.cf b/tests/format/004_comments.input.cf index c81b157..93b6b05 100644 --- a/tests/format/004_comments.input.cf +++ b/tests/format/004_comments.input.cf @@ -9,6 +9,7 @@ if => "something", # Inside promise, next to attributes string => "value"; +# Before next promise "some_list" slist => { "Strings that go in a list which would be long", @@ -17,6 +18,13 @@ slist => { "More and more and more and more", }; +# A class guard shifts everything over 2 spaces: +class_guard:: +# Inside promise type +"some_var" +if => "something", +# Inside promise, next to attributes +string => "value"; # A class guard shifts everything over 2 spaces: class_guard:: # Inside promise type From bed1713672f8a4c95ef2db60a699f54571d86468 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Thu, 9 Apr 2026 03:02:55 +0200 Subject: [PATCH 2/2] cfengine format: Added newline before comment in more places Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index c48a874..4469bd5 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -338,7 +338,13 @@ def autoformat(node, fmt, line_length, macro_indent, indent=0): fmt.print("", 0) elif child.type == "comment": prev = child.prev_named_sibling - if prev and prev.type in ["promise", "half_promise"]: + if prev and prev.type in [ + "promise", + "half_promise", + "class_guarded_promises", + "class_guarded_body_attributes", + "class_guarded_promise_block_attributes", + ]: parent = child.parent if parent and parent.type in [ "bundle_section",