Skip to content

fix(lint): resolve static values only from effectively-const variables - #1141

Merged
camc314 merged 1 commit into
fix/lint-prefer-optional-chain-global-typeoffrom
fix/lint-static-values-effectively-const
Nov 29, 2026
Merged

camc314 merged 1 commit into
fix/lint-prefer-optional-chain-global-typeoffrom
fix/lint-static-values-effectively-const

Conversation

@camc314

@camc314 camc314 commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Ports oxc-project/tsgolint#1391 to tsrs.

prefer-includes and prefer-string-starts-ends-with read the initializer of any variable, including one that is reassigned later. That gave false positives and fixes built from a stale value:

let pattern = /^a/;
pattern = /^b/;
pattern.test(s); // reported, and fixed to s.startsWith("a")

prefer-regexp-exec went the other way: it followed only const declarations, so it missed let bindings that are never reassigned.

Add utils::get_constant_variable_initializer, matching tsgolint b3c5445e, and use it in all three rules. It follows an initializer only when the variable has a single declaration in the same file, binds a plain identifier, and is either const or never written in that file. This refreshes the three rule baselines to that commit and adds the upstream cases. The prefer-regexp-exec headless fixture also gains the let mutable diagnostic that the Go oracle now reports in all four fix modes.

Validation: baselines for the three rules (83, 137 and 38 cases), the six prefer_includes/prefer_regexp_exec/prefer_string_starts_ends_with headless tests, cargo clippy -p tsrs_lint --all-targets with warnings denied, and tools/lint/source.mjs.

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

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:56:06.028283Z 192073d 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e31690ff39

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/tsrs_lint/src/utils.rs Resolved
@camc314
camc314 force-pushed the fix/lint-static-values-effectively-const branch from e31690f to f9ad784 Compare November 29, 2026 16:58
@codspeed

codspeed Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will improve performance by 3.14%

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.

1 warning

⚠️ 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 improved benchmark
✅ 7 untouched benchmarks
⏩ 8 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory webpack 86.1 MB 83.5 MB +3.14%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix/lint-static-values-effectively-const (192073d) with fix/lint-prefer-optional-chain-global-typeof (825ef8c)

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-static-values-effectively-const branch from f9ad784 to e80eb77 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 9add83a6c38d (head 192073d2f1c3)

