Skip to content

fix(lint/prefer-optional-chain): ignore typeof guards on global references - #1142

Merged
camc314 merged 1 commit into
fix/lint-no-base-to-string-to-primitivefrom
fix/lint-prefer-optional-chain-global-typeof
Nov 29, 2026
Merged

camc314 merged 1 commit into
fix/lint-no-base-to-string-to-primitivefrom
fix/lint-prefer-optional-chain-global-typeof

Conversation

@camc314

@camc314 camc314 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Ports oxc-project/tsgolint#1392 to tsrs.

typeof x !== 'undefined' on a global (a lib global like window, a declare global var, or an undeclared name) checks whether the binding exists, not whether it is nullish. Optional chaining can't replace that check, because window?.document still throws a ReferenceError when window isn't defined:

typeof window !== 'undefined' && typeof window.document !== 'undefined';
// was fixed to: typeof window?.document !== 'undefined'

Treat a typeof X comparison with 'undefined' as an invalid operand when X is an identifier with no declaration in the linted file outside a declare global block, matching tsgolint c52fd036. This refreshes the rule baseline to that commit and adds the upstream cases.

Copilot AI balanced review requested due to automatic review settings November 29, 2026 16:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T18:55:54.196351Z 825ef8c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@camc314
camc314 force-pushed the fix/lint-prefer-optional-chain-global-typeof branch from 8e85df5 to 58b7c42 Compare November 29, 2026 16:56
@codspeed

codspeed Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 3.89%

Warning

oxc-project has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

2 warnings

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 1 benchmark with a significant change ran on different hardware

Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

❌ 1 regressed benchmark
✅ 7 untouched benchmarks
⏩ 8 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory drizzle-orm 97.1 MB 101 MB -3.89%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/lint-prefer-optional-chain-global-typeof (825ef8c) with fix/lint-no-base-to-string-to-primitive (66a3c8c)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@camc314
camc314 force-pushed the fix/lint-prefer-optional-chain-global-typeof branch from 58b7c42 to 1dfaa4d Compare November 29, 2026 17:24
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Performance change vs main

Workflow run · main 5784fadd39b2 → PR merge 30c597db023c (head 825ef8c041cf)

Clef gate: Clef estimated 16.9% default and single-threaded wall time, 11.6% peak RSS, 10.1% single-threaded instruction count impact probability.

Release builds in fast mode (TSRS_FAST=1) with Hyperfine 2 hardware counters. After warming each binary, alternating main/PR pairs measure wall time at both the fast preset's default checker count and with --singleThreaded, with ten pairs per configuration by default. Instructions come from the single-threaded runs; peak RSS comes from the default-count runs.
Incremental runs start with fresh build info before every invocation; check runs disable incremental compilation.

