Skip to content

Commit 10a73e3

Browse files
authored
ci: add check_tag_problems.py (#52)
1 parent 396bbdc commit 10a73e3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ endef
4343

4444
lint:
4545
poetry run python scripts/sort_tags.py
46+
poetry run python scripts/check_tag_problems.py
4647
poetry sort
4748
npx prettier --write "**/*.{ts,tsx,css,json,yaml,yml,md}"
4849
$(call lint_target,.)

scripts/check_tag_problems.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
from pathlib import Path
4+
5+
import json5
6+
7+
8+
def main():
9+
# Load tags file
10+
tags_file = Path("leetcode_py/cli/resources/leetcode/json/tags.json5")
11+
problems_dir = Path("leetcode_py/cli/resources/leetcode/json/problems")
12+
13+
with open(tags_file) as f:
14+
tags_data = json5.load(f)
15+
16+
# Get all existing problem JSON files
17+
existing_problems = {p.stem for p in problems_dir.glob("*.json")}
18+
19+
# Check each tag's problems
20+
missing_problems = []
21+
for tag_name, problems in tags_data.items():
22+
if isinstance(problems, list):
23+
for problem in problems:
24+
if isinstance(problem, str): # Skip dict entries like {"tag": "grind-75"}
25+
if problem not in existing_problems:
26+
missing_problems.append((tag_name, problem))
27+
28+
if missing_problems:
29+
print("❌ Found problems in tags that don't have JSON files:")
30+
for tag_name, problem in missing_problems:
31+
print(f" {tag_name}: {problem}")
32+
sys.exit(1)
33+
else:
34+
print("✅ All tagged problems have corresponding JSON files!")
35+
sys.exit(0)
36+
37+
38+
if __name__ == "__main__":
39+
main()

0 commit comments

Comments
 (0)