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

New rule: `no-useless-lookaround-assertions`

ota-meshi opened this issue · comments

Motivation

We can define unnecessary lookaround assertions within lookaround assertions, so I would like a rule to report this and fix it automatically.

'JavaScript'.replace(/Java(?=Scrip(?=t))/u, 'Type');
'JavaScript'.replace(/(?<=(?<=J)ava)Script/u, '');

Description

New rule report unnecessary lookaround assertions within lookaround assertions.

Examples

/* ✗ BAD */
'JavaScript'.replace(/Java(?=Scrip(?=t))/u, 'Type');
'JavaScript'.replace(/(?<=(?<=J)ava)Script/u, '');

/* ✓ GOOD */
'JavaScript'.replace(/Java(?=Script)/u, 'Type');
'JavaScript'.replace(/(?<=Java)Script/u, '');