Update lint to validate keymap names (#25969)

This commit is contained in:
Joel Challis
2026-02-10 16:48:09 +00:00
committed by GitHub
parent db4d8823d6
commit a170e6f191
2 changed files with 17 additions and 6 deletions
+9 -6
View File
@@ -8,7 +8,7 @@ from milc import cli
from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.info import info_json
from qmk.keyboard import keyboard_completer, keyboard_folder_or_all, is_all_keyboards, list_keyboards
from qmk.keymap import locate_keymap, list_keymaps
from qmk.keymap import locate_keymap, list_keymaps, is_valid_keymap_name
from qmk.path import keyboard
from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files, preprocess_c_file
@@ -245,18 +245,21 @@ def _handle_duplicating_code_defaults(kb, info):
def keymap_check(kb, km):
"""Perform the keymap level checks.
"""
ok = True
keymap_path = locate_keymap(kb, km)
if not keymap_path:
ok = False
cli.log.error("%s: Can't find %s keymap.", kb, km)
return ok
return False
if km in INVALID_KM_NAMES:
ok = False
cli.log.error("%s: The keymap %s should not exist!", kb, km)
return ok
return False
ok = True
if not is_valid_keymap_name(km):
cli.log.error(f'{kb}/{km}: Keymap name must contain only a-z, 0-9 and _!')
ok = False
# Additional checks
invalid_files = git_get_ignored_files(keymap_path.parent.as_posix())
+8
View File
@@ -1,6 +1,7 @@
"""Functions that help you work with QMK keymaps.
"""
import sys
import re
from pathlib import Path
from subprocess import DEVNULL
@@ -239,6 +240,13 @@ def is_keymap_dir(keymap, c=True, json=True, additional_files=None):
return True
def is_valid_keymap_name(name):
"""Returns True if the given keymap name contains only valid characters.
"""
regex = re.compile(r'^[a-z0-9][a-z0-9_]+$')
return bool(regex.match(name))
def generate_json(keymap, keyboard, layout, layers, macros=None):
"""Returns a `keymap.json` for the specified keyboard, layout, and layers.