Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.37 KB

no-trivially-nested-quantifier.md

File metadata and controls

50 lines (33 loc) · 1.37 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-trivially-nested-quantifier
disallow nested quantifiers that can be rewritten as one quantifier
v0.9.0

regexp/no-trivially-nested-quantifier

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

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

disallow nested quantifiers that can be rewritten as one quantifier

📖 Rule Details

In some cases, nested quantifiers can be rewritten as one quantifier (e.g. (?:a{1,2}){3} -> a{3,6}).

/* eslint regexp/no-trivially-nested-quantifier: "error" */

/* ✓ GOOD */
var foo = /(a{1,2})+/;  // the rule won't touch capturing groups
var foo = /(?:a{2})+/;

/* ✗ BAD */
var foo = /(?:a{1,2})+/;
var foo = /(?:a{1,2}){3,4}/;
var foo = /(?:a{4,}){5}/;

🔧 Options

Nothing.

🚀 Version

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

🔍 Implementation