Skip to content

@typescript-eslint/prefer-regexp-exec#482

Open
ScriptedAlchemy wants to merge 8 commits intomainfrom
codex/ts-eslint-prefer-regexp-exec-e6c2
Open

@typescript-eslint/prefer-regexp-exec#482
ScriptedAlchemy wants to merge 8 commits intomainfrom
codex/ts-eslint-prefer-regexp-exec-e6c2

Conversation

@ScriptedAlchemy
Copy link
Contributor

Summary: Port @typescript-eslint/prefer-regexp-exec from ScriptedAlchemy#13.

Related Links:

Checklist:

  • Tests updated
  • Documentation updated (rule md)

@gemini-code-assist
Copy link

Summary of Changes

Hello @ScriptedAlchemy, 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 integrates the @typescript-eslint/prefer-regexp-exec rule into the linter. This rule aims to improve code quality and consistency by guiding developers to use the more appropriate RegExp#exec() method when performing regular expression matches that do not require global flags. The implementation includes robust detection logic and provides automated fixes, making it easier for users to adopt the recommended pattern.

Highlights

  • New Linting Rule: Introduced the @typescript-eslint/prefer-regexp-exec rule, which recommends using RegExp#exec() over String#match() for non-global regular expressions.
  • Automatic Fixes: The new rule includes auto-fix capabilities to automatically refactor String#match() calls to RegExp#exec() where applicable.
  • Comprehensive Testing: Added extensive unit and snapshot tests to ensure the new rule correctly identifies and fixes violations across various scenarios.
Changelog
  • internal/config/config.go
    • Imported the prefer_regexp_exec rule.
    • Registered the prefer_regexp_exec rule in the global rule registry.
  • internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec.go
    • Implemented the prefer-regexp-exec rule logic.
    • Defined helper functions for static argument analysis and regex flag detection.
    • Included logic for generating auto-fix replacements.
  • internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec.md
    • Added documentation for the prefer-regexp-exec rule.
    • Provided examples of correct and incorrect code usage.
  • internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec_test.go
    • Added unit tests for the prefer-regexp-exec rule, covering valid and invalid cases with auto-fix suggestions.
  • packages/rslint-test-tools/rstest.config.mts
    • Enabled the test suite for the prefer-regexp-exec rule.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/prefer-regexp-exec.test.ts.snap
    • Generated snapshot tests for the prefer-regexp-exec rule's diagnostics and auto-fix outputs.
  • rslint.json
    • Configured the prefer-regexp-exec rule, setting its default level to "off".
Activity
  • The @typescript-eslint/prefer-regexp-exec rule was ported from ScriptedAlchemy/rslint#13.
  • Tests have been updated to cover the new rule's functionality.
  • Documentation for the new rule has been added/updated.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a new TypeScript ESLint rule, @typescript-eslint/prefer-regexp-exec, which promotes the use of RegExp#exec() over String#match() for non-global regex matches. The changes include adding the rule's import and registration in internal/config/config.go, implementing the rule logic in internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec.go, documenting it in prefer_regexp_exec.md, and adding comprehensive tests in prefer_regexp_exec_test.go and its snapshot. The rstest.config.mts and rslint.json files are also updated to include the new rule and its test configuration. The implementation appears robust, handling various cases for string and RegExp arguments, and providing automatic fixes.

@ScriptedAlchemy ScriptedAlchemy marked this pull request as ready for review February 26, 2026 03:46
Copilot AI review requested due to automatic review settings February 26, 2026 03:46
@ScriptedAlchemy ScriptedAlchemy enabled auto-merge (squash) February 26, 2026 03:46
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

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: 0339c7bc89

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR ports the @typescript-eslint/prefer-regexp-exec rule from TypeScript ESLint to rslint. The rule suggests using RegExp#exec() instead of String#match() when performing non-global regex matches, as exec() is more performant and has consistent behavior.

Changes:

  • Implements the prefer-regexp-exec rule with comprehensive type checking and static analysis
  • Adds auto-fix functionality that converts String#match() calls to RegExp#exec()
  • Includes extensive test coverage matching the original TypeScript ESLint test suite

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec.go Core rule implementation with regex validation, type checking, and auto-fix logic
internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec_test.go Comprehensive test suite covering valid and invalid cases
internal/plugins/typescript/rules/prefer_regexp_exec/prefer_regexp_exec.md User-facing documentation with examples
internal/config/config.go Registers the new rule in the global rule registry
rslint.json Disables the rule for this codebase (set to "off")
packages/rslint-test-tools/rstest.config.mts Enables the test file in the test configuration
packages/rslint-test-tools/tests/typescript-eslint/rules/__snapshots__/prefer-regexp-exec.test.ts.snap Test snapshots verifying expected outputs
scripts/dictionary.txt Adds "dlclark" to the dictionary for the regexp2 package author

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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