Download scripts/lint.py from VanyaJ/bada-terminal: direct link, hf CLI and curl.
- Browser
- Download file 5.18 kB
-
https://huggingface.co/VanyaJ/bada-terminal/resolve/main/scripts/lint.py
- Command line
-
hf download hf://VanyaJ/bada-terminal/scripts/lint.py
-
curl -L -o lint.py https://huggingface.co/VanyaJ/bada-terminal/resolve/main/scripts/lint.py
5.18 kB
| #!/usr/bin/env python3 | |
| """ | |
| BADA & Knot LLMWiki ์ง์ ๋ฌด๊ฒฐ์ฑ Linter | |
| ์ฌ์ฉ: python3 scripts/lint.py [wiki_path] (๊ธฐ๋ณธ๊ฐ: ./wiki) | |
| ๊ท์ฝ ์๋ฐ ์ exit 1์ ๋ฐํํฉ๋๋ค. | |
| """ | |
| import os | |
| import re | |
| import sys | |
| from pathlib import Path | |
| TYPES = {"source", "entity", "concept", "note"} | |
| REQUIRED_FIELDS = ["type", "created", "updated", "sources"] | |
| DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$") | |
| LINK_RE = re.compile(r"\[\[([^\]|#\n]+?)(?:\|[^\]]*)?\]\]") | |
| errors = [] | |
| warnings = [] | |
| def parse_frontmatter(text): | |
| """YAML Frontmatter๋ฅผ ํ์ฑํ์ฌ dict๋ก ๋ฐํ. ํ์ ์ค๋ฅ ์ None.""" | |
| lines = text.split("\n") | |
| if not lines or lines[0].strip() != "---": | |
| return None | |
| fm = {} | |
| key = None | |
| for line in lines[1:]: | |
| if line.strip() == "---": | |
| return fm | |
| if ":" in line: | |
| k, _, v = line.partition(":") | |
| k = k.strip() | |
| v = v.split("#")[0].strip() | |
| key = k | |
| # ๋ฐฐ์ด ์ฒ๋ฆฌ [a, b] | |
| if v.startswith("[") and v.endswith("]"): | |
| fm[k] = [x.strip().strip("'\"") for x in v[1:-1].split(",") if x.strip()] | |
| else: | |
| fm[k] = v.strip("'\"") | |
| elif key and line.strip().startswith("- "): | |
| if not isinstance(fm[key], list): | |
| fm[key] = [] | |
| fm[key].append(line.strip()[2:].strip().strip("'\"")) | |
| return None # ๋ซ๋ ---๊ฐ ์์ | |
| def main(): | |
| wiki_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("./wiki") | |
| if not wiki_path.is_dir(): | |
| print(f"๐จ ERROR: wiki ๋๋ ํ ๋ฆฌ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค: {wiki_path}") | |
| return 1 | |
| print(f"๐ Starting LLMWiki Lint check on: {wiki_path.resolve()}") | |
| # 1. wiki/ ๋ด์ ๋ชจ๋ ๋งํฌ๋ค์ด ํ์ผ ํ์ (Flat ๊ตฌ์กฐ ๊ฒ์ฆ) | |
| pages = sorted(wiki_path.glob("*.md")) | |
| slugs = {p.stem for p in pages} | |
| inbound_links = {s: [] for s in slugs} | |
| # 2. ๊ฐ๋ณ ํ์ผ ๋ถ์ ๋ฐ ์ ํฉ์ฑ ๊ฒ์ฌ | |
| for p in pages: | |
| if p.name.lower() in ("schema.md", "index.md", "ontology-index.md", "claude.md", "architecture.md", "readme.md"): | |
| continue | |
| filename = f"wiki/{p.name}" | |
| try: | |
| text = p.read_text(encoding="utf-8") | |
| except Exception as e: | |
| errors.append(f"{filename}: ํ์ผ ์ฝ๊ธฐ ์คํจ - {str(e)}") | |
| continue | |
| # Frontmatter ํ์ฑ | |
| fm = parse_frontmatter(text) | |
| if fm is None: | |
| errors.append(f"{filename}: Frontmatter๊ฐ ๋๋ฝ๋์๊ฑฐ๋ ํ์์ด ๋ถ๋ํฉ๋๋ค.") | |
| continue | |
| # ํ์ ํ๋ ์ฒดํฌ | |
| for field in REQUIRED_FIELDS: | |
| if field not in fm: | |
| errors.append(f"{filename}: ํ์ ํ๋ '{field}'๊ฐ Frontmatter์ ์์ต๋๋ค.") | |
| # ํ์ ๊ฒ์ฌ | |
| if "type" in fm and fm["type"] not in TYPES: | |
| errors.append(f"{filename}: ํ์ฉ๋์ง ์์ type '{fm['type']}' (ํ์ฉ: {list(TYPES)})") | |
| # ๋ ์ง ํฌ๋งท ๊ฒ์ฌ | |
| for date_field in ("created", "updated"): | |
| if date_field in fm and not DATE_RE.match(str(fm[date_field])): | |
| errors.append(f"{filename}: '{date_field}' ๋ ์ง ํฌ๋งท์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค (YYYY-MM-DD ๊ถ์ฅ).") | |
| # ๋ณธ๋ฌธ ๋งํฌ ๊ฒ์ฌ | |
| lines = text.split("\n") | |
| for line_num, line in enumerate(lines, 1): | |
| for match in LINK_RE.finditer(line): | |
| target_slug = match.group(1).strip() | |
| # ์ต์ปค ๋งํฌ(#) ์ ๊ฑฐ ํ ํ์ผ๋ช ์ฌ๋ฌ๊ทธ ์ถ์ถ | |
| clean_slug = target_slug.split("#")[0].strip() | |
| # notes/ ๋ฐ ์ด๋ ฅ ๋ฑ ์ธ๋ถ ํด๋ ์ฐธ์กฐ ๋งํฌ ์์ธ ํต๊ณผ | |
| if "/" in clean_slug or clean_slug.startswith(".."): | |
| continue | |
| # wiki ๋ด๋ถ ์ฌ๋ฌ๊ทธ ๊ฒ์ฌ | |
| if clean_slug not in slugs: | |
| # stub ์ฃผ์ ์ฒ๋ฆฌ๋์ด ์์ผ๋ฉด ํต๊ณผ | |
| if "<!-- stub -->" in line: | |
| continue | |
| errors.append(f"{filename}:{line_num}: ๊นจ์ง ๋งํฌ [[{target_slug}]] ๊ฐ ์กด์ฌํฉ๋๋ค (์กด์ฌํ์ง ์๋ ์ฌ๋ฌ๊ทธ).") | |
| else: | |
| inbound_links[clean_slug].append(p.stem) | |
| # 3. ๊ณ ์ ๋ ธ๋(Orphan Node) ํ์ (index.md ๋ฐ ontology-index.md ์ ์ธ) | |
| for slug, links in inbound_links.items(): | |
| if slug in ("index", "ontology-index", "schema"): | |
| continue | |
| if not links: | |
| warnings.append(f"wiki/{slug}.md: ํผ๋งํฌ๊ฐ ์๋ ๊ณ ์(Orphan) ์ง์ ๋ ธ๋์ ๋๋ค.") | |
| # 4. ๊ฒ์ฌ ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
| print("\n=== Lint Summary ===") | |
| print(f"Total processed files: {len(pages)}") | |
| print(f"Errors found: {len(errors)}") | |
| print(f"Warnings found: {len(warnings)}") | |
| if warnings: | |
| print("\nโ ๏ธ WARNINGS:") | |
| for w in warnings: | |
| print(f" - {w}") | |
| if errors: | |
| print("\n๐จ ERRORS (Lint Failed):") | |
| for e in errors: | |
| print(f" - {e}") | |
| return 1 | |
| print("\nโ LLMWiki Lint PASSED successfully!") | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |