Skip to content

feat: port rule no-empty-character-class#527

Open
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-no-empty-character-class-20260317
Open

feat: port rule no-empty-character-class#527
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-no-empty-character-class-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the no-empty-character-class rule from ESLint to rslint.

Disallow empty character classes in regular expressions

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@fansenze fansenze mentioned this pull request Mar 17, 2026
2 tasks
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 introduces a new linting rule, no-empty-character-class, to the rslint project. This rule enhances code quality by identifying and preventing the use of empty character classes in regular expressions, which are typically unintentional errors. The implementation includes the core rule logic, comprehensive documentation, and dedicated test cases to ensure its correctness and reliability.

Highlights

  • New Linting Rule: Implemented the no-empty-character-class rule, ported from ESLint, to disallow empty character classes in regular expressions.
  • Regex Validation: The new rule helps prevent common mistakes in regular expressions by flagging [] which do not match anything, improving code quality.
Changelog
  • internal/config/config.go
    • Imported the no_empty_character_class rule.
    • Registered the no-empty-character-class rule in the global rule registry.
  • internal/rules/no_empty_character_class/no_empty_character_class.go
    • Added the NoEmptyCharacterClassRule definition.
    • Implemented extractPattern to parse regex patterns from literal strings.
    • Implemented hasEmptyCharacterClass using a state machine to detect empty character classes.
  • internal/rules/no_empty_character_class/no_empty_character_class.md
    • Created documentation for the no-empty-character-class rule, including rule details and examples of correct and incorrect code.
  • internal/rules/no_empty_character_class/no_empty_character_class_test.go
    • Added Go-based unit tests for the NoEmptyCharacterClassRule, covering valid and invalid regex patterns.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new no-empty-character-class.test.ts file.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/no-empty-character-class.test.ts.snap
    • Added snapshot test results for the no-empty-character-class rule's invalid cases.
  • packages/rslint-test-tools/tests/eslint/rules/no-empty-character-class.test.ts
    • Created a JavaScript-based rule tester file with valid and invalid test cases for the new rule.
Activity
  • The author has marked the tests and documentation as updated/not required in the PR checklist.
  • No other review comments or activity were found in the provided context.
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
Copy Markdown
Contributor

@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 successfully ports the no-empty-character-class rule from ESLint to rslint. The core logic for detecting empty character classes in regular expression literals (/pattern/) appears correct and handles escaped characters and negated classes ([^]) appropriately. The documentation and test files have been added and configured correctly. However, a significant functional gap exists as the rule currently does not process regular expressions created via new RegExp("pattern"), which is a common pattern in JavaScript and is covered by the original ESLint rule.

@fansenze fansenze force-pushed the feat/port-rule-no-empty-character-class-20260317 branch from 18bc1dd to 1ff3bd3 Compare March 17, 2026 10:29
@fansenze fansenze force-pushed the feat/port-rule-no-empty-character-class-20260317 branch 2 times, most recently from 96a494e to c2b85e0 Compare March 18, 2026 02:45
@fansenze fansenze force-pushed the feat/port-rule-no-empty-character-class-20260317 branch from c2b85e0 to 025efd9 Compare March 18, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant