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 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 +}