Skip to content

Commit 4afff89

Browse files
committed
lint-hotkeys: Lint the validity of help categories.
To check for typos.
1 parent e5e9010 commit 4afff89

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

tools/lint-hotkeys

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def lint_hotkeys_file() -> None:
3939
existing OUTPUT_FILE
4040
"""
4141
hotkeys_file_string = get_hotkeys_file_string()
42+
error_flag = 0 if is_every_key_category_valid() else 1
4243
# To lint keys description
43-
error_flag = 0
4444
categories = read_help_categories()
4545
for action in HELP_CATEGORIES:
4646
check_duplicate_keys_list: List[str] = []
@@ -91,6 +91,24 @@ def generate_hotkeys_file() -> None:
9191
print(f"Hot Keys list saved in {OUTPUT_FILE}")
9292

9393

94+
def is_every_key_category_valid() -> bool:
95+
"""
96+
Check for typos in key categories in KEYS_FILE
97+
"""
98+
error_flag = False
99+
for key, binding in KEY_BINDINGS.items():
100+
key_category = binding.get("key_category")
101+
if key_category not in HELP_CATEGORIES:
102+
print(
103+
f"Invalid key_category '{key_category}' for key '{key}'."
104+
f" Choose a category from:\n{', '.join(HELP_CATEGORIES.keys())}\n"
105+
)
106+
error_flag = True
107+
if not error_flag:
108+
print("All key bindings have valid categories.")
109+
return not error_flag
110+
111+
94112
def get_hotkeys_file_string() -> str:
95113
"""
96114
Construct string in form for output to OUTPUT_FILE based on help text

0 commit comments

Comments
 (0)