Debian Codegraph @

blueprintcompiler/linter_rules/unused_widget.py

raw
1 from ..errors import UnusedWarning
2 from ..lsp_utils import CodeAction
3 from .utils import LinterRule
4
5
6 class UnusedWidget(LinterRule):
7 id = "unused_widget"
8 severity = "suggestion"
9 category = "technical"
10
11 def check(self, type, child, stack):
12 gtk_widget = child.root.gir.get_type("Widget", "Gtk")
13 if (
14 len(stack) == 0
15 and child.id is None
16 and child.gir_class is not None
17 and child.gir_class.assignable_to(gtk_widget)
18 ):
19 self.problems.append(
20 UnusedWarning(
21 f"{type} is unused because it has no ID and no parent",
22 range=child.signature_range,
23 actions=[
24 CodeAction(
25 "remove this widget",
26 "",
27 edit_range=child.range.with_preceding_whitespace,
28 )
29 ],
30 id=self.id,
31 )
32 )