Skip to content

Commit bda6622

Browse files
committed
Extend lint checks to reject duplication of defaults
1 parent 00f07ec commit bda6622

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

Diff for: data/mappings/info_defaults.hjson

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"bootmagic": {
3+
"matrix": [0, 0]
4+
},
5+
"backlight": {
6+
"default": {
7+
"on": true
8+
},
9+
"breathing_period": 6,
10+
"levels": 3,
11+
"on_state": 1
12+
},
13+
"features": {
14+
"command": false,
15+
"console": false
16+
},
17+
"indicators": {
18+
"on_state": 1
19+
},
20+
"led_matrix": {
21+
"default": {
22+
"animation": "solid",
23+
"on": true,
24+
"val": 255,
25+
"speed": 128
26+
},
27+
"led_flush_limit": 16,
28+
"max_brightness": 255,
29+
"sleep": false,
30+
"speed_steps": 16,
31+
"val_steps": 16
32+
},
33+
"rgblight": {
34+
"default": {
35+
"animation": "static_light",
36+
"on": true,
37+
"hue": 0,
38+
"sat": 255,
39+
"val": 255,
40+
"speed": 0
41+
},
42+
"brightness_steps": 17,
43+
"hue_steps": 8,
44+
"max_brightness": 255,
45+
"saturation_steps": 17,
46+
"sleep": false
47+
},
48+
"rgb_matrix": {
49+
"default": {
50+
"animation": "cycle_left_right",
51+
"on": true,
52+
"hue": 0,
53+
"sat": 255,
54+
"val": 255,
55+
"speed": 128
56+
},
57+
"hue_steps": 8,
58+
"led_flush_limit": 16,
59+
"max_brightness": 255,
60+
"sat_steps": 16,
61+
"sleep": false,
62+
"speed_steps": 16,
63+
"val_steps": 16
64+
},
65+
"split": {
66+
"serial": {
67+
"driver": "bitbang"
68+
}
69+
},
70+
"ws2812": {
71+
"driver": "bitbang"
72+
}
73+
}

Diff for: lib/python/qmk/cli/lint.py

+34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Command to look over a keyboard/keymap and check for common mistakes.
22
"""
3+
from dotty_dict import dotty
34
from pathlib import Path
45

56
from milc import cli
@@ -11,6 +12,7 @@
1112
from qmk.path import keyboard
1213
from qmk.git import git_get_ignored_files
1314
from qmk.c_parse import c_source_files, preprocess_c_file
15+
from qmk.json_schema import json_load
1416

1517
CHIBIOS_CONF_CHECKS = ['chconf.h', 'halconf.h', 'mcuconf.h', 'board.h']
1618
INVALID_KB_FEATURES = set(['encoder_map', 'dip_switch_map', 'combo', 'tap_dance', 'via'])
@@ -206,6 +208,35 @@ def _rules_mk_assignment_only(rules_mk):
206208
return errors
207209

208210

211+
def _handle_duplicating_code_defaults(kb, info):
212+
def _collect_dotted_output(kb_info_json, prefix=''):
213+
"""Print the info.json in a plain text format with dot-joined keys.
214+
"""
215+
for key in sorted(kb_info_json):
216+
new_prefix = f'{prefix}.{key}' if prefix else key
217+
218+
if isinstance(kb_info_json[key], dict):
219+
yield from _collect_dotted_output(kb_info_json[key], new_prefix)
220+
elif isinstance(kb_info_json[key], list):
221+
# TODO: handle non primitives?
222+
yield (new_prefix, kb_info_json[key])
223+
else:
224+
yield (new_prefix, kb_info_json[key])
225+
226+
defaults_map = json_load(Path('data/mappings/info_defaults.hjson'))
227+
dotty_info = dotty(info)
228+
229+
ok = True
230+
231+
for key, v_default in _collect_dotted_output(defaults_map):
232+
v_info = dotty_info.get(key)
233+
if v_default == v_info:
234+
cli.log.error(f'{kb}: Option "{key}" duplicates default value of "{v_default}"')
235+
ok = False
236+
237+
return ok
238+
239+
209240
def keymap_check(kb, km):
210241
"""Perform the keymap level checks.
211242
"""
@@ -255,6 +286,9 @@ def keyboard_check(kb): # noqa C901
255286
if not _handle_invalid_features(kb, kb_info):
256287
ok = False
257288

289+
if not _handle_duplicating_code_defaults(kb, kb_info):
290+
ok = False
291+
258292
invalid_files = git_get_ignored_files(f'keyboards/{kb}/')
259293
for file in invalid_files:
260294
if 'keymap' in file:

0 commit comments

Comments
 (0)