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-useless-escape support v flag #17420

Merged
merged 4 commits into from Jul 28, 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-useless-escape 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 26, 2023 13:55
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jul 26, 2023
@netlify
Copy link

netlify bot commented Jul 26, 2023

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 672bd44
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/64c3069214045a0008f4e169

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, thanks! Would like @mdjermanovic to review before merging.

lib/rules/no-useless-escape.js Outdated Show resolved Hide resolved
lib/rules/no-useless-escape.js Outdated Show resolved Hide resolved
lib/rules/no-useless-escape.js Outdated Show resolved Hide resolved
lib/rules/no-useless-escape.js Show resolved Hide resolved
@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 27, 2023
@mdjermanovic
Copy link
Member

When the useless escape is an operand of -- or &&, the "escapeBackslash" suggestion is wrong and therefore shouldn't be offered.

For example:

/* eslint no-useless-escape: "error" */

/[\p{ASCII}--\.]/v;

After applying "Replace the \ with \\ to include the actual backslash character":

/* eslint no-useless-escape: "error" */

/[\p{ASCII}--\\.]/v; // parsing error

validateRegExp could pass an additional boolean argument to function report to exclude this suggestion.

@ota-meshi
Copy link
Member Author

Oh... Thank you for finding that issue. I didn't notice that.
Do you think it should be an auto-fix instead of a suggestion?

@mdjermanovic
Copy link
Member

Do you think it should be an auto-fix instead of a suggestion?

No, it still could be some other kind of mistake in writing the pattern that just happened to manifest as a useless escape, so it seems better to report the problem and let the user choose whether to apply the suggestion to remove \ or fix the pattern in another way. I'd just remove the other, invalid suggestion (in this special case only).

@mdjermanovic mdjermanovic mentioned this pull request Jul 27, 2023
19 tasks
@ota-meshi
Copy link
Member Author

I got it! Thank you for letting me know your thoughts. I will fix that.

@ota-meshi
Copy link
Member Author

I fixed that. Could you check it again?

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 1a2f966 into eslint:main Jul 28, 2023
22 checks passed
@ota-meshi ota-meshi deleted the no-useless-escape branch July 28, 2023 11:00
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jan 25, 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 25, 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