Clef gate: Clef estimated 51.5% default and single-threaded wall time, 43.6% peak RSS, 70.9% 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.7% 0.0%
vscode incremental +0.4% +0.001% +0.1% +0.1%
xstate-main check +1.2% 0.000% -0.6% +0.8%
xstate-main incremental 0.0% 0.000% -1.7% +0.3%
webpack check +0.1% +0.001% -0.1% +0.1%
webpack incremental -0.4% +0.002% +0.1% -0.2%
mui-docs check -0.2% -0.003% -1.9% -0.8%
mui-docs incremental 0.0% 0.000% +0.3% +0.1%
Compiler check +0.8% 0.000% -1.2% +0.3%
Compiler incremental -0.5% +0.001% +0.5% -0.2%
Compiler-Unions check -1.2% 0.000% +0.8% +0.4%
Compiler-Unions incremental -0.2% 0.000% +1.6% 0.0%
cal-diy check -0.3% -0.004% +0.9% +0.7%
cal-diy incremental -0.4% -0.005% 0.0% -0.1%
formbricks-web check -0.5% 0.000% +0.3% +0.2%
formbricks-web incremental +0.4% 0.000% -0.3% 0.0%
supabase-studio check +0.1% -0.001% -1.3% -0.1%
supabase-studio incremental +0.1% +0.003% +0.1% +0.1%
t3code-server check +0.5% -0.002% +0.5% -0.3%
t3code-server incremental -0.9% +0.006% -0.7% -0.1%
mikro-orm check -0.6% 0.000% -0.9% -0.2%
mikro-orm incremental +0.1% 0.000% -0.8% +0.2%
next-packages-next check 0.0% 0.000% +0.1% 0.0%
next-packages-next incremental -0.6% 0.000% -0.4% 0.0%
next-root check +0.1% -0.001% +0.1% +0.1%
next-root incremental +0.1% 0.000% +0.2% -0.3%
storybook check +0.4% +0.001% -1.6% -0.1%
storybook incremental +0.1% -0.003% -0.1% -0.2%
nuxt check +0.1% +0.003% -0.6% -0.4%
nuxt incremental -0.6% 0.000% -1.1% +0.3%
playwright check -0.3% +0.001% -0.6% +0.7%
playwright incremental -0.8% -0.003% +1.6% +0.3%
drizzle-orm check +0.1% +0.002% -0.8% +1.0%
drizzle-orm incremental -0.6% +0.001% +0.1% -0.3%
typeorm check -0.9% -0.001% -2.0% -0.1%
typeorm incremental -0.1% -0.002% +3.0% -0.4%
date-fns check +0.9% -0.001% -4.6% +0.3%
date-fns incremental -0.7% -0.011% +0.2% +0.1%
opencode-core check -0.2% -0.006% -0.5% 0.0%
opencode-core incremental -0.5% +0.001% +0.2% 0.0%
lobehub check -0.1% +0.006% -0.2% +0.1%
lobehub incremental -0.2% -0.003% -0.3% 0.0%
sentry check +0.7% +0.003% -0.1% +0.3%
sentry incremental +0.6% -0.002% +0.8% +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.630 → 8.608 81,815,433,448.5 → 81,816,288,332 1.490 → 1.486 1804.7 → 1804.9
vscode incremental 8.467 → 8.496 84,217,270,600.5 → 84,217,269,837.5 1.638 → 1.641 2123.9 → 2125.1
xstate-main check 0.510 → 0.513 5,520,549,190.5 → 5,520,562,724.5 0.127 → 0.127 239.7 → 241.5
xstate-main incremental 0.523 → 0.524 5,679,490,254 → 5,679,461,961.5 0.161 → 0.158 241.3 → 242.0
webpack check 0.905 → 0.907 10,760,154,142.5 → 10,760,233,994.5 0.203 → 0.205 401.4 → 401.6
webpack incremental 0.942 → 0.941 10,980,150,180 → 10,980,394,063 0.237 → 0.242 399.6 → 398.7
mui-docs check 2.352 → 2.350 32,890,442,270 → 32,889,606,040.5 0.968 → 0.923 1194.1 → 1184.3
mui-docs incremental 2.594 → 2.594 34,223,065,423.5 → 34,221,460,962 1.131 → 1.139 1139.9 → 1140.6
Compiler check 0.140 → 0.140 1,745,225,835.5 → 1,745,223,001 0.065 → 0.066 77.2 → 77.4
Compiler incremental 0.140 → 0.139 1,759,513,904 → 1,759,528,102.5 0.064 → 0.064 78.5 → 78.4
Compiler-Unions check 0.208 → 0.206 3,014,356,967 → 3,014,352,210.5 0.101 → 0.101 79.7 → 80.0
Compiler-Unions incremental 0.194 → 0.194 3,026,964,115.5 → 3,026,958,393.5 0.091 → 0.092 83.8 → 83.8
cal-diy check 2.520 → 2.514 28,707,833,026 → 28,707,686,610.5 0.797 → 0.808 1337.5 → 1346.8
cal-diy incremental 2.689 → 2.683 30,308,590,940 → 30,307,261,595 1.012 → 1.011 1247.4 → 1246.6
formbricks-web check 3.347 → 3.338 36,891,950,876 → 36,891,609,859.5 0.863 → 0.866 1557.5 → 1560.7
formbricks-web incremental 3.507 → 3.523 39,476,310,461 → 39,474,271,204 1.060 → 1.061 1599.9 → 1599.8
supabase-studio check 3.577 → 3.578 40,540,324,784.5 → 40,540,303,637.5 0.901 → 0.893 1287.0 → 1286.3
supabase-studio incremental 3.855 → 3.865 43,469,725,067 → 43,471,433,067 1.050 → 1.053 1342.1 → 1343.6
t3code-server check 3.604 → 3.625 40,781,707,381 → 40,781,114,390 1.161 → 1.170 1299.5 → 1295.2
t3code-server incremental 3.571 → 3.543 41,289,035,566.5 → 41,291,113,869.5 1.395 → 1.381 1294.0 → 1293.1
mikro-orm check 3.986 → 3.962 44,046,762,321.5 → 44,046,546,636.5 0.834 → 0.828 1255.6 → 1253.1
mikro-orm incremental 4.037 → 4.031 44,356,535,915.5 → 44,356,901,117 0.948 → 0.944 1235.7 → 1237.8
next-packages-next check 1.440 → 1.442 17,277,957,203.5 → 17,277,886,000.5 0.361 → 0.361 552.8 → 552.9
next-packages-next incremental 1.477 → 1.469 17,589,241,954 → 17,589,156,329 0.436 → 0.430 556.1 → 556.0
next-root check 1.163 → 1.164 13,893,261,996 → 13,893,137,827.5 0.256 → 0.256 427.8 → 428.4
next-root incremental 1.239 → 1.238 14,350,170,430 → 14,350,133,052 0.318 → 0.318 468.1 → 467.0
storybook check 0.765 → 0.768 8,812,937,983 → 8,812,992,293 0.197 → 0.199 390.8 → 390.3
storybook incremental 0.813 → 0.814 9,132,525,687 → 9,132,039,177.5 0.248 → 0.252 368.9 → 368.3
nuxt check 0.806 → 0.807 8,428,781,084.5 → 8,429,050,216.5 0.206 → 0.206 385.8 → 384.1
nuxt incremental 0.874 → 0.870 8,824,992,502.5 → 8,824,916,883.5 0.236 → 0.235 384.5 → 385.6
playwright check 0.672 → 0.669 7,363,149,208.5 → 7,363,194,920 0.175 → 0.173 356.5 → 359.0
playwright incremental 0.689 → 0.684 7,539,545,550 → 7,539,485,880.5 0.193 → 0.197 336.8 → 337.8
drizzle-orm check 0.516 → 0.514 5,907,183,936 → 5,907,301,383.5 0.175 → 0.173 375.5 → 379.1
drizzle-orm incremental 0.551 → 0.547 6,075,966,598 → 6,075,950,528 0.185 → 0.186 340.6 → 339.6
typeorm check 0.598 → 0.592 6,344,432,026 → 6,344,342,134.5 0.135 → 0.131 224.8 → 224.6
typeorm incremental 0.640 → 0.642 6,728,676,444 → 6,728,634,404.5 0.175 → 0.181 230.3 → 229.5
date-fns check 0.272 → 0.275 3,297,276,438.5 → 3,297,202,050 0.087 → 0.084 149.8 → 150.3
date-fns incremental 0.306 → 0.304 3,530,718,235.5 → 3,530,656,025 0.102 → 0.101 161.6 → 161.8
opencode-core check 2.152 → 2.146 25,106,877,801.5 → 25,106,311,462 1.090 → 1.083 1184.2 → 1184.1
opencode-core incremental 2.294 → 2.288 25,468,297,852.5 → 25,468,562,161.5 1.165 → 1.168 1091.8 → 1091.5
lobehub check 16.530 → 16.529 185,332,312,941 → 185,351,640,734.5 5.495 → 5.485 4377.0 → 4380.5
lobehub incremental 16.980 → 16.943 188,899,820,966 → 188,892,491,919.5 6.957 → 6.918 4432.8 → 4431.4
sentry check 7.631 → 7.676 91,308,621,286 → 91,309,580,136.5 1.685 → 1.684 1748.6 → 1753.3
sentry incremental 7.861 → 7.899 93,270,684,471.5 → 93,271,265,613 2.046 → 2.063 1894.2 → 1895.3

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 -2.7% -1.3% -0.1% 35405, identical
webpack TSRS_FAST=1 0.0% +0.4% 0.0% 35405, identical
drizzle-orm default +0.1% +0.5% -0.1% 7057 → 7055, 2 only on main, 0 only on PR
drizzle-orm TSRS_FAST=1 -1.5% -1.9% -0.1% 7057 → 7055, 2 only on main, 0 only on PR
xstate-main default +0.4% +0.2% 0.0% 6489, identical
xstate-main TSRS_FAST=1 -0.2% 0.0% +0.1% 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.362 → 0.356 1.865 → 1.852 454.8 → 454.5
webpack TSRS_FAST=1 0.361 → 0.360 1.857 → 1.868 455.1 → 454.8
drizzle-orm default 0.217 → 0.218 1.164 → 1.176 393.2 → 392.8
drizzle-orm TSRS_FAST=1 0.220 → 0.216 1.177 → 1.161 392.9 → 392.4
xstate-main default 0.315 → 0.316 1.387 → 1.383 337.2 → 337.1
xstate-main TSRS_FAST=1 0.311 → 0.314 1.385 → 1.390 337.9 → 338.1

@camc314
camc314 force-pushed the fix/lint-static-values-effectively-const branch from e80eb77 to 192073d Compare November 29, 2026 18:54
@camc314
camc314 changed the base branch from main to fix/lint-prefer-optional-chain-global-typeof 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 2d48918 Nov 29, 2026
76 checks passed
@camc314
camc314 deleted the fix/lint-static-values-effectively-const 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