Skip to content

Commit 1dc9856

Browse files
authored
Merge pull request #70 from olehermanse/main
Fixed formatting of empty slists and stakeholders
2 parents 133de4a + c30e764 commit 1dc9856

5 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/cfengine_cli/format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def stringify_single_line_nodes(nodes: list[Node]) -> str:
152152
result += " "
153153
if previous and previous.type == "=>":
154154
result += " "
155-
if previous and previous.type == "{":
155+
if previous and previous.type == "{" and node.type != "}":
156156
result += " "
157-
if previous and node.type == "}":
157+
if previous and node.type == "}" and previous.type != "{":
158158
result += " "
159159
result += string
160160
previous = node

tests/format/002_basics.expected.cf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ body common control
55
inputs => { "/var/cfengine/inputs/some_file.cf" };
66
linux::
77
inputs => { "/var/cfengine/inputs/other_file.cf" };
8+
ubuntu::
9+
inputs => {};
810
}
911

1012
promise agent example
@@ -30,6 +32,8 @@ bundle agent main
3032
# Comment at atttribute level
3133
string => "some_value";
3234

35+
"empty_list" slist => {};
36+
3337
classes:
3438
# Comment before promise
3539
"a" if => "b";

tests/format/002_basics.input.cf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ body common control{
55
inputs => { "/var/cfengine/inputs/some_file.cf" };
66
linux::
77
inputs => { "/var/cfengine/inputs/other_file.cf" };
8+
ubuntu::
9+
inputs => {};
810
}
911

1012
promise agent example{
@@ -26,6 +28,9 @@ baz::
2628
if => "bar"
2729
# Comment at atttribute level
2830
string => "some_value";
31+
"empty_list"
32+
slist => {
33+
};
2934
classes:
3035
# Comment before promise
3136
"a" if => "b";

tests/format/010_stakeholder.expected.cf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
bundle agent main
22
{
33
packages:
4+
"platform-python-devel" -> {};
45
"platform-python-devel" -> { "cfbs shebang", "ENT-1234" };
56

67
"platform-python-devel" -> { "cfbs shebang", "ENT-1234" }

tests/format/010_stakeholder.input.cf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
bundle agent main
22
{
33
packages:
4+
"platform-python-devel" -> { };
45
"platform-python-devel" -> { "cfbs shebang", "ENT-1234" };
56
"platform-python-devel" -> { "cfbs shebang", "ENT-1234" }
67
comment => "foo";

0 commit comments

Comments
 (0)