feat(brain): integrate Ruff linting and Pyright type checking into validator
Brain Structural Validation / Validate Markdown Structure & Links (push) Failing after 4s

- Add check 8 to automatically run ruff check on repository scripts and practice code
- Add check 9 to verify type consistency via Pyright
- Handle environments where ruff or pyright are not installed by gracefully skipping
This commit is contained in:
kiskaadee committed 2026-09-10 08:56:06 -05:00
1 parent ff59aa44af
commit e822cccadb
1 file changed
+32 -3
+32 -3
View File
@@ -11,9 +11,11 @@ Checks:
5. Every relative markdown link resolves to an existing file.
"""
import re
import sys
import pathlib
import re
import shutil
import subprocess
import sys
ROOT = pathlib.Path(__file__).parent.parent.resolve()
@@ -113,7 +115,7 @@ for md in ROOT.rglob("*.md"):
content = md.read_text(errors="replace")
for m in re.finditer(r'\[([^\]]*)\]\(([^)]+)\)', content):
target = m.group(2).split('#')[0].strip()
if not target or target.startswith('http') or target.startswith('file:') or target.startswith('mailto:'):
if not target or target.startswith(('http', 'file:', 'mailto:')):
continue
resolved = (md.parent / target).resolve()
if not resolved.exists():
@@ -199,6 +201,32 @@ for md in ROOT.rglob("*.md"):
print(f" {'✓' if mermaid_errors == 0 else '✗'} Done ({mermaid_errors} issues).\n")
# ── Check 8: Python Linting (Ruff) ────────────────────────────────────────────
print("Checking Python code quality (Ruff)...")
if shutil.which("ruff"):
res = subprocess.run(["ruff", "check", str(ROOT)], capture_output=True, text=True, check=False)
if res.returncode != 0:
errors.append(f"Ruff linting failed:\n{res.stdout.strip()}")
print(" ✗ Done (Ruff errors found).\n")
else:
print(" ✓ Done (0 lint issues).\n")
else:
print(" ℹ Skipped (ruff not in PATH).\n")
# ── Check 9: Python Type Checking (Pyright) ───────────────────────────────────
print("Checking Python type consistency (Pyright)...")
if shutil.which("pyright"):
res = subprocess.run(["pyright", str(ROOT / "scripts"), str(ROOT / "practice")], capture_output=True, text=True, check=False)
if res.returncode != 0:
errors.append(f"Pyright type checks failed:\n{res.stdout.strip()}")
print(" ✗ Done (Pyright errors found).\n")
else:
print(" ✓ Done (0 type errors).\n")
else:
print(" ℹ Skipped (pyright not in PATH).\n")
# ── Summary ───────────────────────────────────────────────────────────────────
if errors:
print(f"❌ Validation failed — {len(errors)} error(s):\n")
@@ -208,3 +236,4 @@ if errors:
else:
print("✅ All checks passed. Brain structure is valid.")