-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdesign_misplaced_attribute.rego
More file actions
88 lines (73 loc) · 2.06 KB
/
design_misplaced_attribute.rego
File metadata and controls
88 lines (73 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package glitch
import rego.v1
import data.glitch_lib
# Second option for Puppet was not tested in real code due to lack of test data
chef_priority(attr) := index if {
attr == "source"
index = 1
} else := index if {
attr == "owner"
index = 2
} else := index if {
attr == "group"
index = 2
} else := index if {
attr == "mode"
index = 3
} else := index if {
attr == "action"
index = 4
}
# Chef
Glitch_Analysis contains result if {
parent := glitch_lib._gather_parent_unit_blocks[_]
parent.path != ""
endswith(parent.name, ".rb")
atomic_units := glitch_lib.all_atomic_units(parent)
node := atomic_units[_]
attr_names := ["source", "owner", "group", "mode", "action"]
order := [
chef_priority(attr) |
attr := node.attributes[_].name
attr = attr_names[_]
]
order != sort(order)
result := {{
"type": "design_misplaced_attribute",
"element": node,
"path": parent.path,
"description": "Misplaced attribute - The developers should try to follow the languages' style guides. These style guides define the expected attribute order.",
}}
}
# Puppet
Glitch_Analysis contains result if {
parent := glitch_lib._gather_parent_unit_blocks[_]
parent.path != ""
endswith(parent.name, ".pp")
atomic_units := glitch_lib.all_atomic_units(parent)
node := atomic_units[_]
some n
n > 0
node.attributes[n].name == "ensure"
result := {{
"type": "design_misplaced_attribute",
"element": node,
"path": parent.path,
"description": "Misplaced attribute - The developers should try to follow the languages' style guides. These style guides define the expected attribute order.",
}}
}
Glitch_Analysis contains result if {
parent := glitch_lib._gather_parent_unit_blocks[_]
parent.path != ""
endswith(parent.name, ".pp")
some i
i >= 0
i < count(parent.attributes) - 1
parent.attributes[i].value != {}
result := {
"type": "design_misplaced_attribute",
"element": parent,
"path": parent.path,
"description": "Misplaced attribute - The developers should try to follow the languages' style guides. These style guides define the expected attribute order.",
}
}