From d211bcb28db6379f72a2f5bc58485d04c9950e99 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 17 Apr 2026 13:58:57 +0200 Subject: [PATCH 1/2] Formatting tests: Added cases for empty slists / stakeholders Signed-off-by: Ole Herman Schumacher Elgesem --- tests/format/002_basics.expected.cf | 4 ++++ tests/format/002_basics.input.cf | 5 +++++ tests/format/010_stakeholder.expected.cf | 1 + tests/format/010_stakeholder.input.cf | 1 + 4 files changed, 11 insertions(+) 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"; From c30e7643b34e56acf262fd3efcf9e1b4053d04e1 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 17 Apr 2026 14:00:49 +0200 Subject: [PATCH 2/2] Fixed formatting of empty slists and stakeholders Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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