Project Mode Single-thread wall time Δ Single-thread instructions Δ Default wall time Δ Default peak RSS Δ
vscode check -0.2% +0.001% +0.3% 0.0%
vscode incremental +0.6% +0.001% +1.2% -0.1%
xstate-main check -1.5% 0.000% -1.5% -0.7%
xstate-main incremental +0.7% -0.001% -0.6% +0.8%
webpack check +0.1% +0.002% -1.4% -0.5%
webpack incremental 0.0% 0.000% -0.7% +0.2%
mui-docs check -0.5% -0.001% +4.8% +0.6%
mui-docs incremental -0.1% -0.001% +0.4% +0.1%
Compiler check +0.9% 0.000% -0.6% -1.2%
Compiler incremental +0.1% +0.001% -0.4% +0.2%
Compiler-Unions check +1.5% 0.000% -1.3% +1.5%
Compiler-Unions incremental -0.7% 0.000% -0.7% +0.2%
cal-diy check 0.0% +0.001% -0.5% +0.5%
cal-diy incremental +0.2% 0.000% -0.2% +0.2%
formbricks-web check -0.1% -0.002% -0.3% 0.0%
formbricks-web incremental +0.1% +0.002% +0.2% -0.1%
supabase-studio check +0.3% -0.001% -0.6% -0.2%
supabase-studio incremental +0.1% 0.000% +0.1% +0.2%
t3code-server check +0.3% +0.002% -1.2% -0.6%
t3code-server incremental +0.1% -0.003% 0.0% +0.1%
mikro-orm check 0.0% -0.001% -1.1% +0.6%
mikro-orm incremental -0.3% 0.000% -0.4% -0.1%
next-packages-next check -0.2% +0.001% -0.8% +0.2%
next-packages-next incremental -0.3% 0.000% -1.5% -0.1%
next-root check +0.2% -0.001% -0.1% -0.2%
next-root incremental 0.0% -0.001% +1.0% -0.1%
storybook check +0.2% -0.001% -0.4% +0.3%
storybook incremental +0.1% +0.004% -0.1% -0.2%
nuxt check -0.4% +0.002% 0.0% +0.2%
nuxt incremental -0.3% +0.001% +0.6% +0.2%
playwright check -0.1% 0.000% +1.3% +1.0%
playwright incremental 0.0% -0.001% -1.6% +0.3%
drizzle-orm check -0.5% +0.001% -3.7% -0.9%
drizzle-orm incremental -0.8% -0.003% -0.3% +0.2%
typeorm check -0.4% +0.001% -1.7% -0.1%
typeorm incremental -0.3% 0.000% -0.3% +0.5%
date-fns check +0.8% -0.003% -5.3% +0.8%
date-fns incremental -0.6% +0.017% -0.8% +0.2%
opencode-core check +0.1% -0.002% +8.8% +1.4%
opencode-core incremental -0.1% -0.004% +0.4% +0.2%
lobehub check +0.2% +0.001% -0.2% +0.1%
lobehub incremental -0.2% -0.003% -0.5% -0.1%
sentry check +0.2% -0.001% +0.5% -0.1%
sentry incremental 0.0% -0.001% -0.5% +0.1%

Negative means the PR used less; positive means it used more. Deltas are medians of paired PR/main ratios for wall time and instructions. Single-threaded runs reduce scheduling noise; shared CI machines can still add noise to wall time.

