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", 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