ws-cleanup: shared plumbing: Err.from, core/Sniff, Pcm.drain, Bits.msbPut; DUP lint; tools/move.py
- core/Err.from(message, offset?, kind?): the private-submodule -> Err plumbing (a kind, or a 'code: ' prefix / 'truncated' / 'past the end' in the message) that Brotli, Bzip2, Zstd, Jpeg, WOFF2, FBX, plist, msgpack and bmfont each wrote. - core/Sniff (new): Sniff.text(r, n, trim?) (the start of a text file without its BOM), Sniff.dropBom(s), Sniff.magic(r, s); 13 text formats' sniff / decode BOM handling goes through it. - codecs/Pcm.drain(dec, source?, maxFrames?): a format's decode() through its open(); the collect-the-Decoder loops of aac, aiff, au, caf, flac, m4a, mp3, opus, vorbis and wav are one call each. - core/Bits.msbPut: the MSB-first bit writer the MP3 / MP2 / FLAC encoders each copied. - tools/lint_rules.py DUP: a function body of 12+ code lines repeated token for token in another module fails. - tools/move.py: moves a module and rewrites every reference (requires, deps, headers, fixture INPUTS, docs). - tools/fixtures/zstd.py: the incompressible corpus is smaller (zstd.luau 15.1 -> 13.4 MB; every fixture module is now under 14.3 MB). - tools/bench.luau: MPEG-1 also runs with the api's LuaJIT trace limits; the sections that compare tuned / default limits set them explicitly (jitTune), so the order of sections no longer leaks the tuning.
This commit is contained in:
1 parent
3243404374
commit
763f4a7c04
44 files changed
+374
-370
No files matched your search
@@ -16,6 +16,9 @@
|
||||
# extensions, mime, deps, caps (with decode / encode matching the functions), function <X>.sniff, at least
|
||||
# one of decode / encode / open, the section markers in order, and ends with return <X>; it has a test
|
||||
# tests/<category>/<fmt>.luau with a fuzz pass (:fuzz().
|
||||
# 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.
|
||||
import os, re, sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
@@ -275,5 +278,33 @@ for folder in folders:
|
||||
elif ":fuzz(" not in open(test).read():
|
||||
bad(test, 0, "CONTRACT: a format test includes the fuzz no-throw pass (t:fuzz(...))")
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------- DUP
|
||||
DUP_LINES = 12
|
||||
TOKEN = re.compile(r'"(?:[^"\\]|\\.)*"|\'(?:[^\'\\]|\\.)*\'|\[=*\[.*?\]=*\]|[A-Za-z_][A-Za-z0-9_]*|\d[\w.]*|\S')
|
||||
FUNC = re.compile(r"^(\s*)(?:local\s+)?function\b")
|
||||
bodies = {}
|
||||
for f, lines in text.items():
|
||||
for i, line in enumerate(lines):
|
||||
m = FUNC.match(line)
|
||||
if not m:
|
||||
continue
|
||||
end = re.compile("^" + re.escape(m.group(1)) + r"end\b")
|
||||
j = i + 1
|
||||
while j < len(lines) and not end.match(lines[j]):
|
||||
j += 1
|
||||
body = [code(x).strip() for x in lines[i + 1:j]]
|
||||
body = [x for x in body if x]
|
||||
if len(body) < DUP_LINES:
|
||||
continue
|
||||
key = " ".join(TOKEN.findall(" ".join(body)))
|
||||
bodies.setdefault(key, []).append((f, i + 1, line.strip()))
|
||||
for key, where in bodies.items():
|
||||
files_ = {w[0] for w in where}
|
||||
if len(files_) > 1:
|
||||
first = where[0]
|
||||
for f, ln, head in where[1:]:
|
||||
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]))
|
||||
|
||||
print("\n".join(out))
|
||||
sys.exit(1 if out else 0)
|
||||
Reference in new issue
Block a user