Add errors for duplicate properties and blocks

This commit is contained in:
James Westman 2022-05-27 13:27:18 -05:00
parent f18c8b7a2d
commit 824476bda1
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
12 changed files with 122 additions and 0 deletions

View file

@ -112,6 +112,14 @@ class Property(AstNode):
)
@validate("name")
def unique_in_parent(self):
self.validate_unique_in_parent(
f"Duplicate property '{self.tokens['name']}'",
check=lambda child: child.tokens["name"] == self.tokens["name"]
)
@docs("name")
def property_docs(self):
if self.gir_property is not None:

View file

@ -139,6 +139,13 @@ class A11yProperty(BaseTypedAttribute):
did_you_mean=(self.tokens["name"], types.keys()),
)
@validate("name")
def unique_in_parent(self):
self.validate_unique_in_parent(
f"Duplicate accessibility attribute '{self.tokens['name']}'",
check=lambda child: child.tokens["name"] == self.tokens["name"],
)
@docs("name")
def prop_docs(self):
if self.tokens["name"] in get_types(self.root.gir):
@ -156,6 +163,9 @@ class A11y(AstNode):
def container_is_widget(self):
validate_parent_type(self, "Gtk", "Widget", "accessibility properties")
@validate("accessibility")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate accessibility block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("accessibility")

View file

@ -56,6 +56,9 @@ class Items(AstNode):
def container_is_combo_box_text(self):
validate_parent_type(self, "Gtk", "ComboBoxText", "combo box items")
@validate("items")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate items block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("items")

View file

@ -27,6 +27,18 @@ class Filters(AstNode):
def container_is_file_filter(self):
validate_parent_type(self, "Gtk", "FileFilter", "file filter properties")
@validate()
def unique_in_parent(self):
# The token argument to validate() needs to be calculated based on
# the instance, hence wrapping it like this.
@validate(self.tokens["tag_name"])
def wrapped_validator(self):
self.validate_unique_in_parent(
f"Duplicate {self.tokens['tag_name']} block",
check=lambda child: child.tokens["tag_name"] == self.tokens["tag_name"],
)
wrapped_validator(self)
def emit_xml(self, xml: XmlEmitter):
xml.start_tag(self.tokens["tag_name"])
for child in self.children:

View file

@ -31,6 +31,13 @@ class LayoutProperty(BaseAttribute):
# there isn't really a way to validate these
return None
@validate("name")
def unique_in_parent(self):
self.validate_unique_in_parent(
f"Duplicate layout property '{self.name}'",
check=lambda child: child.name == self.name,
)
layout_prop = Group(
LayoutProperty,
@ -53,6 +60,9 @@ class Layout(AstNode):
def container_is_widget(self):
validate_parent_type(self, "Gtk", "Widget", "layout properties")
@validate("layout")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate layout block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("layout")

View file

@ -55,6 +55,10 @@ class Widgets(AstNode):
def container_is_size_group(self):
validate_parent_type(self, "Gtk", "SizeGroup", "size group properties")
@validate("widgets")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate widgets block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("widgets")
for child in self.children:

View file

@ -51,6 +51,9 @@ class Strings(AstNode):
def container_is_string_list(self):
validate_parent_type(self, "Gtk", "StringList", "StringList items")
@validate("strings")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate strings block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("items")

View file

@ -41,6 +41,10 @@ class Styles(AstNode):
def container_is_widget(self):
validate_parent_type(self, "Gtk", "Widget", "style classes")
@validate("styles")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate styles block")
def emit_xml(self, xml: XmlEmitter):
xml.start_tag("style")
for child in self.children: