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

regexp/no-dupe-disjunctions should "de-sugar" character classes #402

Closed
RunDevelopment opened this issue Mar 10, 2022 · 0 comments · Fixed by #404
Closed

regexp/no-dupe-disjunctions should "de-sugar" character classes #402

RunDevelopment opened this issue Mar 10, 2022 · 0 comments · Fixed by #404
Assignees
Labels
enhancement New feature or request

Comments

@RunDevelopment
Copy link
Collaborator

RunDevelopment commented Mar 10, 2022

Description
While writing some regexes, I noticed the regexp/no-dupe-disjunctions didn't say anything about a regex of this from:

/a+|[abc]/

The a in [abc] is clearly useless but didn't get reported. This is because regexp/no-dupe-disjunctions looks at the [abc] as a whole and only detects the overlap between a+ and [abc]. It doesn't understand that the overlap is really subset (with a in [abc]) and therefor you get this report with report: "all" even though the problem is trivial.


Some test cases:

// bad
var foo = /a+|[abc]/; // remove `a` in `[abc]`
var foo = /a+|a|b|c/; // remove `a` (this currently works)
var foo = /a+|[a-f]/; // change `a-f` to `b-f`

var foo = /a|[ab]a/; // remove `a` in `[ab]`
var foo = /a|aa|bb/; // remove `aa` (this currently works)

// ok
var foo = /c+|[a-f]/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant