History

perf(schema): hoist Schema compilers and add lint rule

Schema.is, Schema.decode*, Schema.encode*, Schema.validate*, and Schema.parse* each compile a parser/guard from a schema. Calling them inside a function body rebuilds that function on every invocation. Adds executor/no-inline-schema-compile (oxlint plugin rule) that flags these calls when they appear inside a function body, with two severities: HIGH when the schema argument is itself an inline Schema.X(...) literal (both AST and compile rebuilt), MEDIUM when only the compiler is re-called. Fixes the 44 existing violations across 22 files by hoisting the compiled function (and where applicable, its schema literal) to module scope. Notable consolidations: - oauth-service.ts: 8 sites (5 decode + 3 encode of OAuthProviderState) collapse into two hoisted helpers - jwks-cache.ts, mcp-auth.ts: per-call guard compilation removed from JWT verify error path - React Add*Source / EditOpenApiSource components: shared decodeErrorMessage / isOpenApiSourceBindingValue hoisted migrate-connections.ts has one targeted oxlint-disable for a higher-order helper whose schema is a function parameter; the compile is hoisted into the outer closure but the rule (correctly) flags any Schema compiler call inside a function body.

Rhys Sullivan committed 6 months ago

Commit 25515e31 parent bfb87a025 files · +224 −99Browse files

Showing the changes to scripts/oxlint-plugin-executor.js (1 of 25 files). Show all

Unified · Split

scripts/oxlint-plugin-executor.js+2−0
@@ -5,6 +5,7 @@ import noEffectEscapeHatch from "./oxlint-plugin-executor/rules/no-effect-escape · 4 unmodified lines
5import noEffectInternalTags from "./oxlint-plugin-executor/rules/no-effect-internal-tags.js";5import noEffectInternalTags from "./oxlint-plugin-executor/rules/no-effect-internal-tags.js";
6import noErrorConstructor from "./oxlint-plugin-executor/rules/no-error-constructor.js";6import noErrorConstructor from "./oxlint-plugin-executor/rules/no-error-constructor.js";
7import noInlineObjectTypeAssertion from "./oxlint-plugin-executor/rules/no-inline-object-type-assertion.js";7import noInlineObjectTypeAssertion from "./oxlint-plugin-executor/rules/no-inline-object-type-assertion.js";
8import noInlineSchemaCompile from "./oxlint-plugin-executor/rules/no-inline-schema-compile.js";
8import noInstanceofError from "./oxlint-plugin-executor/rules/no-instanceof-error.js";9import noInstanceofError from "./oxlint-plugin-executor/rules/no-instanceof-error.js";
9import noInstanceofTaggedError from "./oxlint-plugin-executor/rules/no-instanceof-tagged-error.js";10import noInstanceofTaggedError from "./oxlint-plugin-executor/rules/no-instanceof-tagged-error.js";
10import noJsonParse from "./oxlint-plugin-executor/rules/no-json-parse.js";11import noJsonParse from "./oxlint-plugin-executor/rules/no-json-parse.js";
@@ -42,6 +43,7 @@ export default { · 31 unmodified lines
42 "no-error-constructor": noErrorConstructor,43 "no-error-constructor": noErrorConstructor,
43 "no-ts-nocheck": noTsNocheck,44 "no-ts-nocheck": noTsNocheck,
44 "no-inline-object-type-assertion": noInlineObjectTypeAssertion,45 "no-inline-object-type-assertion": noInlineObjectTypeAssertion,
46 "no-inline-schema-compile": noInlineSchemaCompile,
45 "no-instanceof-error": noInstanceofError,47 "no-instanceof-error": noInstanceofError,
46 "no-instanceof-tagged-error": noInstanceofTaggedError,48 "no-instanceof-tagged-error": noInstanceofTaggedError,
47 "no-json-parse": noJsonParse,49 "no-json-parse": noJsonParse,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t