diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index 81ac781..cdaf716 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -152,9 +152,9 @@ def stringify_single_line_nodes(nodes: list[Node]) -> str: result += " " if previous and previous.type == "=>": result += " " - if previous and previous.type == "{": + if previous and previous.type == "{" and node.type != "}": result += " " - if previous and node.type == "}": + if previous and node.type == "}" and previous.type != "{": result += " " result += string previous = node diff --git a/tests/format/002_basics.expected.cf b/tests/format/002_basics.expected.cf index d20e36d..a21c37e 100644 --- a/tests/format/002_basics.expected.cf +++ b/tests/format/002_basics.expected.cf @@ -5,6 +5,8 @@ body common control inputs => { "/var/cfengine/inputs/some_file.cf" }; linux:: inputs => { "/var/cfengine/inputs/other_file.cf" }; + ubuntu:: + inputs => {}; } promise agent example @@ -30,6 +32,8 @@ bundle agent main # Comment at atttribute level string => "some_value"; + "empty_list" slist => {}; + classes: # Comment before promise "a" if => "b"; diff --git a/tests/format/002_basics.input.cf b/tests/format/002_basics.input.cf index 54aafee..1a12122 100644 --- a/tests/format/002_basics.input.cf +++ b/tests/format/002_basics.input.cf @@ -5,6 +5,8 @@ body common control{ inputs => { "/var/cfengine/inputs/some_file.cf" }; linux:: inputs => { "/var/cfengine/inputs/other_file.cf" }; +ubuntu:: +inputs => {}; } promise agent example{ @@ -26,6 +28,9 @@ baz:: if => "bar" # Comment at atttribute level string => "some_value"; +"empty_list" +slist => { +}; classes: # Comment before promise "a" if => "b"; diff --git a/tests/format/010_stakeholder.expected.cf b/tests/format/010_stakeholder.expected.cf index 529b9e9..14a4dbe 100644 --- a/tests/format/010_stakeholder.expected.cf +++ b/tests/format/010_stakeholder.expected.cf @@ -1,6 +1,7 @@ bundle agent main { packages: + "platform-python-devel" -> {}; "platform-python-devel" -> { "cfbs shebang", "ENT-1234" }; "platform-python-devel" -> { "cfbs shebang", "ENT-1234" } diff --git a/tests/format/010_stakeholder.input.cf b/tests/format/010_stakeholder.input.cf index 78ab2d4..02ac6b2 100644 --- a/tests/format/010_stakeholder.input.cf +++ b/tests/format/010_stakeholder.input.cf @@ -1,6 +1,7 @@ bundle agent main { packages: +"platform-python-devel" -> { }; "platform-python-devel" -> { "cfbs shebang", "ENT-1234" }; "platform-python-devel" -> { "cfbs shebang", "ENT-1234" } comment => "foo";