Skip to content

Commit 03ecbb2

Browse files
authored
Merge pull request #101 from olehermanse/linting-next
cfengine lint: Added more specific error messages and hints about where something is defined
2 parents d28b570 + 1c8157b commit 03ecbb2

10 files changed

Lines changed: 480 additions & 205 deletions

src/cfengine_cli/lint.py

Lines changed: 369 additions & 200 deletions
Large diffs are not rendered by default.

tests/lint/008_namespace.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
methods:
33
"x" usebundle => default:target("arg");
44
^------------^
5-
Error: Call to unknown function / bundle / body 'default:target' at tests/lint/008_namespace.x.cf:15:22
5+
Error: Call to unknown bundle 'default:target' at tests/lint/008_namespace.x.cf:15:22
66
FAIL: tests/lint/008_namespace.x.cf (1 error)
77
Failure, 1 error in total.

tests/lint/014_num_args_body.expected.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
perms => mog("644");
44
^--------^
55
Error: Expected 3 arguments, received 1 for body 'mog' at tests/lint/014_num_args_body.x.cf:13:16
6+
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12
67

78
create => "true",
89
perms => mog("644", "root");
910
^----------------^
1011
Error: Expected 3 arguments, received 2 for body 'mog' at tests/lint/014_num_args_body.x.cf:16:16
12+
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12
1113

1214
create => "true",
1315
perms => mog("644", "root", "root", "root");
1416
^--------------------------------^
1517
Error: Expected 3 arguments, received 4 for body 'mog' at tests/lint/014_num_args_body.x.cf:22:16
18+
Hint: The body 'mog' is defined at tests/lint/014_num_args_body.x.cf:1:12
1619
FAIL: tests/lint/014_num_args_body.x.cf (3 errors)
1720
Failure, 3 errors in total.

tests/lint/014_num_args_bundle.expected.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
usebundle => test();
44
^----^
55
Error: Expected 2 arguments, received 0 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:5:20
6+
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14
67

78
"test2"
89
usebundle => test("a");
910
^-------^
1011
Error: Expected 2 arguments, received 1 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:7:20
12+
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14
1113

1214
"test4"
1315
usebundle => test("a", "b", "c");
1416
^-----------------^
1517
Error: Expected 2 arguments, received 3 for bundle 'test' at tests/lint/014_num_args_bundle.x.cf:11:20
18+
Hint: The bundle 'test' is defined at tests/lint/014_num_args_bundle.x.cf:13:14
1619
FAIL: tests/lint/014_num_args_bundle.x.cf (3 errors)
1720
Failure, 3 errors in total.

tests/lint/016_macro_multi_def_bundle.expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
usebundle => test();
44
^----^
55
Error: Expected 1 or 2 arguments, received 0 for bundle 'test' at tests/lint/016_macro_multi_def_bundle.x.cf:20:20
6+
Hint: The bundle 'test' is defined at tests/lint/016_macro_multi_def_bundle.x.cf:2:14 and tests/lint/016_macro_multi_def_bundle.x.cf:8:14
67

78
"test2"
89
usebundle => test("hello", "world", "!");
910
^-------------------------^
1011
Error: Expected 1 or 2 arguments, received 3 for bundle 'test' at tests/lint/016_macro_multi_def_bundle.x.cf:23:20
12+
Hint: The bundle 'test' is defined at tests/lint/016_macro_multi_def_bundle.x.cf:2:14 and tests/lint/016_macro_multi_def_bundle.x.cf:8:14
1113
FAIL: tests/lint/016_macro_multi_def_bundle.x.cf (2 errors)
1214
Failure, 2 errors in total.

tests/lint/018_implies_body.expected.txt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,37 @@
22
"/tmp/test1"
33
copy_from => helper("oops");
44
^----^
5-
Error: Call to unknown function / bundle / body 'helper' at tests/lint/018_implies_body.x.cf:17:20
5+
Error: Expected a body but 'helper' is a bundle at tests/lint/018_implies_body.x.cf:17:20
66

77
"/tmp/test2"
88
copy_from => unknown_name("oops");
99
^----------^
10-
Error: Call to unknown function / bundle / body 'unknown_name' at tests/lint/018_implies_body.x.cf:19:20
10+
Error: Call to unknown body 'unknown_name' at tests/lint/018_implies_body.x.cf:19:20
1111