Measured medians (main → PR)
Project Mode Single-thread wall time (s) Single-thread instructions Default wall time (s) Default peak RSS (MiB)
vscode check 8.325 → 8.313 81,815,965,774.5 → 81,816,363,639.5 1.418 → 1.426 1802.1 → 1802.5
vscode incremental 8.433 → 8.492 84,217,315,003.5 → 84,218,017,579.5 1.631 → 1.644 2127.4 → 2125.0
xstate-main check 0.516 → 0.509 5,520,603,201.5 → 5,520,606,938.5 0.129 → 0.127 241.2 → 239.6
xstate-main incremental 0.530 → 0.533 5,679,446,752.5 → 5,679,367,027.5 0.160 → 0.158 240.2 → 242.0
webpack check 0.918 → 0.916 10,759,749,687.5 → 10,759,961,772.5 0.203 → 0.197 403.2 → 401.0
webpack incremental 0.945 → 0.946 10,980,199,678.5 → 10,980,253,397 0.239 → 0.238 398.8 → 399.8
mui-docs check 2.366 → 2.368 32,891,610,726.5 → 32,891,907,165.5 0.924 → 0.966 1177.5 → 1184.9
mui-docs incremental 2.574 → 2.573 34,221,204,484 → 34,220,654,005 1.127 → 1.128 1140.9 → 1141.6
Compiler check 0.151 → 0.151 1,745,223,351.5 → 1,745,212,496 0.072 → 0.072 77.3 → 76.4
Compiler incremental 0.142 → 0.143 1,759,516,866 → 1,759,524,862.5 0.066 → 0.065 78.4 → 78.6
Compiler-Unions check 0.198 → 0.201 3,014,341,074.5 → 3,014,345,003 0.095 → 0.093 79.8 → 81.0
Compiler-Unions incremental 0.195 → 0.191 3,026,975,889 → 3,026,954,668.5 0.090 → 0.089 83.6 → 83.8
cal-diy check 2.540 → 2.541 28,707,369,859.5 → 28,707,355,583 0.818 → 0.813 1332.2 → 1338.3
cal-diy incremental 2.728 → 2.732 30,307,702,713 → 30,307,465,062.5 1.045 → 1.037 1245.6 → 1247.6
formbricks-web check 3.409 → 3.409 36,892,342,793 → 36,891,697,710.5 0.892 → 0.888 1558.6 → 1558.0
formbricks-web incremental 3.496 → 3.496 39,474,762,253.5 → 39,475,594,440 1.066 → 1.068 1600.4 → 1598.4
supabase-studio check 3.852 → 3.867 40,539,441,269 → 40,538,800,910.5 0.980 → 0.978 1288.4 → 1286.4
supabase-studio incremental 4.185 → 4.181 43,471,297,782 → 43,470,161,054.5 1.137 → 1.145 1341.1 → 1343.8
t3code-server check 3.614 → 3.626 40,781,480,849.5 → 40,782,114,790 1.173 → 1.163 1305.1 → 1296.7
t3code-server incremental 3.593 → 3.589 41,291,859,132 → 41,289,843,445.5 1.389 → 1.393 1292.4 → 1293.9
mikro-orm check 3.980 → 3.986 44,047,337,968 → 44,047,293,346 0.831 → 0.822 1253.2 → 1260.4
mikro-orm incremental 4.042 → 4.027 44,356,367,089.5 → 44,356,517,822.5 0.935 → 0.938 1238.4 → 1236.9
next-packages-next check 1.483 → 1.479 17,277,897,932 → 17,278,050,008 0.373 → 0.371 551.5 → 552.4
next-packages-next incremental 1.498 → 1.494 17,589,104,399 → 17,589,202,878.5 0.439 → 0.436 555.7 → 555.3
next-root check 1.171 → 1.173 13,893,329,618 → 13,893,264,859 0.260 → 0.259 427.7 → 426.9
next-root incremental 1.204 → 1.206 14,350,192,006.5 → 14,350,287,976.5 0.306 → 0.309 467.6 → 467.3
storybook check 0.767 → 0.767 8,813,018,397 → 8,812,978,856 0.204 → 0.198 389.7 → 391.0
storybook incremental 0.799 → 0.799 9,132,330,140.5 → 9,132,789,672 0.242 → 0.241 368.3 → 367.7
nuxt check 0.828 → 0.824 8,428,718,557.5 → 8,429,032,509 0.213 → 0.212 384.4 → 385.1
nuxt incremental 0.921 → 0.920 8,824,813,748.5 → 8,824,855,070.5 0.251 → 0.256 383.7 → 384.3
playwright check 0.667 → 0.666 7,363,149,594.5 → 7,363,126,034 0.172 → 0.177 358.2 → 361.9
playwright incremental 0.701 → 0.701 7,539,520,396.5 → 7,539,444,383 0.200 → 0.197 336.6 → 337.5
drizzle-orm check 0.509 → 0.508 5,907,205,346.5 → 5,907,233,590.5 0.173 → 0.167 380.8 → 377.3
drizzle-orm incremental 0.530 → 0.527 6,076,010,815.5 → 6,075,925,272.5 0.176 → 0.175 339.2 → 340.0
typeorm check 0.580 → 0.579 6,344,414,306 → 6,344,436,372.5 0.135 → 0.132 224.6 → 224.3
typeorm incremental 0.635 → 0.640 6,728,568,813 → 6,728,648,156.5 0.165 → 0.163 230.4 → 231.5
date-fns check 0.266 → 0.269 3,297,320,510 → 3,297,293,309 0.084 → 0.080 149.8 → 150.9
date-fns incremental 0.307 → 0.305 3,529,892,022 → 3,530,607,604.5 0.102 → 0.103 161.7 → 162.0
opencode-core check 2.095 → 2.091 25,108,677,538.5 → 25,107,016,597 1.057 → 1.142 1182.3 → 1198.3
opencode-core incremental 2.150 → 2.146 25,469,131,761.5 → 25,468,170,134 1.070 → 1.073 1090.0 → 1091.9
lobehub check 16.635 → 16.658 185,330,872,084 → 185,338,513,479 5.550 → 5.558 4376.2 → 4381.4
lobehub incremental 16.686 → 16.651 188,910,181,033 → 188,905,085,888 6.829 → 6.782 4431.9 → 4429.6
sentry check 7.652 → 7.672 91,308,494,416.5 → 91,307,227,690.5 1.701 → 1.700 1753.1 → 1751.6
sentry incremental 7.941 → 7.935 93,275,969,844.5 → 93,270,988,957 2.079 → 2.070 1895.7 → 1896.9

