forked from mirror/qmk_firmware
Update lint to validate keymap names (#25969)
This commit is contained in:
@@ -8,7 +8,7 @@ from milc import cli
|
|||||||
from qmk.decorators import automagic_keyboard, automagic_keymap
|
from qmk.decorators import automagic_keyboard, automagic_keymap
|
||||||
from qmk.info import info_json
|
from qmk.info import info_json
|
||||||
from qmk.keyboard import keyboard_completer, keyboard_folder_or_all, is_all_keyboards, list_keyboards
|
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.path import keyboard
|
||||||
from qmk.git import git_get_ignored_files
|
from qmk.git import git_get_ignored_files
|
||||||
from qmk.c_parse import c_source_files, preprocess_c_file
|
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):
|
def keymap_check(kb, km):
|
||||||
"""Perform the keymap level checks.
|
"""Perform the keymap level checks.
|
||||||
"""
|
"""
|
||||||
ok = True
|
|
||||||
keymap_path = locate_keymap(kb, km)
|
keymap_path = locate_keymap(kb, km)
|
||||||
|
|
||||||
if not keymap_path:
|
if not keymap_path:
|
||||||
ok = False
|
|
||||||
cli.log.error("%s: Can't find %s keymap.", kb, km)
|
cli.log.error("%s: Can't find %s keymap.", kb, km)
|
||||||
return ok
|
return False
|
||||||
|
|
||||||
if km in INVALID_KM_NAMES:
|
if km in INVALID_KM_NAMES:
|
||||||
ok = False
|
|
||||||
cli.log.error("%s: The keymap %s should not exist!", kb, km)
|
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
|
# Additional checks
|
||||||
invalid_files = git_get_ignored_files(keymap_path.parent.as_posix())
|
invalid_files = git_get_ignored_files(keymap_path.parent.as_posix())
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""Functions that help you work with QMK keymaps.
|
"""Functions that help you work with QMK keymaps.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from subprocess import DEVNULL
|
from subprocess import DEVNULL
|
||||||
|
|
||||||
@@ -239,6 +240,13 @@ def is_keymap_dir(keymap, c=True, json=True, additional_files=None):
|
|||||||
return True
|
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):
|
def generate_json(keymap, keyboard, layout, layers, macros=None):
|
||||||
"""Returns a `keymap.json` for the specified keyboard, layout, and layers.
|
"""Returns a `keymap.json` for the specified keyboard, layout, and layers.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user