From 3c4e0b21ad76a734731725cf16cdfb772aa69bbf Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Tue, 28 Jul 2026 20:40:58 +0530 Subject: chore: make the boundary scanner see every cast, not just the unsafe forms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scanner banned as any, as {, as unknown as, non-null assertions and ts-ignore, but said nothing about `as SomeNamedType` — so a new cast over CDP or JSON data could be added and CI would stay green, which is the exact regression the refactor exists to prevent. It also could not see a cast whose target type sits on the following line. Adds named-cast, function-cast and trailing-cast. All six surviving assertions in src/ are now visible to the scanner and individually exempted with a stated reason, so the allowlist is the complete inventory. Co-Authored-By: Claude Opus 5 (1M context) --- test/util/check-boundaries-test.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/util/check-boundaries-test.ts b/test/util/check-boundaries-test.ts index e3c2440..b42baa0 100644 --- a/test/util/check-boundaries-test.ts +++ b/test/util/check-boundaries-test.ts @@ -77,8 +77,24 @@ describe("boundary check", () => { assert.equal(checkSource([{ path: "a.ts", text: "const x = [1] as const;" }], noExemptions).length, 0); }); - test("allows a cast to a named type", () => { - assert.equal(checkSource([{ path: "a.ts", text: "return ok(raw as ResultOf);" }], noExemptions).length, 0); + test("flags a cast to a named type", () => { + const v = checkSource([{ path: "a.ts", text: "return ok(raw as ResultOf);" }], noExemptions); + assert.equal(v.some((x) => x.rule === "named-cast"), true); + }); + + test("flags a cast to a function type", () => { + const v = checkSource([{ path: "a.ts", text: "(fn as (a: unknown) => void)(x);" }], noExemptions); + assert.equal(v.some((x) => x.rule === "function-cast"), true); + }); + + test("flags a cast whose target type sits on the next line", () => { + const v = checkSource([{ path: "a.ts", text: "const f = base.constructor as\n new () => void;" }], noExemptions); + assert.equal(v.some((x) => x.rule === "trailing-cast"), true); + }); + + test("does not flag the word as inside prose", () => { + const text = 'const d = "Capture the page as a JPEG. DO NOT use as a default tool.";'; + assert.equal(checkSource([{ path: "a.ts", text }], noExemptions).length, 0); }); test("reports the 1-indexed line number and the trimmed text", () => { -- cgit v1.2.3