Skip to content

Commit c99692d

Browse files
zvecrchrisjung01
authored andcommitted
Ensure keyboard aliases do not point to themselves (qmk#25500)
1 parent 3d6296d commit c99692d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/python/qmk/cli/ci/validate_aliases.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@ def _target_keyboard_exists(target):
2525
return True
2626

2727

28+
def _alias_not_self(alias):
29+
"""Check if alias points to itself, either directly or within a circular reference
30+
"""
31+
aliases = keyboard_alias_definitions()
32+
33+
found = set()
34+
while alias in aliases:
35+
found.add(alias)
36+
alias = aliases[alias].get('target', alias)
37+
if alias in found:
38+
return False
39+
40+
return True
41+
42+
2843
@cli.subcommand('Validates the list of keyboard aliases.', hidden=True)
2944
def ci_validate_aliases(cli):
3045
aliases = keyboard_alias_definitions()
3146

3247
success = True
3348
for alias in aliases.keys():
3449
target = aliases[alias].get('target', None)
35-
if not _target_keyboard_exists(target):
50+
if not _alias_not_self(alias):
51+
cli.log.error(f'Keyboard alias {alias} should not point to itself')
52+
success = False
53+
54+
elif not _target_keyboard_exists(target):
3655
cli.log.error(f'Keyboard alias {alias} has a target that doesn\'t exist: {target}')
3756
success = False
3857

0 commit comments

Comments
 (0)