forked from mirrors/qmk_firmware
Reduce false positives in layout name validation (#19646)
This commit is contained in:
parent
0a9d06a505
commit
90f3d6201a
1 changed files with 27 additions and 12 deletions
|
@ -1,9 +1,10 @@
|
||||||
"""Functions that help us generate and use info.json files.
|
"""Functions that help us generate and use info.json files.
|
||||||
"""
|
"""
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
from dotty_dict import dotty
|
from dotty_dict import dotty
|
||||||
|
|
||||||
from milc import cli
|
from milc import cli
|
||||||
|
|
||||||
from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS
|
from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS
|
||||||
|
@ -17,16 +18,31 @@ from qmk.math import compute
|
||||||
true_values = ['1', 'on', 'yes']
|
true_values = ['1', 'on', 'yes']
|
||||||
false_values = ['0', 'off', 'no']
|
false_values = ['0', 'off', 'no']
|
||||||
|
|
||||||
|
|
||||||
|
def _keyboard_in_layout_name(keyboard, layout):
|
||||||
|
"""Validate that a layout macro does not contain name of keyboard
|
||||||
|
"""
|
||||||
# TODO: reduce this list down
|
# TODO: reduce this list down
|
||||||
SAFE_LAYOUT_TOKENS = {
|
safe_layout_tokens = {
|
||||||
'ansi',
|
'ansi',
|
||||||
'iso',
|
'iso',
|
||||||
|
'jp',
|
||||||
|
'jis',
|
||||||
|
'ortho',
|
||||||
'wkl',
|
'wkl',
|
||||||
'tkl',
|
'tkl',
|
||||||
'preonic',
|
'preonic',
|
||||||
'planck',
|
'planck',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Ignore tokens like 'split_3x7_4' or just '2x4'
|
||||||
|
layout = re.sub(r"_split_\d+x\d+_\d+", '', layout)
|
||||||
|
layout = re.sub(r"_\d+x\d+", '', layout)
|
||||||
|
|
||||||
|
name_fragments = set(keyboard.split('/')) - safe_layout_tokens
|
||||||
|
|
||||||
|
return any(fragment in layout for fragment in name_fragments)
|
||||||
|
|
||||||
|
|
||||||
def _valid_community_layout(layout):
|
def _valid_community_layout(layout):
|
||||||
"""Validate that a declared community list exists
|
"""Validate that a declared community list exists
|
||||||
|
@ -60,10 +76,9 @@ def _validate(keyboard, info_data):
|
||||||
_log_warning(info_data, '"LAYOUT_all" should be "LAYOUT" unless additional layouts are provided.')
|
_log_warning(info_data, '"LAYOUT_all" should be "LAYOUT" unless additional layouts are provided.')
|
||||||
|
|
||||||
# Extended layout name checks - ignoring community_layouts and "safe" values
|
# Extended layout name checks - ignoring community_layouts and "safe" values
|
||||||
name_fragments = set(keyboard.split('/')) - SAFE_LAYOUT_TOKENS
|
|
||||||
potential_layouts = set(layouts.keys()) - set(community_layouts_names)
|
potential_layouts = set(layouts.keys()) - set(community_layouts_names)
|
||||||
for layout in potential_layouts:
|
for layout in potential_layouts:
|
||||||
if any(fragment in layout for fragment in name_fragments):
|
if _keyboard_in_layout_name(keyboard, layout):
|
||||||
_log_warning(info_data, f'Layout "{layout}" should not contain name of keyboard.')
|
_log_warning(info_data, f'Layout "{layout}" should not contain name of keyboard.')
|
||||||
|
|
||||||
# Filter out any non-existing community layouts
|
# Filter out any non-existing community layouts
|
||||||
|
|
Loading…
Reference in a new issue