Skip to content
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

feat: no-regex-spaces support v flag #17407

Merged
merged 3 commits into from Jul 25, 2023

Conversation

ota-meshi
Copy link
Member

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[X] Changes an existing rule (template)

What changes did you make? (Give an overview)

Refs #17223

This PR modifies the no-regex-space rule and adds support for regexp v flag.

Is there anything you'd like reviewers to focus on?

@ota-meshi ota-meshi requested a review from a team as a code owner July 23, 2023 03:23
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jul 23, 2023
@netlify
Copy link

netlify bot commented Jul 23, 2023

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 28ca7f4
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/64bfb013037520000859e6a4
😎 Deploy Preview https://deploy-preview-17407--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mdjermanovic mdjermanovic mentioned this pull request Jul 23, 2023
19 tasks
@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion new syntax This issue is related to new syntax that has reached stage 4 contributor pool labels Jul 23, 2023
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Parsing with the v flag is significantly different, so the assumption that unknown flags don't include v could be problematic. For example, these patterns are parsable without the v flag, but the consecutive spaces don't end up being in character classes and are therefore reported (and even autofixed in the first case):

/* eslint no-regex-spaces: "error" */

function createRegexes(additionalFlags = "") {
    const flags = `${additionalFlags}v`;
    return [
        new RegExp("[[abc]  ]", flags), // false positive, autofixed to "[[abc] {2}]"
        new RegExp("[[abc]\\q{  }]", flags) // another false positive
    ]
}

I'm not sure if there is a good solution aside from ignoring RegExp constructor calls for which the flags cannot be determined.

@ota-meshi
Copy link
Member Author

Thank you for letting me know about that problem!
I changed this PR to ignore the check if the flag cannot be determined.

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Would like @mdjermanovic to verify before merging.

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdjermanovic mdjermanovic merged commit 3caf514 into eslint:main Jul 25, 2023
22 checks passed
@ota-meshi ota-meshi deleted the no-regex-spaces branch July 25, 2023 12:10
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jan 22, 2024
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion contributor pool feature This change adds a new feature to ESLint new syntax This issue is related to new syntax that has reached stage 4 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants