Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.55 KB

no-empty-alternative.md

File metadata and controls

58 lines (39 loc) · 1.55 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-empty-alternative
disallow alternatives without elements
v0.8.0

regexp/no-empty-alternative

⚠️ This rule warns in the ✅ plugin:regexp/recommended config.

disallow alternatives without elements

📖 Rule Details

While (re-)writing long regular expressions, it can happen that one forgets to remove the | character of a former alternative. This rule tries to point out these potential mistakes by reporting all empty alternatives.

/* eslint regexp/no-empty-alternative: "error" */

/* ✓ GOOD */
var foo = /(?:)/
var foo = /a+|b*/

/* ✗ BAD */
var foo = /a+|b+|/
var foo = /\|\||\|||\|\|\|/
var foo = /a(?:a|bc|def|h||ij|k)/

🔧 Options

Nothing.

❤️ Compatibility

This rule was taken from eslint-plugin-clean-regex.
This rule is compatible with clean-regex/no-empty-alternative rule.

🚀 Version

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

🔍 Implementation