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
8 changes: 7 additions & 1 deletion src/cfengine_cli/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions tests/format/004_comments.expected.cf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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";
}
8 changes: 8 additions & 0 deletions tests/format/004_comments.input.cf
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
Loading