Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 1.39 KB

prefer-predefined-assertion.md

File metadata and controls

51 lines (33 loc) · 1.39 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/prefer-predefined-assertion
prefer predefined assertion over equivalent lookarounds
v0.10.0

regexp/prefer-predefined-assertion

💼 This rule is enabled in the ✅ plugin:regexp/recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

prefer predefined assertion over equivalent lookarounds

📖 Rule Details

All predefined assertions (\b, \B, ^, and $) can be expressed as lookaheads and lookbehinds. E.g. /a$/ is the same as /a(?![^])/.

In most cases, it's better to use the predefined assertions because they are better known.

/* eslint regexp/prefer-predefined-assertion: "error" */

/* ✓ GOOD */
var foo = /a(?=\W)/;

/* ✗ BAD */
var foo = /a(?![^])/;
var foo = /a(?!\w)/;
var foo = /a+(?!\w)(?:\s|bc+)+/;

🔧 Options

Nothing.

🚀 Version

This rule was introduced in eslint-plugin-regexp v0.10.0

🔍 Implementation