From 85903cd953aba1b26c22923e011e499fa4d9efa5 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:13:40 +0000 Subject: [PATCH] refactor(linter/plugins): add type assertions to ensure correctness of `TEST_CASE_PROP_KEYS_ARRAY` (#18450) AI review on #18445 caught a mistake (https://github.com/oxc-project/oxc/pull/18445#discussion_r2720807411). I'd neglected to add `"settings"` to `TEST_CASE_PROP_KEYS` when I added the field to the `TestCase` type. Add type constraints that prevent this mistake in future. --- apps/oxlint/src-js/package/rule_tester.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/oxlint/src-js/package/rule_tester.ts b/apps/oxlint/src-js/package/rule_tester.ts index bf4607535b1f5..3ea770fbb5c78 100644 --- a/apps/oxlint/src-js/package/rule_tester.ts +++ b/apps/oxlint/src-js/package/rule_tester.ts @@ -243,7 +243,8 @@ let sharedConfig: Config = {}; // List of keys that `ValidTestCase` or `InvalidTestCase` can have. // Must be kept in sync with properties of `ValidTestCase` and `InvalidTestCase` interfaces. -const TEST_CASE_PROP_KEYS = new Set([ +// The type constraints enforce this. +const TEST_CASE_PROP_KEYS_ARRAY = [ "code", "name", "only", @@ -256,7 +257,13 @@ const TEST_CASE_PROP_KEYS = new Set([ "errors", // Not a valid key for `TestCase` interface, but present here to prevent prototype pollution in `createConfigForRun` "__proto__", -]); +] as const satisfies readonly (TestCaseOwnKeys | "__proto__")[]; + +type TestCaseOwnKeys = Exclude; +type MissingKeys = Exclude; +type KeysSet = MissingKeys extends never ? Set : never; + +const TEST_CASE_PROP_KEYS: KeysSet = new Set(TEST_CASE_PROP_KEYS_ARRAY); /** * Test case.