ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.

Home Page:https://ota-meshi.github.io/eslint-plugin-regexp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

RunDevelopment opened this issue · comments

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]/;