Skip to content

Add regexp/grapheme-string-literal rule #646

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 5 commits into from
Oct 7, 2023

Conversation

ota-meshi
Copy link
Owner

close #644

@changeset-bot
Copy link

changeset-bot bot commented Oct 4, 2023

🦋 Changeset detected

Latest commit: 331159a

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

@RunDevelopment
Copy link
Collaborator

Same problem as #642.

Comment on lines 179 to 182
code: String.raw`/[\q{abc}]/v`,
errors: [
{
message: "Use single grapheme in string literal.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error message needs to be improved. If I didn't read the docs for the rule, I would have no idea what the error message wants me to do.

Maybe we could say this: "Only single characters and graphemes are allowed inside character classes. Use regular alternatives (e.g. (?:foo|[...])) for strings instead."

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you! I will use that message.

meta: {
docs: {
description: "enforce single grapheme in string literal",
category: "Best Practices",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure whether this should be a best practice. The practice this rule enforces is good, because it brings regexes into a canonical form (e.g. don't use [\q{foo|bar}], use (?:foo|bar)), but that's more of a stylistic thing IMO.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I agree with you 👍 I will categorize it under "Stylistic Issues".

@RunDevelopment RunDevelopment merged commit c01e6a6 into master Oct 7, 2023
@RunDevelopment RunDevelopment deleted the grapheme-string-literal branch October 7, 2023 09:31
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.

Force one grapheme in the disjunction of string literals
2 participants