Skip to content

Add support for v flag to regexp/prefer-character-class #619

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

Merged
merged 2 commits into from
Oct 1, 2023

Conversation

RunDevelopment
Copy link
Collaborator

Related to #545

Changes:

  • What the title says.
  • Added unicode-set.ts util file for reserved punctuators.
  • Changed no-useless-character-class, no-useless-escape, and require-unicode-sets-regexp to use the new util file.

Some details about how I changed prefer-character-class:

  • This rule assumes that character elements are exactly one character long. So it's hard to add support for e.g. \q{abc}. So I restricted it to character elements that don't contain strings. So the rule won't combine e.g. [abc]|[\q{abc}] -> [abc\q{abc}]. I think support for this can be added in a follow-up PR.
  • Since the parsing with the v flag is stricter, I had to change elementsToCharacterClass (the function that creates the combined character class) to make more escapes. Those additional escapes apply to all regexes regardless of flags.

@changeset-bot
Copy link

changeset-bot bot commented Sep 26, 2023

🦋 Changeset detected

Latest commit: 2990bc5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-regexp Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you! I'm glad that the scattered code has been organized 😄

@ota-meshi ota-meshi merged commit 81f0153 into master Oct 1, 2023
@ota-meshi ota-meshi deleted the v-flag-prefer-character-class branch October 1, 2023 07:56
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