aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <[email protected]>2025-04-24 05:39:56 +0100
committerGitHub <[email protected]>2025-04-24 05:39:56 +0100
commit8244659b44ac5ecdeef42d62839a24aa60516ff3 (patch)
tree44e4edac33710d2aa9ac19536561d841b38cf062
parent0bd02952eab98f3c2327b80705f03ce7ede6e100 (diff)
downloadqmk_firmware-8244659b44ac5ecdeef42d62839a24aa60516ff3.tar.gz
qmk_firmware-8244659b44ac5ecdeef42d62839a24aa60516ff3.zip
Extend lint checks to reject duplication of defaults (#25149)
-rw-r--r--data/mappings/info_defaults.hjson73
-rw-r--r--lib/python/qmk/cli/lint.py31
2 files changed, 104 insertions, 0 deletions
diff --git a/data/mappings/info_defaults.hjson b/data/mappings/info_defaults.hjson
new file mode 100644
index 0000000000..00f50437a2
--- /dev/null
+++ b/data/mappings/info_defaults.hjson
@@ -0,0 +1,73 @@
+{
+ "bootmagic": {
+ "matrix": [0, 0]
+ },
+ "backlight": {
+ "default": {
+ "on": true
+ },
+ "breathing_period": 6,
+ "levels": 3,
+ "on_state": 1
+ },
+ "features": {
+ "command": false,
+ "console": false
+ },
+ "indicators": {
+ "on_state": 1
+ },
+ "led_matrix": {
+ "default": {
+ "animation": "solid",
+ "on": true,
+ "val": 255,
+ "speed": 128
+ },
+ "led_flush_limit": 16,
+ "max_brightness": 255,
+ "sleep": false,
+ "speed_steps": 16,
+ "val_steps": 16
+ },
+ "rgblight": {
+ "default": {
+ "animation": "static_light",
+ "on": true,
+ "hue": 0,
+ "sat": 255,
+ "val": 255,
+ "speed": 0
+ },
+ "brightness_steps": 17,
+ "hue_steps": 8,
+ "max_brightness": 255,
+ "saturation_steps": 17,
+ "sleep": false
+ },
+ "rgb_matrix": {
+ "default": {
+ "animation": "cycle_left_right",
+ "on": true,
+ "hue": 0,
+ "sat": 255,
+ "val": 255,
+ "speed": 128
+ },
+ "hue_steps": 8,
+ "led_flush_limit": 16,
+ "max_brightness": 255,
+ "sat_steps": 16,
+ "sleep": false,
+ "speed_steps": 16,
+ "val_steps": 16
+ },
+ "split": {
+ "serial": {
+ "driver": "bitbang"
+ }
+ },
+ "ws2812": {
+ "driver": "bitbang"
+ }
+}
diff --git a/lib/python/qmk/cli/lint.py b/lib/python/qmk/cli/lint.py
index e2c76e4465..484ddb5bd9 100644
--- a/lib/python/qmk/cli/lint.py
+++ b/lib/python/qmk/cli/lint.py
@@ -1,5 +1,6 @@
"""Command to look over a keyboard/keymap and check for common mistakes.
"""
+from dotty_dict import dotty
from pathlib import Path
from milc import cli
@@ -11,6 +12,7 @@ from qmk.keymap import locate_keymap, list_keymaps
from qmk.path import keyboard
from qmk.git import git_get_ignored_files
from qmk.c_parse import c_source_files, preprocess_c_file
+from qmk.json_schema import json_load
CHIBIOS_CONF_CHECKS = ['chconf.h', 'halconf.h', 'mcuconf.h', 'board.h']
INVALID_KB_FEATURES = set(['encoder_map', 'dip_switch_map', 'combo', 'tap_dance', 'via'])
@@ -214,6 +216,32 @@ def _rules_mk_assignment_only(rules_mk):
return errors
+def _handle_duplicating_code_defaults(kb, info):
+ def _collect_dotted_output(kb_info_json, prefix=''):
+ """Print the info.json in a plain text format with dot-joined keys.
+ """
+ for key in sorted(kb_info_json):
+ new_prefix = f'{prefix}.{key}' if prefix else key
+
+ if isinstance(kb_info_json[key], dict):
+ yield from _collect_dotted_output(kb_info_json[key], new_prefix)
+ elif isinstance(kb_info_json[key], list):
+ # TODO: handle non primitives?
+ yield (new_prefix, kb_info_json[key])
+ else:
+ yield (new_prefix, kb_info_json[key])
+
+ defaults_map = json_load(Path('data/mappings/info_defaults.hjson'))
+ dotty_info = dotty(info)
+
+ for key, v_default in _collect_dotted_output(defaults_map):
+ v_info = dotty_info.get(key)
+ if v_default == v_info:
+ cli.log.warning(f'{kb}: Option "{key}" duplicates default value of "{v_default}"')
+
+ return True
+
+
def keymap_check(kb, km):
"""Perform the keymap level checks.
"""
@@ -266,6 +294,9 @@ def keyboard_check(kb): # noqa C901
if not _handle_invalid_config(kb, kb_info):
ok = False
+ if not _handle_duplicating_code_defaults(kb, kb_info):
+ ok = False
+
invalid_files = git_get_ignored_files(f'keyboards/{kb}/')
for file in invalid_files:
if 'keymap' in file: