ws-polish: README / STYLE module lists and format counts from the tree, checked by a DOCS lint rule

tools/lint_rules.py DOCS: the README and STYLE layout blocks must name every codecs/<domain>/<Name>,
containers/ and core/ module; README's format counts must match docs/FORMATS.md; the guide index must
link every guide page. STYLE's 'use what exists' table lists the wave-3 shared modules.
This commit is contained in:
4DBug committed 2026-10-31 17:16:08 -05:00
1 parent 42e96a0964
commit 84fb8f42f1
4 files changed
+132 -37

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@
# TYPES: the other type diagnostics are counted (unique lines: the analyzer reports a required module once per
# path spelling) and printed with LINT_TYPES=1. The count may not rise above tools/lint_types_baseline.txt; when
# it drops, lower the baseline (LINT_TYPES_UPDATE=1 writes the current count), so it only goes down.
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT:
# 2. HEADER, REQUIRE, NATIVE (native code never throws: it crashes Roblox Studio), LAYERS, DEPS, CONTRACT, DUP, DOCS:
# tools/lint_rules.py (its header lists the rules; docs/STYLE.md explains them).
# 3. The generated registry / docs/FORMATS.md are up to date (tools/gen_registry.py --check), and tools/build.py's
# token passes pass their self-test.
+67
View File
@@ -20,6 +20,9 @@
# DUP no copy-pasted code: a function body of DUP_LINES (12) or more code lines whose tokens (comments and
# whitespace dropped, identifiers kept) equal another module's function body fails; move it down to a
# shared module (core / codecs / containers) and call it from both.
# DOCS the module lists in README.md's Layout block and docs/STYLE.md's layer block name every codec
# (codecs/<domain>/<Name>), container and core module in the tree; README.md's format counts
# ("images (25)", ...) match the registry (docs/FORMATS.md); docs/guide/README.md links every guide page.
import os, re, sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -314,5 +317,69 @@ for key, where in bodies.items():
if f != first[0]:
bad(f, ln, "DUP: `%s` repeats %s:%d (move it to a shared module)" % (head[:60], os.path.relpath(first[0], ROOT), first[1]))
# ---------------------------------------------------------------------------------------------------- DOCS
def module_names(rel):
"""the module names directly under src/Formats/<rel>: Foo.luau and Foo/ (a folder module)"""
d = os.path.join(SRC, rel)
names = set()
for n in os.listdir(d):
if n.endswith(".luau"):
names.add(n[:-5])
elif os.path.isdir(os.path.join(d, n)):
names.add(n)
return names
def layout_block(path):
"""(first line, text) of the first fenced block of a markdown file that starts with src/Formats/"""
lines = open(path, encoding="utf-8").read().split("\n")
for i, line in enumerate(lines):
if line.startswith("```") and i + 1 < len(lines) and lines[i + 1].startswith("src/Formats/"):
j = i + 1
while j < len(lines) and not lines[j].startswith("```"):
j += 1
return i + 1, "\n".join(lines[i + 1:j])
return 1, ""
modules = []
for dom in sorted(os.listdir(os.path.join(SRC, "codecs"))):
modules += ["codecs/%s/%s" % (dom, n) for n in sorted(module_names("codecs/" + dom))]
modules += ["containers/" + n for n in sorted(module_names("containers"))]
modules += ["core/" + n for n in sorted(module_names("core"))]
for doc in ("README.md", os.path.join("docs", "STYLE.md")):
path = os.path.join(ROOT, doc)
ln, block = layout_block(path)
if not block:
bad(path, 1, "DOCS: no layout block (a ``` block starting with src/Formats/)")
continue
for m in modules:
if not re.search(r"(?<![\w/])" + re.escape(m.rsplit("/", 1)[1]) + r"\b", block):
bad(path, ln, "DOCS: the layout block does not list %s" % m)
LABELS = {"image": "images", "audio": "audio", "video": "video", "model": "3D models", "cad": "CAD", "font": "fonts",
"archive": "archives", "data": "data", "vector": "vector graphics and tile maps", "layered": "layered images",
"subtitle": "subtitles", "music": "music", "playlist": "playlists"}
counts = {}
for line in open(os.path.join(ROOT, "docs", "FORMATS.md"), encoding="utf-8"):
cells = [c.strip() for c in line.split("|")]
if len(cells) > 3 and cells[1] in LABELS:
counts[cells[1]] = counts.get(cells[1], 0) + 1
readme = os.path.join(ROOT, "README.md")
rtext = open(readme, encoding="utf-8").read()
m = re.search(r"(\d+) formats:", rtext)
if not m or int(m.group(1)) != sum(counts.values()):
bad(readme, 1, "DOCS: README.md should say \"%d formats:\" (docs/FORMATS.md)" % sum(counts.values()))
for cat, label in LABELS.items():
m = re.search(r"\s+".join(map(re.escape, label.split())) + r"\s+\((\d+)\)", rtext)
if not m or int(m.group(1)) != counts.get(cat, 0):
bad(readme, 1, "DOCS: README.md should say \"%s (%d)\" (docs/FORMATS.md)" % (label, counts.get(cat, 0)))
guide = os.path.join(ROOT, "docs", "guide")
gindex = open(os.path.join(guide, "README.md"), encoding="utf-8").read()
for n in sorted(os.listdir(guide)):
if n.endswith(".md") and n != "README.md" and "](%s" % n not in gindex:
bad(os.path.join(guide, "README.md"), 1, "DOCS: the guide index does not link %s" % n)
print("\n".join(out))
sys.exit(1 if out else 0)