From ee9f2f497088f5934de7188c30743b5333687106 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 5 Nov 2025 10:38:43 +0000 Subject: [PATCH] perf(linter/plugins): faster check for `cwd` (#15301) Follow-on after #14814. Small perf optimization. `cwd` is either `null` or a string, so use cheaper `=== null` check instead of `??` (which is equivalent to `cwd === null || cwd === undefined`). Also rename the var, just for brevity. --- apps/oxlint/src-js/plugins/context.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/oxlint/src-js/plugins/context.ts b/apps/oxlint/src-js/plugins/context.ts index a7cccc90826a2..a82e76be61ac7 100644 --- a/apps/oxlint/src-js/plugins/context.ts +++ b/apps/oxlint/src-js/plugins/context.ts @@ -86,7 +86,7 @@ export interface InternalContext { } // Cached current working directory. -let cachedCwd: string | null = null; +let cwd: string | null = null; /** * Context class. @@ -133,8 +133,9 @@ export class Context { // Getter for current working directory. get cwd() { - getInternal(this, 'access `context.cwd`'); - return (cachedCwd ??= process.cwd()); + // Note: We can allow accessing `cwd` in `createOnce`, as it's global. So skip `getInternal` call. + if (cwd === null) cwd = process.cwd(); + return cwd; } // Getter for options for file being linted.