Repository navigation
fix(lint/prefer-regexp-exec): resolve RegExp copies and validate patterns with the TypeScript scanner - #1168
Conversation
There was a problem hiding this comment.
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.
Codex Review Summary: â CompletedThis comment shows the latest Codex review activity on this pull request.
âđïļ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with ð while any review is running, comments if it has suggestions, and reacts with ð once all reviews finish with no findings. |
There was a problem hiding this comment.
ðĄ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bccdb1a8d4
âđïļ 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".
| if !is_valid_reg_exp_literal(&(reg_exp_literal_from_pattern(pattern) + flags)) { | ||
| return StaticArgumentValue::Unknown; |
There was a problem hiding this comment.
Resolve
undefined before treating flags as absent
When undefined is shadowed, the new static evaluation can incorrectly classify a global regex as non-global. For example, in function f(undefined: string) { const re = new RegExp('a', undefined); return 'aa'.match(re); }, calling f('g') now produces a diagnostic and an autofix to re.exec('aa'), changing the result from two matches to one. Previously, the nonliteral flags left the initializer unknown and the alias was not reported. Only treat the identifier as absent flags after confirming that it refers to the global undefined, rather than checking its spelling alone.
Useful? React with ð / ð.
bccdb1a to
2f67573
Compare
Merging this PR will not alter performanceWarning 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
Comparing Footnotes
|
Performance change vs mainWorkflow run · main Clef gate: Running benchmarks because the decision was unavailable (crates/tsrs_lint/src/rules/prefer_regexp_exec.rs: patch exceeds the Clef context limit (31745 bytes)). 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.
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. |
âĶerns with the TypeScript scanner
2f67573 to
35b093c
Compare
Ports oxc-project/tsgolint#1420 (
baaf46bd), including its baseline update.This fixes three problems with
RegExpconstructor calls and string patterns:new RegExp(/a/g)copies thegflag from its argument, but the rule only read the flags argument, so it reporteds.match(new RegExp(/a/g))and the fix changed the result from all matches to the first. The static value of the constructor call now inherits flags from a static regex argument, and anundefinedflags argument counts as missing.(?i)a, so the fix could produce invalid code. Patterns are now validated with the TypeScript scanner's regular expression support. This removes the regexp2 pattern parser, its generated Unicode tables inregexp_unicode.rsand their generator,tools/tsgolint/gen-regexp-unicode.go.//, which starts a comment, and copied line terminators into the literal. Literals are now built like V8'sRegExp.prototype.toString: an empty pattern becomes(?:), and slashes outside character classes and line terminators are escaped.The headless
prefer_regexp_execfixtures are updated to match.