Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 1.46 KB

prefer-set-operation.md

File metadata and controls

49 lines (32 loc) · 1.46 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/prefer-set-operation
prefer character class set operations instead of lookarounds
v2.0.0-next.9

regexp/prefer-set-operation

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

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

prefer character class set operations instead of lookarounds

📖 Rule Details

Regular expressions with the v flag have access to character class set operations (e.g. /[\s&&\p{ASCII}]/v, /[\w--\d]/v). These are more readable and performant than using lookarounds to achieve the same effect. For example, /(?!\d)\w/v is the same as /[\w--\d]/v.

/* eslint regexp/prefer-set-operation: "error" */

/* ✓ GOOD */
var foo = /(?!\d)\w/  // requires the v flag
var foo = /(?!\d)\w/u // requires the v flag

/* ✗ BAD */
var foo = /(?!\d)\w/v
var foo = /(?!\s)[\w\P{ASCII}]/v

🔧 Options

Nothing.

🚀 Version

This rule was introduced in eslint-plugin-regexp v2.0.0-next.9

🔍 Implementation