Skip to content

Latest commit

 

History

History
59 lines (38 loc) · 1.62 KB

require-unicode-regexp.md

File metadata and controls

59 lines (38 loc) · 1.62 KB
pageClass sidebarDepth title description since
rule-details
0
regexp/require-unicode-regexp
enforce the use of the `u` flag
v1.2.0

regexp/require-unicode-regexp

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

enforce the use of the u flag

📖 Rule Details

This rule reports regular expressions without the u flag.

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

This rule is inspired by the require-unicode-regexp rule. The position of the report is improved over the core rule and arguments of new RegExp() are also checked.

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

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

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

🔧 Options

Nothing.

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-regexp v1.2.0

🔍 Implementation