diff --git a/src/Formats/audio/flac/Encode.luau b/src/Formats/audio/flac/Encode.luau index e6a0297..09bb289 100644 --- a/src/Formats/audio/flac/Encode.luau +++ b/src/Formats/audio/flac/Encode.luau @@ -769,7 +769,7 @@ function Encode.encode(src: Source, opts: Options): (buffer?, string?) local mbuf = buffer.create(bs * ch * mbytes) local scale = POW[bps] local maxv, minv = scale - 1, -scale - local X = table.create(ch) + local X: { { number } } = table.create(ch) :: any for c = 1, ch do X[c] = table.create(bs, 0) end diff --git a/src/Formats/audio/opus/Encode.luau b/src/Formats/audio/opus/Encode.luau index d26e4b1..971d872 100644 --- a/src/Formats/audio/opus/Encode.luau +++ b/src/Formats/audio/opus/Encode.luau @@ -25,7 +25,7 @@ local floor = math.floor -- encode(audio | decoder, opts) -> buffer | nil, Err function Encode.encode(value: any, opts: Options?): (buffer?, Err.Err?) - local o = opts or {} + local o: Options = opts or {} local src, serr = Pcm.source(value) if not src then return nil, serr diff --git a/src/Formats/audio/vorbis/Encode.luau b/src/Formats/audio/vorbis/Encode.luau index 2b1405e..e1ce3ad 100644 --- a/src/Formats/audio/vorbis/Encode.luau +++ b/src/Formats/audio/vorbis/Encode.luau @@ -604,7 +604,7 @@ function Encode.encode(src: Source, opts: Options): (buffer?, string?) local plan = Mdct.new(N) :: Mdct.Plan local win = Mdct.window("vorbis", N) :: { number } -- input ring: per channel the samples of the current frame [k*1024 - 1024, k*1024 + 1024) - local frame = table.create(ch) + local frame: { { number } } = table.create(ch) :: any for c = 1, ch do frame[c] = table.create(N, 0) end @@ -617,8 +617,8 @@ function Encode.encode(src: Source, opts: Options): (buffer?, string?) end end local blk = table.create(N, 0) - local X = table.create(ch) - local R = table.create(ch) + local X: { { number } } = table.create(ch) :: any + local R: { { number } } = table.create(ch) :: any for c = 1, ch do X[c] = table.create(N2, 0) R[c] = table.create(N2, 0) diff --git a/src/Formats/codecs/Resample/init.luau b/src/Formats/codecs/Resample/init.luau index e0bfdfd..1096060 100644 --- a/src/Formats/codecs/Resample/init.luau +++ b/src/Formats/codecs/Resample/init.luau @@ -208,7 +208,7 @@ local function run(st: State, limitOut: number, out: buffer?): (buffer, number) st.histFrames = 0 st.base = base + histFrames else - local nh = table.create((histFrames - drop) * ch) + local nh: { number } = table.create((histFrames - drop) * ch) :: any table.move(hist, drop * ch + 1, histFrames * ch, 1, nh) st.hist = nh st.histFrames = histFrames - drop @@ -251,7 +251,7 @@ function Resample.new(from: number, to: number, channels: number, opts: Options? if type(channels) ~= "number" or channels < 1 or channels > 256 or channels ~= floor(channels) then return nil, "bad channel count" end - local q = QUALITY[(opts and opts.quality) or "medium"] + local q: { number }? = QUALITY[(opts and opts.quality) or "medium"] if not q then return nil, "quality must be low, medium or high" end @@ -260,12 +260,11 @@ function Resample.new(from: number, to: number, channels: number, opts: Options? return nil, "cutoff must be 0.5 .. 1" end -- positions are exact integers: output j sits at input j * M / L (non-integer rates: to 1 / 1000 Hz) - local fi, ti = from, to - if from ~= floor(from) or to ~= floor(to) then - fi, ti = floor(from * 1000 + 0.5), floor(to * 1000 + 0.5) - end - local g = gcd(fi, ti) - local L, M = ti // g, fi // g + local scale = if from ~= floor(from) or to ~= floor(to) then 1000 else 1 + local fi: number = floor(from * scale + 0.5) + local ti: number = floor(to * scale + 0.5) + local g: number = gcd(fi, ti) + local L: number, M: number = ti // g, fi // g local exact = L <= MAX_EXACT local phases = if exact then L else INTERP_PHASES local st: State = { @@ -348,7 +347,7 @@ function Resample.source(src: any, to: number, opts: Options?): (any, string?) function out.read(self: any, n: number, dst: buffer?): (buffer, number) n = floor(n) while pendingFrames - pendingPos <= 0 and not ended do - local b, m = src:read(math.max(1024, floor(n * src.sampleRate / to) + 64), inTmp) + local b: buffer, m: number = (src :: any):read(math.max(1024, floor(n * src.sampleRate / to) + 64), inTmp) inTmp = b local r: buffer, k: number if m <= 0 then diff --git a/src/Formats/ops/AudioOps.luau b/src/Formats/ops/AudioOps.luau index c1a5d53..b1803e6 100644 --- a/src/Formats/ops/AudioOps.luau +++ b/src/Formats/ops/AudioOps.luau @@ -207,7 +207,7 @@ local TO_STEREO: { [string]: { number } } = { -- matrix(from, to) -> m[o][i]: output channel o = sum m[o][i] * input i local function matrix(from: number, to: number): { { number } } - local m = table.create(to) + local m: { { number } } = table.create(to) :: any for o = 1, to do m[o] = table.create(from, 0) end @@ -220,7 +220,7 @@ local function matrix(from: number, to: number): { { number } } local inL, outL = LAYOUT[from], LAYOUT[to] if to < from and inL and outL and to <= 2 then -- down to stereo (then mono = the average of the two) - local l, r = table.create(from, 0), table.create(from, 0) + local l: { number }, r: { number } = table.create(from, 0), table.create(from, 0) local sl, sr = 0, 0 for i, sp in inL do local w = TO_STEREO[sp] or { 0, 0 } @@ -266,10 +266,11 @@ local function matrix(from: number, to: number): { { number } } local o = outIdx[sp] if o then m[o][i] = 1 - elseif to < from and outIdx.FL and outIdx.FR then + elseif to < from and outIdx.FL ~= nil and outIdx.FR ~= nil then local w = TO_STEREO[sp] or { 0, 0 } - m[outIdx.FL][i] += w[1] - m[outIdx.FR][i] += w[2] + local fl, fr = outIdx.FL :: number, outIdx.FR :: number + m[fl][i] += w[1] + m[fr][i] += w[2] end end if to < from then diff --git a/tools/lint.sh b/tools/lint.sh index 270d758..bc16885 100644 --- a/tools/lint.sh +++ b/tools/lint.sh @@ -1,8 +1,10 @@ #!/usr/bin/env bash # Lint (bash tools/lint.sh): # 1. GLOBALS: unknown globals (luau-analyze), a local used before its declaration compiles fine but reads a nil -# global at runtime. Roblox globals are allowed (the library runs in Roblox, luau and LuaJIT). Other type errors -# are counted and printed with LINT_TYPES=1, but do not fail the lint (absorbed code predates --!strict). +# global at runtime. Roblox globals are allowed (the library runs in Roblox, luau and LuaJIT). +# 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: # 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 @@ -19,12 +21,24 @@ if [ -n "$bad" ]; then echo "lint: unknown globals (a local used before it is declared?)" fail=1 fi -ntype=$(echo "$report" | grep -c "Error:") -[ -n "$LINT_TYPES" ] && echo "$report" | grep -v "Unknown global" +types=$(echo "$report" | grep "Error:" | grep -v "Unknown global" | sed "s#^$PWD/#./#" | sort -u) +ntype=$(if [ -n "$types" ]; then echo "$types" | wc -l; else echo 0; fi) +[ -n "$LINT_TYPES" ] && echo "$types" +baseline=$(cat tools/lint_types_baseline.txt 2>/dev/null || echo 0) +if [ -n "$LINT_TYPES_UPDATE" ]; then + echo "$ntype" > tools/lint_types_baseline.txt + baseline=$ntype +fi +if [ "$ntype" -gt "$baseline" ]; then + echo "lint: $ntype type diagnostics, more than the baseline $baseline (tools/lint_types_baseline.txt); LINT_TYPES=1 lists them" + fail=1 +elif [ "$ntype" -lt "$baseline" ]; then + echo "lint: $ntype type diagnostics, below the baseline $baseline: lower it (LINT_TYPES_UPDATE=1 bash tools/lint.sh)" +fi python3 -I tools/lint_rules.py || { echo "lint: structure rules failed (see tools/lint_rules.py)"; fail=1; } python3 -I tools/gen_registry.py --check > /dev/null || { python3 -I tools/gen_registry.py --check; fail=1; } python3 -I tools/build.py --test > /dev/null || { echo "lint: tools/build.py --test failed"; fail=1; } if [ $fail -eq 0 ]; then - echo "lint passed (globals, header, require, native, layers, deps, contract, registry; $ntype type diagnostics: LINT_TYPES=1 shows them)" + echo "lint passed (globals, header, require, native, layers, deps, contract, registry; $ntype type diagnostics, baseline $baseline: LINT_TYPES=1 shows them)" fi exit $fail diff --git a/tools/lint_types_baseline.txt b/tools/lint_types_baseline.txt new file mode 100644 index 0000000..49541f7 --- /dev/null +++ b/tools/lint_types_baseline.txt @@ -0,0 +1 @@ +94