Skip to content

Commit 65c1f55

Browse files
ENT-13075: Error if user tries to call bundle inside custom promise
Ticket: ENT-13075 Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
1 parent dbad057 commit 65c1f55

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/cfengine_cli/lint.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ def _text(node):
8080
return node.text.decode()
8181

8282

83+
def _find_node_parent_type(node, parent_type):
84+
current = node
85+
while current is not None and current.type != parent_type:
86+
current = current.parent
87+
88+
return current
89+
90+
8391
def _walk_generic(filename, lines, node, visitor):
8492
visitor(node)
8593
for node in node.children:
@@ -133,7 +141,6 @@ def _single_node_checks(filename, lines, node, user_definition, strict):
133141
f"Error: Undefined promise type '{promise_type}' at {filename}:{line}:{column}"
134142
)
135143
return 1
136-
137144
if node.type == "bundle_block_name":
138145
if _text(node) != _text(node).lower():
139146
_highlight_range(node, lines)
@@ -156,6 +163,24 @@ def _single_node_checks(filename, lines, node, user_definition, strict):
156163
)
157164
return 1
158165
if node.type == "calling_identifier":
166+
if (
167+
strict
168+
and _text(node) in user_definition.get("all_bundle_names", set())
169+
and (
170+
(parent := _find_node_parent_type(node, "bundle_section")) is not None
171+
) # Find parent node with type
172+
and (
173+
(
174+
parent := _text(parent)[0 : _text(parent).index(":")]
175+
) # Extract the content of section until ':' for promise_type name
176+
in user_definition.get("custom_promise_types", set())
177+
)
178+
):
179+
_highlight_range(node, lines)
180+
print(
181+
f"Error: Call to bundle ('{_text(node)}') inside custom promise: '{parent}' at at {filename}:{line}:{column}"
182+
)
183+
return 1
159184
if strict and (
160185
_text(node)
161186
not in BUILTIN_FUNCTIONS.union(

0 commit comments

Comments
 (0)