From 4660b1d508d6033c7230ffa4c85bdc0732aaf1b6 Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Wed, 22 Apr 2026 17:24:09 +0200 Subject: [PATCH 1/2] ENT-13880: Added check for half-promises outside of macros Missing semicolons not handled, leave this to the formatter. --- src/cfengine_cli/lint.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cfengine_cli/lint.py b/src/cfengine_cli/lint.py index 9c3944c..a23fa93 100644 --- a/src/cfengine_cli/lint.py +++ b/src/cfengine_cli/lint.py @@ -702,7 +702,13 @@ def _lint_node( f"Error: Expected {len(params)} arguments, received {len(args)} for body '{call}' {location}" ) return 1 - + if node.type == "half_promise": + if (n := node.prev_named_sibling) and n.type != "macro": + _highlight_range(node, lines) + print( + f"Error: Found promise attribute with no parent-promiser outside of a macro {location}" + ) + return 1 return 0 From 9f32835821031d9b1bc7ce345b9f8787a1a30c2c Mon Sep 17 00:00:00 2001 From: Simon Halvorsen Date: Wed, 22 Apr 2026 17:27:34 +0200 Subject: [PATCH 2/2] Added tests for checking validity of half-promises/macro --- tests/lint/016_half_promises.cf | 12 ++++++++++++ tests/lint/016_half_promises.expected.txt | 7 +++++++ tests/lint/016_half_promises.x.cf | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/lint/016_half_promises.cf create mode 100644 tests/lint/016_half_promises.expected.txt create mode 100644 tests/lint/016_half_promises.x.cf diff --git a/tests/lint/016_half_promises.cf b/tests/lint/016_half_promises.cf new file mode 100644 index 0000000..c19abbe --- /dev/null +++ b/tests/lint/016_half_promises.cf @@ -0,0 +1,12 @@ +bundle agent main +{ + vars: + "string" + string => $(bar); + "string" +@if minimum_version(3.18) + string => $($(baz)); +@else + string => $($(baz)); +@endif +} diff --git a/tests/lint/016_half_promises.expected.txt b/tests/lint/016_half_promises.expected.txt new file mode 100644 index 0000000..bf4b6f3 --- /dev/null +++ b/tests/lint/016_half_promises.expected.txt @@ -0,0 +1,7 @@ + + string => $(bar); + string => $(bar); + ^---------------^ +Error: Found promise attribute with no parent-promiser outside of a macro at tests/lint/016_half_promises.x.cf:6:9 +FAIL: tests/lint/016_half_promises.x.cf (1 error) +Failure, 1 error in total. diff --git a/tests/lint/016_half_promises.x.cf b/tests/lint/016_half_promises.x.cf new file mode 100644 index 0000000..35bddf7 --- /dev/null +++ b/tests/lint/016_half_promises.x.cf @@ -0,0 +1,13 @@ +bundle agent main +{ + vars: + "string" + string => $(bar); + string => $(bar); + "string" +@if minimum_version(3.18) + string => $($(baz)); +@else + string => $($(baz)); +@endif +}