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 . 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() 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 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")); }