Debian Codegraph @

blueprintcompiler/linter_rules/incorrect_widget_placement.py

raw
1 from ..errors import CompileWarning
2 from .utils import LinterRule
3
4
5 class IncorrectWidgetPlacement(LinterRule):
6 id = "wrong_parent"
7 severity = "problem"
8 category = "technical"
9
10 def check(self, type, child, stack):
11 if type in declared_widgets:
12 if len(stack) == 0:
13 problem = CompileWarning(
14 f"{type} must be a child of a " + declared_widgets[type],
15 child.signature_range,
16 )
17 self.problems.append(problem)
18 else:
19 parent_type = stack[-1].class_name.gir_type
20 if (
21 parent_type is None
22 or parent_type.full_name not in declared_widgets[type]
23 ):
24 self.problems.append(
25 CompileWarning(
26 f"{type} must be a child of a {declared_widgets[type]}",
27 child.signature_range,
28 id=self.id,
29 )
30 )
31
32
33 # Add more test widgets as needed with relevant parents
34 declared_widgets = {"Gtk.StackPage": "Gtk.Stack"}