Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cfengine_cli/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Comment thread
SimonThalvorsen marked this conversation as resolved.
_highlight_range(node, lines)
print(
f"Error: Found promise attribute with no parent-promiser outside of a macro {location}"
)
return 1
return 0


Expand Down
12 changes: 12 additions & 0 deletions tests/lint/016_half_promises.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bundle agent main
{
vars:
"string"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format with cfengine format

string => $(bar);
"string"
@if minimum_version(3.18)
string => $($(baz));
@else
string => $($(baz));
@endif
Comment on lines +6 to +11
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to expand these tests a bit more, for example;

Suggested change
"string"
@if minimum_version(3.18)
string => $($(baz));
@else
string => $($(baz));
@endif
"string"
@if minimum_version(3.18)
string => $($(baz));
@else
string => $($(baz));
@endif
"string"
# comment
@if minimum_version(3.18)
# comment
# comment
string => $($(baz));
# comment
@else
# comment
string => $($(baz));
# comment
@endif

}
7 changes: 7 additions & 0 deletions tests/lint/016_half_promises.expected.txt
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions tests/lint/016_half_promises.x.cf
Original file line number Diff line number Diff line change
@@ -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
}
Loading