Skip to content

@typescript-eslint/prefer-includes#483

Open
ScriptedAlchemy wants to merge 14 commits intomainfrom
codex/ts-eslint-prefer-includes-e14e
Open

@typescript-eslint/prefer-includes#483
ScriptedAlchemy wants to merge 14 commits intomainfrom
codex/ts-eslint-prefer-includes-e14e

Conversation

@ScriptedAlchemy
Copy link
Contributor

Summary: Port @typescript-eslint/prefer-includes 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-includes rule into the linter. This rule aims to enhance code readability and maintainability by promoting the use of the includes() method over less explicit indexOf comparisons or RegExp.prototype.test() calls. By standardizing these checks, the change helps developers write cleaner and more understandable JavaScript/TypeScript code.

Highlights

  • New TypeScript ESLint Rule Added: Introduced the @typescript-eslint/prefer-includes rule, which encourages the use of Array.prototype.includes() or String.prototype.includes() for better readability and intent clarity.
  • Improved Code Readability: The new rule identifies and provides auto-fixes for common patterns like indexOf(...) !== -1 or RegExp.prototype.test() that can be simplified using includes().
  • Comprehensive Testing and Documentation: The rule comes with dedicated unit tests covering various scenarios and detailed Markdown documentation explaining its purpose, incorrect examples, and correct usage.
Changelog
  • internal/config/config.go
    • Imported the new prefer_includes rule module.
    • Registered the @typescript-eslint/prefer-includes rule within the global rule registry.
  • internal/plugins/typescript/rules/prefer_includes/prefer_includes.go
    • Added the core implementation for the prefer-includes rule.
    • Implemented logic to detect indexOf comparisons (e.g., !== -1, === -1) and RegExp.prototype.test() calls.
    • Included helper functions for parsing regular expressions, escaping strings, and checking node types.
    • Provided auto-fixing capabilities to transform identified patterns into includes() calls.
  • internal/plugins/typescript/rules/prefer_includes/prefer_includes.md
    • Added documentation for the prefer-includes rule.
    • Provided examples of both incorrect and correct code usage for the rule.
  • internal/plugins/typescript/rules/prefer_includes/prefer_includes_test.go
    • Added unit tests for the prefer-includes rule.
    • Included test cases for valid code that should not trigger the rule.
    • Provided test cases for invalid code, demonstrating how the rule identifies issues and applies auto-fixes.
  • packages/rslint-test-tools/rstest.config.mts
    • Enabled the prefer-includes.test.ts file in the test configuration to ensure the new rule's tests are run.
  • packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/prefer-includes.test.ts.snap
    • Added snapshot test results for the prefer-includes rule, capturing expected diagnostics and output for various invalid code scenarios.
  • rslint.json
    • Added the @typescript-eslint/prefer-includes rule to the default configuration, initially setting its status to 'off'.
Activity
  • The author has updated tests to cover the new rule's functionality.
  • Documentation for the new rule has been updated (rule md).
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 ports the @typescript-eslint/prefer-includes rule to the Go-based linter. The implementation correctly identifies indexOf comparisons and /regex/.test(str) calls that can be replaced with includes(). However, I identified a few critical issues in the auto-fix logic: specifically, incorrect range calculations when parentheses are present in indexOf checks, and an incorrect order of fix applications in the regex conversion logic. I also suggested adding a missing nil check for the type checker and improving numeric literal parsing to support non-decimal formats.

@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
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 pull request ports the @typescript-eslint/prefer-includes rule from the ScriptedAlchemy/rslint repository. The rule encourages the use of includes() method instead of indexOf() comparisons (like indexOf() !== -1), and also suggests using String#includes() instead of simple regex patterns with .test() when appropriate. This leads to more readable and expressive code.

Changes:

  • Implemented the prefer-includes rule in Go with comprehensive type checking and auto-fix capabilities
  • Added test coverage in both TypeScript and Go test files with multiple edge cases
  • Enabled the rule in test configuration and registered it in the global rule registry

Reviewed changes

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

Show a summary per file
File Description
rslint.json Added rule configuration (set to "off" by default)
packages/rslint-test-tools/tests/typescript-eslint/rules/prefer-includes.test.ts Added valid and invalid test cases including edge cases for optional chaining, regex patterns, and type arrays
packages/rslint-test-tools/tests/typescript-eslint/rules/snapshots/prefer-includes.test.ts.snap New snapshot file containing expected diagnostic outputs for all test cases
packages/rslint-test-tools/rstest.config.mts Enabled the prefer-includes test file in test configuration
internal/plugins/typescript/rules/prefer_includes/prefer_includes_test.go Go test implementation with key test cases
internal/plugins/typescript/rules/prefer_includes/prefer_includes.md Documentation explaining the rule with examples
internal/plugins/typescript/rules/prefer_includes/prefer_includes.go Core implementation with logic for detecting indexOf comparisons and regex patterns, including auto-fix generation
internal/config/config.go Imported and registered the new rule in the global rule registry

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

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: ed912357d6

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

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