ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.

Home Page:https://ota-meshi.github.io/eslint-plugin-regexp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Force one grapheme in the disjunction of string literals

ota-meshi opened this issue ยท comments

Motivation

It may be useful to be able to force the disjunction of string literals to use only strings that humans recognize as single characters.

Description

It is possible to use strings of two or more characters in the disjunction of string literals, but normal disjunction is also possible. (However, there are differences in the evaluation order.)
Forcing a single character to be used in the disjunction of string literals allows people to distinguish between uses.

I think it is better to implement the rule by using Intl.Segmenter and allowing it if it is recognized as one grapheme.

Examples

/* โœ“ GOOD */
var foo = /[\p{RGI_Emoji}--\q{๐Ÿ‡ฆ๐Ÿ‡จ|๐Ÿ‡ฆ๐Ÿ‡ฉ|๐Ÿ‡ฆ๐Ÿ‡ช|๐Ÿ‡ฆ๐Ÿ‡ซ|๐Ÿ‡ฆ๐Ÿ‡ฌ|๐Ÿ‡ฆ๐Ÿ‡ฎ|๐Ÿ‡ฆ๐Ÿ‡ฑ|๐Ÿ‡ฆ๐Ÿ‡ฒ|๐Ÿ‡ฆ๐Ÿ‡ด|๐Ÿ‡ฆ๐Ÿ‡ถ|๐Ÿ‡ฆ๐Ÿ‡ท|๐Ÿ‡ฆ๐Ÿ‡ธ|๐Ÿ‡ฆ๐Ÿ‡น|๐Ÿ‡ฆ๐Ÿ‡บ|๐Ÿ‡ฆ๐Ÿ‡ผ|๐Ÿ‡ฆ๐Ÿ‡ฝ|๐Ÿ‡ฆ๐Ÿ‡ฟ|๐Ÿ‡ง๐Ÿ‡ฆ|๐Ÿ‡ง๐Ÿ‡ง|๐Ÿ‡ง๐Ÿ‡ฉ|๐Ÿ‡ง๐Ÿ‡ช|๐Ÿ‡ง๐Ÿ‡ซ|๐Ÿ‡ง๐Ÿ‡ฌ|๐Ÿ‡ง๐Ÿ‡ญ|๐Ÿ‡ง๐Ÿ‡ฎ|๐Ÿ‡ง๐Ÿ‡ฏ}]/v

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