Skip to content

Latest commit

 

History

History
60 lines (39 loc) · 1.53 KB

no-empty-string-literal.md

File metadata and controls

60 lines (39 loc) · 1.53 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/no-empty-string-literal
disallow empty string literals in character classes
v2.0.0-next.11

regexp/no-empty-string-literal

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

disallow empty string literals in character classes

📖 Rule Details

This rule reports empty string literals in character classes.

If the empty string literal is supposed to match the empty string, then use a quantifier instead. For example, [ab\q{}] should be written as [ab]?.

This rule does not report empty alternatives in string literals. (e.g. /[\q{a|}]/v)
If you want to report empty alternatives in string literals, use the regexp/no-empty-alternative rule.

/* eslint regexp/no-empty-string-literal: "error" */

/* ✓ GOOD */
var foo = /[\q{a}]/v;
var foo = /[\q{abc}]/v;
var foo = /[\q{a|}]/v;

/* ✗ BAD */
var foo = /[\q{}]/v;
var foo = /[\q{|}]/v;

🔧 Options

Nothing.

👫 Related rules

🚀 Version

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

🔍 Implementation