Skip to content

Commit 6e2630c

Browse files
ENT-13829: Errors on missing value and mutually exclusive types in vars promises
Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
1 parent 26797e7 commit 6e2630c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/cfengine_cli/lint.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,42 @@ def _lint_node(
550550
f"Error: {'Bundle' if 'bundle' in node.type else 'Body'} '{_text(node)}' conflicts with built-in function with the same name {location}"
551551
)
552552
return 1
553+
if state.promise_type == "vars" and node.type == "promise":
554+
attribute_nodes = [x for x in node.children if x.type == "attribute"]
555+
if not attribute_nodes:
556+
_highlight_range(node, lines)
557+
print(
558+
f"Error: Missing attribute value for promiser "
559+
f"{_text(node)[:-1]} inside vars-promise type {location}"
560+
)
561+
return 1
562+
563+
mutually_excl_vars_attrs = {
564+
"data",
565+
"ilist",
566+
"int",
567+
"real",
568+
"rlist",
569+
"slist",
570+
"string",
571+
}
572+
573+
promise_type_attrs = {
574+
_text(child): attr_node
575+
for attr_node in attribute_nodes
576+
for child in attr_node.children
577+
if child.type == "attribute_name"
578+
and _text(child) in mutually_excl_vars_attrs
579+
}
580+
581+
if len(promise_type_attrs) > 1:
582+
for n in promise_type_attrs:
583+
_highlight_range(promise_type_attrs[n], lines)
584+
print(
585+
f"Error: Mutually exclusive attribute values {tuple(promise_type_attrs)} for a single promiser"
586+
f" inside vars-promise {location}"
587+
)
588+
return 1
553589
if node.type == "calling_identifier":
554590
name = _text(node)
555591
qualified_name = _qualify(name, state.namespace)

0 commit comments

Comments
 (0)