Split shared UI knowledge into atomic topic directories
This commit is contained in:
1 parent
08ff987edb
commit
b0e6402d66
37 files changed
+600
-516
No files matched your search
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check local documentation links and reachability of nested contracts."""
|
||||
from pathlib import Path
|
||||
import re
|
||||
import sys
|
||||
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
patterns = root / 'rules/patterns'
|
||||
documents = list(root.glob('*.md')) + list((root / 'rules').rglob('*.md'))
|
||||
links = {}
|
||||
errors = []
|
||||
|
||||
for document in documents:
|
||||
text = re.sub(r'```.*?```', '', document.read_text(), flags=re.S)
|
||||
targets = []
|
||||
for reference in re.findall(r'\[[^\]]*\]\(([^)]+)\)', text):
|
||||
if re.match(r'[a-zA-Z]+:|#', reference):
|
||||
continue
|
||||
target = (document.parent / reference.split('#')[0]).resolve()
|
||||
if not target.exists():
|
||||
errors.append(f'{document.relative_to(root)}: missing {reference}')
|
||||
targets.append(target)
|
||||
links[document.resolve()] = targets
|
||||
|
||||
# Top-level patterns are checked against the bootstrap router by lint.sh.
|
||||
# Every nested contract must also be reachable through that pattern's entry.
|
||||
for pattern in patterns.iterdir():
|
||||
if not pattern.is_dir():
|
||||
continue
|
||||
seen = set()
|
||||
pending = [(pattern / 'contract.md').resolve()]
|
||||
while pending:
|
||||
path = pending.pop()
|
||||
if path in seen:
|
||||
continue
|
||||
seen.add(path)
|
||||
pending.extend(links.get(path, []))
|
||||
for contract in pattern.rglob('contract.md'):
|
||||
if contract.resolve() not in seen:
|
||||
errors.append(f'{contract.relative_to(root)}: unreachable from pattern contract')
|
||||
|
||||
for error in errors:
|
||||
print('FAIL:', error)
|
||||
if not errors:
|
||||
print('OK: local documentation links and nested contracts')
|
||||
sys.exit(bool(errors))
|
||||
Reference in new issue
Block a user