Skip to content

Commit fd2111e

Browse files
FIX: missing attribute error + tests
1 parent 3851b7a commit fd2111e

4 files changed

Lines changed: 20 additions & 28 deletions

File tree

src/cfengine_cli/lint.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,6 @@ def _lint_node(
551551
)
552552
return 1
553553
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-
563554
mutually_excl_vars_attrs = {
564555
"data",
565556
"ilist",
@@ -570,13 +561,22 @@ def _lint_node(
570561
"string",
571562
}
572563

564+
attribute_nodes = [x for x in node.children if x.type == "attribute"]
573565
promise_type_attrs = {
574566
_text(child): attr_node
575567
for attr_node in attribute_nodes
576568
for child in attr_node.children
577569
if child.type == "attribute_name"
578570
and _text(child) in mutually_excl_vars_attrs
579571
}
572+
if not promise_type_attrs:
573+
_highlight_range(node, lines)
574+
print(
575+
f"Error: Missing value type attribute for promiser "
576+
f"{_text(node.children[0])} inside vars-promise type {location}"
577+
)
578+
return 1
579+
580580

581581
if len(promise_type_attrs) > 1:
582582
for n in promise_type_attrs:

tests/lint/011_mutually_exclusive_types_vars.cf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ bundle agent foo
55
policy => "free",
66
real => "11.11";
77

8-
"noerr"
9-
slist => {};
10-
int => "string";
11-
12-
"noerr"
13-
slist => {}
14-
int => "string";
15-
168
"comment"
179
slist => {},
1810
comment => "string";

tests/lint/011_mutually_exclusive_types_vars.expected.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Error: Mutually exclusive attribute values ('slist', 'int', 'real') for a single
1515

1616
"missing-error";
1717
^--------------^
18-
Error: Missing attribute value for promiser "missing-error" inside vars-promise type at tests/lint/011_mutually_exclusive_types_vars.x.cf:18:5
19-
FAIL: tests/lint/011_mutually_exclusive_types_vars.x.cf (2 errors)
20-
Failure, 2 errors in total.
18+
Error: Missing value type attribute for promiser "missing-error" inside vars-promise type at tests/lint/011_mutually_exclusive_types_vars.x.cf:10:5
19+
20+
21+
"missing-type-error";
22+
^-------------------^
23+
Error: Missing value type attribute for promiser "missing-type-error" inside vars-promise type at tests/lint/011_mutually_exclusive_types_vars.x.cf:12:5
24+
FAIL: tests/lint/011_mutually_exclusive_types_vars.x.cf (3 errors)
25+
Failure, 3 errors in total.

tests/lint/011_mutually_exclusive_types_vars.x.cf

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@ bundle agent foo
77
policy => "free",
88
real => "0.5";
99

10-
"noerr"
11-
slist => {};
12-
int => "string";
13-
14-
"noerr"
15-
slist => {}
16-
int => "string";
17-
1810
"missing-error";
11+
12+
"missing-type-error";
13+
comment => "Missing type";
1914
}

0 commit comments

Comments
 (0)