Skip to content

Conversation

@s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Oct 29, 2025

This ESLint plugin provides linting rules relate to better ways to help you avoid problems when using RegExp.

The problem with polynomial regular expressions was mentioned in a couple of comments already:

This ESLint package includes a rule which checks for polynomial expressions. Beside that it also adds some performance improvements like using Non-Capturing groups in case the groups are not used. Or also using /d instead of 0-9

Review Notes

  1. The first commit adds the package and includes all the changes that were automatically made when running --fix
  2. The second commit includes all manual changes (either adding non-capturing groups, other modifications of ignnores)

When making manual changes, I tested the regex on https://regex101.com/ and although I don't have scientific benchmarks, I saw a huge improvement (steps and time reduced by half) in the performance note.

@s1gr1d s1gr1d requested review from a team as code owners October 29, 2025 13:46
@s1gr1d s1gr1d requested review from Lms24 and removed request for a team October 29, 2025 13:46
// Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
new RegExp('^(?:\\s*|/\\*(?:.|\\r|\\n)*?\\*/|//.*[\\n\\r])*(?:"[^"]*";?|\'[^\']*\';?)?');
// eslint-disable-next-line @sentry-internal/sdk/no-regexp-constructor,prefer-regex-literals
new RegExp('^(?:\\s|/\\*(?:.|[\\r\\n])*?\\*/|//.*[\\n\\r])*(?:"[^"]*";?|\'[^\']*\';?)?');
Copy link

Choose a reason for hiding this comment

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

Bug: Regex Pattern Error: Incorrectly Handles Whitespace

The regex pattern incorrectly removed the * quantifier from \s*. The original pattern ^\s* (zero or more whitespace) was changed to ^\s (exactly one whitespace), which fundamentally changes the regex semantics. The pattern should be ^(?:\s|/\*(?:.|[\r\n])*?\*\/|//.*[\n\r])* not ^(?:\\s|/\*(?:.|[\r\n])*?\*\/|//.*[\n\r])* to maintain backward compatibility. This breaks the directive-matching logic that needs to handle cases with no leading whitespace.

Fix in Cursor Fix in Web

@s1gr1d s1gr1d requested a review from JPeer264 October 29, 2025 13:53
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.64 kB -0.02% -3 B 🔽
@sentry/browser - with treeshaking flags 23.12 kB -0.03% -5 B 🔽
@sentry/browser (incl. Tracing) 40.98 kB -0.01% -4 B 🔽
@sentry/browser (incl. Tracing, Profiling) 45.26 kB -0.02% -6 B 🔽
@sentry/browser (incl. Tracing, Replay) 79.32 kB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.02 kB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay with Canvas) 84.03 kB -0.01% -5 B 🔽
@sentry/browser (incl. Tracing, Replay, Feedback) 96.2 kB -0.01% -3 B 🔽
@sentry/browser (incl. Feedback) 41.31 kB -0.02% -5 B 🔽
@sentry/browser (incl. sendFeedback) 29.31 kB -0.02% -5 B 🔽
@sentry/browser (incl. FeedbackAsync) 34.23 kB -0.02% -6 B 🔽
@sentry/react 26.32 kB -0.02% -5 B 🔽
@sentry/react (incl. Tracing) 42.97 kB -0.01% -4 B 🔽
@sentry/vue 29.12 kB -0.04% -11 B 🔽
@sentry/vue (incl. Tracing) 42.77 kB -0.05% -20 B 🔽
@sentry/svelte 24.64 kB -0.03% -5 B 🔽
CDN Bundle 26.89 kB -0.05% -11 B 🔽
CDN Bundle (incl. Tracing) 41.62 kB -0.03% -11 B 🔽
CDN Bundle (incl. Tracing, Replay) 77.9 kB -0.01% -6 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) 83.38 kB -0.01% -7 B 🔽
CDN Bundle - uncompressed 78.83 kB -0.08% -59 B 🔽
CDN Bundle (incl. Tracing) - uncompressed 123.41 kB -0.05% -59 B 🔽
CDN Bundle (incl. Tracing, Replay) - uncompressed 238.63 kB -0.03% -59 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 251.39 kB -0.03% -59 B 🔽
@sentry/nextjs (client) 45.11 kB -0.03% -10 B 🔽
@sentry/sveltekit (client) 41.4 kB -0.02% -6 B 🔽
@sentry/node-core 50.81 kB -0.01% -3 B 🔽
@sentry/node 157.86 kB -0.02% -22 B 🔽
@sentry/node - without tracing 92.68 kB -0.02% -10 B 🔽
@sentry/aws-serverless 106.41 kB -0.02% -11 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,758 - 8,934 -2%
GET With Sentry 1,315 15% 1,387 -5%
GET With Sentry (error only) 5,935 68% 6,232 -5%
POST Baseline 1,168 - 1,217 -4%
POST With Sentry 500 43% 528 -5%
POST With Sentry (error only) 1,052 90% 1,072 -2%
MYSQL Baseline 3,292 - 3,382 -3%
MYSQL With Sentry 466 14% 492 -5%
MYSQL With Sentry (error only) 2,698 82% 2,790 -3%

View base workflow run

@s1gr1d
Copy link
Member Author

s1gr1d commented Oct 31, 2025

Closes in favor of separating this into two PRs, which apply those rules once only for dev-packages and once for the whole project.

#18063

@s1gr1d s1gr1d closed this Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants