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

Applying fix for regexp/optimal-quantifier-concatenation break the regex logic

Eugeno opened this issue · comments

Information:

  • ESLint version: 8.57.0
  • eslint-plugin-regexp version: 2.5.0

Description
Current regex is /^(?!.*(?=.*-)(?=.*,)).*$/ (disallow usage of both comma and dash).

/^(?!.*(?=.*-)(?=.*,)).*$/.test('1,2-3'); // false ✓

I got 3 errors here, one of them: '.*' can be removed because it is already included by '.*'.(regexp/optimal-quantifier-concatenation).
After applying the fix:

/^(?!.*(?=-)(?=.*,)).*$/.test('1,2-3'); // true ✗

Further autofixes give the same false positive result:

/^(?!.*(?=-).+,).*$/.test('1,2-3'); // true ✗

Very good fine. Thanks for reporting.

The transformation:

/^(?!.*(?=.*-)(?=.*,)).*$/;
// to
/^(?!.*(?=-)(?=.*,)).*$/;

Is indeed incorrect. I think I messed one of its conditions, so this shouldn't be too hard to fix.