ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.
https://ota-meshi.github.io/eslint-plugin-regexp/
MIT License
699 stars 10 forks source link

Report sequences unescaped for v flag (even if using the u or earlier flags) #762

Open brettz9 opened 2 months ago

brettz9 commented 2 months ago

Motivation

require-unicode-regexp in ESLint now supports a requireFlag option to require the v flag (as your plugin already does). However, if one is stuck in environments that don't support the v flag, one may end up writing regexes for the u flag which are difficult to refactor later for the v flag if that code doesn't do the proper escaping expected by the v flag.

Description

It would be nice to have a rule which prohibited characters which were unescaped as far as would be valid for the v flag (even if the u flag were in use).

Examples

/* ✓ GOOD */
var foo = /[\[a]/u;

/* ✗ BAD */
var foo = /[[a]/u; // Technically ok, but will be invalid when switching to `v` flag