-
Notifications
You must be signed in to change notification settings - Fork 19.8k
refactor(web): use RegExp.exec instead of string.match #30441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Replace string.match() with RegExp.exec() for better performance in cases where global flag is not needed. This follows the SonarQube rule S6594 recommendation. Changes: - web/utils/error-parser.ts - web/utils/urlValidation.ts - web/app/components/tools/mcp/modal.tsx - web/app/components/base/ga/index.tsx - web/app/components/base/mermaid/index.tsx - web/app/components/base/mermaid/utils.ts - web/app/components/base/date-and-time-picker/utils/dayjs.ts - web/app/components/app/configuration/index.tsx - web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx - web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx fixes langgenius#25199 Signed-off-by: majiayu000 <1835304752@qq.com>
Summary of ChangesHello @majiayu000, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the codebase by replacing instances of Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request successfully refactors string.match() to RegExp.exec() for better performance, as intended. The changes are correct and follow the SonarQube recommendation. I've added a few suggestions to further improve maintainability and code clarity by extracting repeated or inline regular expressions into constants and simplifying some of the match-handling logic. These changes also prevent regex re-compilation on every render, which aligns with the performance goals of this PR.
| // Extract offset from name format like "-11:00 Niue Time" or "+05:30 India Time" | ||
| // Name format is always "{offset}:{minutes} {timezone name}" | ||
| const offsetMatch = tzItem.name.match(/^([+-]?\d{1,2}):(\d{2})/) | ||
| const offsetMatch = /^([+-]?\d{1,2}):(\d{2})/.exec(tzItem.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
web/app/components/base/features/new-feature-panel/annotation-reply/index.tsx
Outdated
Show resolved
Hide resolved
web/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsx
Outdated
Show resolved
Hide resolved
| .map((line) => { | ||
| // Gantt charts have specific syntax needs. | ||
| const taskMatch = line.match(/^\s*([^:]+?)\s*:\s*(.*)/) | ||
| const taskMatch = /^\s*([^:]+?)\s*:\s*(.*)/.exec(line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| && !trimmedCode.includes('[object Object]') | ||
| && trimmedCode.split('\n').every(line => | ||
| !(line.includes('-->') && !line.match(/\S+\s*-->\s*\S+/))) | ||
| !(line.includes('-->') && !/\S+\s*-->\s*\S+/.test(line))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ech/param-config-content.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…reply/index.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
string.match()withRegExp.exec()for better performance in cases where global flag is not neededChanges
web/utils/error-parser.tsweb/utils/urlValidation.tsweb/app/components/tools/mcp/modal.tsxweb/app/components/base/ga/index.tsxweb/app/components/base/mermaid/index.tsxweb/app/components/base/mermaid/utils.ts(using.test()since only boolean check needed)web/app/components/base/date-and-time-picker/utils/dayjs.tsweb/app/components/app/configuration/index.tsxweb/app/components/base/features/new-feature-panel/text-to-speech/param-config-content.tsxweb/app/components/base/features/new-feature-panel/annotation-reply/index.tsxTest plan
pnpm test)pnpm type-check:tsgo)pnpm lint:fix)fixes #25199