Debian Codegraph @

blueprintcompiler/linter_rules/scrollable_parent.py

raw
1 from ..errors import CompileWarning
2 from ..lsp_utils import CodeAction
3 from .utils import LinterRule
4
5 SCROLL_CONTAINERS = ("Gtk.ScrolledWindow", "Adw.ClampScrollable")
6
7
8 class ScrollableParent(LinterRule):
9 id = "scrollable_parent"
10 severity = "problem"
11 category = "technical"
12
13 def check(self, type, child, stack):
14 if child.gir_class is not None and child.gir_class.assignable_to(
15 child.root.gir.get_type("Scrollable", "Gtk")
16 ):
17 if len(stack) > 0:
18 parent_class_name = stack[-1].class_name
19 if (
20 parent_class_name.gir_type is not None
21 and parent_class_name.gir_type.full_name not in SCROLL_CONTAINERS
22 ):
23 actions = []
24 if parent_class_name.gir_type.full_name == "Adw.Clamp":
25 actions.append(
26 CodeAction(
27 "use Adw.ClampScrollable",
28 "Adw.ClampScrollable",
29 parent_class_name.range,
30 )
31 )
32
33 self.problems.append(
34 CompileWarning(
35 "Scrollable widget should be placed in a scroll container",
36 range=child.signature_range,
37 hints=[
38 "scroll containers: " + ", ".join(SCROLL_CONTAINERS)
39 ],
40 actions=actions,
41 id=self.id,
42 )
43 )