Skip to content

Commit 8a6ca2a

Browse files
ENT-13826: Error on user-defined bundle/body with the name of a built-in func
Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
1 parent 9335cc5 commit 8a6ca2a

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/cfengine_cli/lint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ def _lint_node(node: Node, policy_file: PolicyFile, state: State) -> int:
492492
f"Error: Bundle type must be one of ({', '.join(ALLOWED_BUNDLE_TYPES)}), not '{_text(node)}' {location}"
493493
)
494494
return 1
495+
if state.strict and (
496+
node.type in ("bundle_block_name", "body_block_name")
497+
and _text(node) in BUILTIN_FUNCTIONS
498+
):
499+
_highlight_range(node, lines)
500+
print(
501+
f"Error: {"Bundle" if "bundle" in node.type else "Body"} '{_text(node)}' shadows built-in function with the same name {location}"
502+
)
503+
return 1
495504
if node.type == "calling_identifier":
496505
name = _text(node)
497506
qualified_name = _qualify(name, state.namespace)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bundle agent isvariab
2+
{
3+
reports:
4+
"isvariab is not a built-in function";
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
bundle agent isvariable
3+
^--------^
4+
Error: Bundle 'isvariable' shadows built-in function with the same name at tests/lint/009_bundle_shadows_function.x.cf:1:14
5+
FAIL: tests/lint/009_bundle_shadows_function.x.cf (1 error)
6+
Failure, 1 error in total.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bundle agent isvariable
2+
{
3+
reports:
4+
"isvariable is a built-in function";
5+
}

0 commit comments

Comments
 (0)