Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 1.82 KB

grapheme-string-literal.md

File metadata and controls

55 lines (36 loc) · 1.82 KB
pageClass sidebarDepth title description
rule-details
0
regexp/grapheme-string-literal
enforce single grapheme in string literal

regexp/grapheme-string-literal

enforce single grapheme in string literal

📖 Rule Details

This rule is aimed to clarify the difference between using a string literal and normal disjunctions by not using string literals for purposes other than expressing a single grapheme.

/* eslint regexp/grapheme-string-literal: "error" */

/* ✓ GOOD */
var foo = /[\p{RGI_Emoji}--\q{🇦🇨|🇦🇩|🇦🇪|🇦🇫|🇦🇬|🇦🇮|🇦🇱|🇦🇲|🇦🇴|🇦🇶|🇦🇷|🇦🇸|🇦🇹|🇦🇺|🇦🇼|🇦🇽|🇦🇿|🇧🇦|🇧🇧|🇧🇩|🇧🇪|🇧🇫|🇧🇬|🇧🇭|🇧🇮|🇧🇯}]/v
var foo = /[\q{a|b|c}]/v

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

This rule does not report empty string literals. Use regexp/no-empty-string-literal and regexp/no-empty-alternative if you want to check them.

🔧 Options

Nothing.

👫 Related rules

🚀 Version

This rule has not been released yet.

🔍 Implementation