Skip to content

Latest commit

 

History

History
69 lines (45 loc) · 1.9 KB

require-unicode-sets-regexp.md

File metadata and controls

69 lines (45 loc) · 1.9 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/require-unicode-sets-regexp
enforce the use of the `v` flag
v2.0.0-next.7

regexp/require-unicode-sets-regexp

🔧 This rule is automatically fixable by the --fix CLI option.

enforce the use of the v flag

📖 Rule Details

This rule reports regular expressions without the v flag.

It will automatically replace the v flag to regular expressions where it is already uses the 'u' flag and statically guaranteed to be safe to do so. In all other cases, the developer has to check that adding the v flag doesn't cause the regex to behave incorrectly.

If you want to automatically add the v flag to legacy regular expressions that don't use the u flag, use them together with the regexp/require-unicode-regexp rule.

/* eslint regexp/require-unicode-sets-regexp: "error" */

/* ✓ GOOD */
var foo = /foo/v;
var foo = /a\s+b/v;

/* ✗ BAD */
var foo = /foo/;
var foo = RegExp("a\\s+b");
var foo = /[a-z]/i;
var foo = /\S/;
var foo = /foo/u;
var foo = RegExp("a\\s+b", 'u');
var foo = /[a-z]/iu;
var foo = /\S/u;

🔧 Options

Nothing.

👫 Related rules

📚 Further reading

🚀 Version

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

🔍 Implementation