Debian Codegraph @

blueprintcompiler/linter_rules/no_visible_true.py

raw
1 from ..errors import CompileWarning
2 from ..language import Property, Value
3 from ..lsp_utils import CodeAction
4 from .utils import LinterRule
5
6
7 class NoVisibleTrue(LinterRule):
8 id = "visible_true"
9 severity = "suggestion"
10 category = "technical"
11
12 def check(self, type, child, stack):
13 if not child.gir_class.assignable_to(child.root.gir.get_type("Widget", "Gtk")):
14 return
15
16 properties = child.content.children[Property]
17 for property in properties:
18 if property.name != "visible":
19 continue
20
21 if not isinstance(property.value, Value):
22 continue
23
24 ident = property.value.range.text
25 if ident == "true":
26 self.problems.append(
27 CompileWarning(
28 f"In GTK 4, widgets are visible by default, so this property is unnecessary",
29 property.value.range,
30 actions=[
31 CodeAction(
32 "remove the property",
33 "",
34 edit_range=property.range.with_preceding_whitespace,
35 )
36 ],
37 id=self.id,
38 )
39 )