tsrs-lint

Release tsrs-lint linting each project's source files with all 61 rules. After a warmup run of each binary, alternating main/PR pairs (10 per mode) measure wall time, CPU time and peak RSS with TSRS_FAST unset and with TSRS_FAST=1.

Project Mode Wall time Δ CPU time Δ Peak RSS Δ Diagnostics (main → PR)
webpack default -0.5% -0.1% +0.2% 35405, identical
webpack TSRS_FAST=1 +0.4% +0.9% 0.0% 35405, identical
drizzle-orm default -3.1% -1.5% -0.1% 7057 → 7055, 2 only on main, 0 only on PR
drizzle-orm TSRS_FAST=1 -1.8% -0.8% -0.2% 7057 → 7055, 2 only on main, 0 only on PR
xstate-main default +0.4% -1.2% -0.8% 6489, identical
xstate-main TSRS_FAST=1 -0.6% -1.6% -0.6% 6489, identical

Negative means the PR used less. Wall and CPU time deltas are medians of paired PR/main ratios; peak RSS compares medians.

Diagnostics differed (first few of each):

drizzle-orm (default):

  • main only: prefer-optional-chain drizzle-orm/src/sqlite-core/columns/blob.ts:1541 preferOptionalChain
  • main only: prefer-optional-chain drizzle-orm/src/sqlite-core/columns/blob.ts:3174 preferOptionalChain
    drizzle-orm (TSRS_FAST=1):
  • main only: prefer-optional-chain drizzle-orm/src/sqlite-core/columns/blob.ts:1541 preferOptionalChain
  • main only: prefer-optional-chain drizzle-orm/src/sqlite-core/columns/blob.ts:3174 preferOptionalChain
Measured lint medians (main → PR)
Project Mode Wall time (s) CPU time (s) Peak RSS (MiB)
webpack default 0.354 → 0.354 1.836 → 1.826 453.8 → 454.6
webpack TSRS_FAST=1 0.351 → 0.352 1.825 → 1.842 454.0 → 454.2
drizzle-orm default 0.221 → 0.213 1.173 → 1.157 393.5 → 393.1
drizzle-orm TSRS_FAST=1 0.219 → 0.214 1.173 → 1.160 393.8 → 392.9
xstate-main default 0.311 → 0.312 1.366 → 1.359 337.8 → 335.2
xstate-main TSRS_FAST=1 0.311 → 0.309 1.377 → 1.352 338.7 → 336.8

@camc314
camc314 force-pushed the fix/lint-prefer-optional-chain-global-typeof branch from 1dfaa4d to 825ef8c Compare November 29, 2026 18:54
@camc314
camc314 changed the base branch from main to fix/lint-no-base-to-string-to-primitive November 29, 2026 18:54
@camc314
camc314 added this pull request to stack #1148 November 29, 2026 18:54
@camc314
camc314 added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 78686aa Nov 29, 2026
76 checks passed
@camc314
camc314 deleted the fix/lint-prefer-optional-chain-global-typeof branch November 29, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants