From 78538c20d65f8f03d4bd518a3178e3d2bea9a887 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 21:57:26 +0200 Subject: [PATCH 1/4] tests: Added one more macro formatting test case Signed-off-by: Ole Herman Schumacher Elgesem --- tests/format/011_macros.expected.cf | 14 ++++++++++++++ tests/format/011_macros.input.cf | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/tests/format/011_macros.expected.cf b/tests/format/011_macros.expected.cf index 7e380da..20ac1b1 100644 --- a/tests/format/011_macros.expected.cf +++ b/tests/format/011_macros.expected.cf @@ -190,3 +190,17 @@ bundle agent bundle_e @endif }; } + +@if minimum_version(3.24) +bundle agent test(a, b) +{ + reports: + "$(a) and $(b)"; +} +@else +bundle agent test(a) +{ + reports: + "$(a)"; +} +@endif diff --git a/tests/format/011_macros.input.cf b/tests/format/011_macros.input.cf index cb13a38..bdcd477 100644 --- a/tests/format/011_macros.input.cf +++ b/tests/format/011_macros.input.cf @@ -180,3 +180,16 @@ slist => { @endif }; } +@if minimum_version(3.24) +bundle agent test(a, b) +{ +reports: +"$(a) and $(b)"; +} +@else +bundle agent test(a) +{ +reports: +"$(a)"; +} +@endif From 006e6a39a813eac9629a57b8be728fe638e9914b Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 22:08:15 +0200 Subject: [PATCH 2/4] cfengine format: Removed empty line between @else and bundle Co-authored-by: Claude Opus 4.7 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index 3bb6222..0979f82 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -682,7 +682,9 @@ def _format_block_header(node: Node, fmt: Formatter) -> list[Node]: while prev_sib and prev_sib.type == "comment" and _is_empty_comment(prev_sib): prev_sib = prev_sib.prev_named_sibling is_macro_wrapped = ( - prev_sib and prev_sib.type == "macro" and text(prev_sib).startswith("@if") + prev_sib + and prev_sib.type == "macro" + and text(prev_sib).startswith(("@if", "@else")) ) if not (prev_sib and prev_sib.type == "comment") and not is_macro_wrapped: fmt.blank_line() From 27e4fb68d068447a23c4762afefc539c358e0804 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 22:09:09 +0200 Subject: [PATCH 3/4] cfengine format . Signed-off-by: Ole Herman Schumacher Elgesem --- tests/lint/015_macro_multi_def_bundle.cf | 6 ++---- tests/lint/017_implies_body.cf | 3 +-- tests/lint/018_nested_calls.cf | 8 ++++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/lint/015_macro_multi_def_bundle.cf b/tests/lint/015_macro_multi_def_bundle.cf index 4e00ace..52f2a21 100644 --- a/tests/lint/015_macro_multi_def_bundle.cf +++ b/tests/lint/015_macro_multi_def_bundle.cf @@ -16,10 +16,8 @@ bundle agent main { methods: @if minimum_version(3.24) - "test1" - usebundle => test("hello", "world"); + "test1" usebundle => test("hello", "world"); @else - "test2" - usebundle => test("hello"); + "test2" usebundle => test("hello"); @endif } diff --git a/tests/lint/017_implies_body.cf b/tests/lint/017_implies_body.cf index 8a3c3c2..2c6ba9d 100644 --- a/tests/lint/017_implies_body.cf +++ b/tests/lint/017_implies_body.cf @@ -7,6 +7,5 @@ body copy_from mycopy(from, server) bundle agent main { files: - "/tmp/test" - copy_from => mycopy("/src", "host1"); + "/tmp/test" copy_from => mycopy("/src", "host1"); } diff --git a/tests/lint/018_nested_calls.cf b/tests/lint/018_nested_calls.cf index 7f649b2..c26cf86 100644 --- a/tests/lint/018_nested_calls.cf +++ b/tests/lint/018_nested_calls.cf @@ -12,11 +12,11 @@ bundle agent helper(arg) bundle agent main { files: - "/tmp/test" - copy_from => mycopy(readfile("/etc/source", "100")); + "/tmp/test" copy_from => mycopy(readfile("/etc/source", "100")); + methods: - "test" - usebundle => helper(format("hello %s", "world")); + "test" usebundle => helper(format("hello %s", "world")); + vars: "x" string => format("nested: %s", getuid("root")); } From 0d6819a149bea34a3c3adf1bc28f6a6f83ff629e Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 22:09:43 +0200 Subject: [PATCH 4/4] Makefile: Added cfengine format on this repo Signed-off-by: Ole Herman Schumacher Elgesem --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index b015429..9ae6165 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ venv: format: venv uv tool run black . --target-version py310 prettier . --write + uv run cfengine format ./ lint: venv uv tool run black --check . --fast @@ -16,6 +17,7 @@ lint: venv uv tool run pyflakes src/ uv tool run pyright src/ uv run cfengine lint --strict=no ./ + uv run cfengine format --check install: pipx install --force --editable .