mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add warning for confusing object IDs
This commit is contained in:
parent
77dc9350e9
commit
43fbf8cf8e
2 changed files with 14 additions and 0 deletions
|
@ -26,6 +26,9 @@ from .response_id import ExtResponse
|
||||||
from .types import ClassName, ConcreteClassName
|
from .types import ClassName, ConcreteClassName
|
||||||
|
|
||||||
|
|
||||||
|
RESERVED_IDS = {"this", "self", "template", "true", "false", "null", "none"}
|
||||||
|
|
||||||
|
|
||||||
class ObjectContent(AstNode):
|
class ObjectContent(AstNode):
|
||||||
grammar = ["{", Until(OBJECT_CONTENT_HOOKS, "}")]
|
grammar = ["{", Until(OBJECT_CONTENT_HOOKS, "}")]
|
||||||
|
|
||||||
|
@ -73,6 +76,11 @@ class Object(AstNode):
|
||||||
if child.response_id
|
if child.response_id
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@validate("id")
|
||||||
|
def object_id_not_reserved(self):
|
||||||
|
if self.id in RESERVED_IDS:
|
||||||
|
raise CompileWarning(f"{self.id} may be a confusing object ID")
|
||||||
|
|
||||||
|
|
||||||
def validate_parent_type(node, ns: str, name: str, err_msg: str):
|
def validate_parent_type(node, ns: str, name: str, err_msg: str):
|
||||||
parent = node.root.gir.get_type(name, ns)
|
parent = node.root.gir.get_type(name, ns)
|
||||||
|
|
|
@ -23,6 +23,7 @@ from blueprintcompiler.language.values import StringValue
|
||||||
|
|
||||||
from .common import *
|
from .common import *
|
||||||
from .contexts import ValueTypeCtx
|
from .contexts import ValueTypeCtx
|
||||||
|
from .gobject_object import RESERVED_IDS
|
||||||
|
|
||||||
|
|
||||||
class Menu(AstNode):
|
class Menu(AstNode):
|
||||||
|
@ -47,6 +48,11 @@ class Menu(AstNode):
|
||||||
if self.tokens["tag"] == "menu" and self.tokens["id"] is None:
|
if self.tokens["tag"] == "menu" and self.tokens["id"] is None:
|
||||||
raise CompileError("Menu requires an ID")
|
raise CompileError("Menu requires an ID")
|
||||||
|
|
||||||
|
@validate("id")
|
||||||
|
def object_id_not_reserved(self):
|
||||||
|
if self.id in RESERVED_IDS:
|
||||||
|
raise CompileWarning(f"{self.id} may be a confusing object ID")
|
||||||
|
|
||||||
|
|
||||||
class MenuAttribute(AstNode):
|
class MenuAttribute(AstNode):
|
||||||
tag_name = "attribute"
|
tag_name = "attribute"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue