Compare commits

...

2 Commits

Author SHA1 Message Date
Gouvernathor 047a6882d8 Merge branch 'master' into lint-labels-required-params 2024-04-09 10:48:24 +02:00
Gouvernathor c4e4fdfda1 Check reachable labels with required parameters
This is weird since it's one rare kind of statement which should *not* be reachable
2024-01-29 00:47:23 +01:00
+15 -10
View File
@@ -902,7 +902,7 @@ def check_unreachables(all_nodes):
def add_block(block):
next = block[0]
if next in unreachable:
to_check.add(next)
add_to_check(next)
def add_names(names):
for name in names:
@@ -924,7 +924,7 @@ def check_unreachables(all_nodes):
continue
if node in unreachable:
to_check.add(node)
add_to_check(node)
# All nodes, outside of common.
all_nodes = [node for node in all_nodes if not common(node)]
@@ -939,6 +939,8 @@ def check_unreachables(all_nodes):
# The worklist of reachable nodes that haven't been checked yet.
to_check = set()
add_to_check = to_check.add # type: ignore
for node in all_nodes:
if isinstance(node, (renpy.ast.EarlyPython, renpy.ast.Label)):
to_check.add(node)
@@ -975,6 +977,16 @@ def check_unreachables(all_nodes):
elif isinstance(node, renpy.ast.RPY):
weakly_reachable.add(node)
def add_to_check(node):
to_check.add(node)
if (isinstance(node, renpy.ast.Label)
and node.parameters is not None
and any((p.default == p.empty)
and p.kind not in (p.VAR_POSITIONAL, p.VAR_KEYWORD)
for p in node.parameters.parameters.values())
):
report("Warning: label {} at {}:{} has required parameters but is reachable through script execution.".format(node.name, node.filename, node.linenumber))
while to_check:
node = to_check.pop() # type: Any
unreachable.remove(node)
@@ -1008,7 +1020,7 @@ def check_unreachables(all_nodes):
next = node.next
if next in unreachable:
to_check.add(next)
add_to_check(next)
locations = sorted(set((node.filename, node.linenumber) for node in (unreachable - weakly_reachable)))
problems = [ (filename, linenumber, "") for filename, linenumber in locations ]
@@ -1017,13 +1029,6 @@ def check_unreachables(all_nodes):
def check_orphan_translations(none_lang_identifiers, translation_identifiers):
def header():
print("")
print("")
print("Orphan Translations:")
print()
problems = [ ]
faulty = collections.defaultdict(list) # filename : [linenumbers]