1212
"/tmp/test3"
1313
copy_from => mycopy("/src");
1414
^------------^
1515
Error: Expected 2 arguments, received 1 for body 'mycopy' at tests/lint/018_implies_body.x.cf:21:20
16-
FAIL: tests/lint/018_implies_body.x.cf (3 errors)
17-
Failure, 3 errors in total.
16+
Hint: The body 'mycopy' is defined at tests/lint/018_implies_body.x.cf:1:16
17+
18+
"/tmp/test4"
19+
copy_from => readfile("/etc/file", "100");
20+
^------^
21+
Error: Expected a body but 'readfile' is a built-in function at tests/lint/018_implies_body.x.cf:23:20
22+
23+
"test5"
24+
usebundle => mycopy("/src", "host");
25+
^----^
26+
Error: Expected a bundle but 'mycopy' is a body at tests/lint/018_implies_body.x.cf:26:20
27+
28+
"test6"
29+
usebundle => readfile("/etc/file", "100");
30+
^------^
31+
Error: Expected a bundle but 'readfile' is a built-in function at tests/lint/018_implies_body.x.cf:28:20
32+
33+
"test7"
34+
usebundle => unknown_bundle("oops");
35+
^------------^
36+
Error: Call to unknown bundle 'unknown_bundle' at tests/lint/018_implies_body.x.cf:30:20
37+
FAIL: tests/lint/018_implies_body.x.cf (7 errors)
38+
Failure, 7 errors in total.

tests/lint/018_implies_body.x.cf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ bundle agent main
1919
copy_from => unknown_name("oops");
2020
"/tmp/test3"
2121
copy_from => mycopy("/src");
22+
"/tmp/test4"
23+
copy_from => readfile("/etc/file", "100");
24+
methods:
25+
"test5"
26+
usebundle => mycopy("/src", "host");
27+
"test6"
28+
usebundle => readfile("/etc/file", "100");
29+
"test7"
30+
usebundle => unknown_bundle("oops");
2231
}

tests/lint/019_nested_calls.cf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body copy_from mycopy(from)
2+
{
3+
source => "$(from)";
4+
}
5+
6+
bundle agent helper(arg)
7+
{
8+
reports:
9+
"$(arg)";
10+
}
11+
12+
bundle agent main
13+
{
14+
files:
15+
"/tmp/test"
16+
copy_from => mycopy(readfile("/etc/source", "100"));
17+
methods:
18+
"test"
19+
usebundle => helper(format("hello %s", "world"));
20+
vars:
21+
"x" string => format("nested: %s", getuid("root"));
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
"test1"
3+
usebundle => helper(helper("nested-bundle"));
4+
^----^
5+
Error: Expected a built-in function but 'helper' is a bundle at tests/lint/019_nested_calls.x.cf:16:27
6+
7+
"test2"
8+
usebundle => helper(mycopy("nested-body"));
9+
^----^
10+
Error: Expected a built-in function but 'mycopy' is a body at tests/lint/019_nested_calls.x.cf:18:27
11+
12+
"test3"
13+
usebundle => helper(unknown_name("oops"));
14+
^----------^
15+
Error: Call to unknown function 'unknown_name' at tests/lint/019_nested_calls.x.cf:20:27
16+
17+
"/tmp/test4"
18+
copy_from => mycopy(unknown_name("oops"));
19+
^----------^
20+
Error: Call to unknown function 'unknown_name' at tests/lint/019_nested_calls.x.cf:23:27
21+
FAIL: tests/lint/019_nested_calls.x.cf (4 errors)
22+
Failure, 4 errors in total.

tests/lint/019_nested_calls.x.cf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body copy_from mycopy(from)
2+
{
3+
source => "$(from)";
4+
}
5+
6+
bundle agent helper(arg)
7+
{
8+
reports:
9+
"$(arg)";
10+
}
11+
12+
bundle agent main
13+
{
14+
methods:
15+
"test1"
16+
usebundle => helper(helper("nested-bundle"));
17+
"test2"
18+
usebundle => helper(mycopy("nested-body"));
19+
"test3"
20+
usebundle => helper(unknown_name("oops"));
21+
files:
22+
"/tmp/test4"
23+
copy_from => mycopy(unknown_name("oops"));
24+
}

0 commit comments

Comments
 (0)