Debian Codegraph @

blueprintcompiler/linter_rules/number_of_children.py

raw
1 from ..errors import CompileError
2 from ..language import Child
3 from .utils import LinterRule
4
5
6 class NumberOfChildren(LinterRule):
7 id = "number_of_children"
8 severity = "problem"
9 category = "technical"
10
11 def check(self, type, child, stack):
12 # rule problem/number-of-children
13 children = child.content.children[Child]
14 if type in gir_types_no_children and len(children) > 0:
15 range = children[0].range
16 problem = CompileError(f"{type} cannot have children", range, id=self.id)
17 self.problems.append(problem)
18 elif type in gir_types_single_child and len(children) > 1:
19 range = children[1].range
20 problem = CompileError(
21 f"{type} cannot have more than one child", range, id=self.id
22 )
23 self.problems.append(problem)
24
25
26 gir_types_no_children = ["Gtk.Label"]
27 gir_types_single_child = [
28 "Adw.Bin",
29 "Adw.StatusPage",
30 "Adw.Clamp",
31 "Gtk.ScrolledWindow",
32 ]