require-unicode-regexp

在 RegExp 上强制使用 u 标志

RegExp u 标志有两个作用:

  1. 使正则表达式正确处理 UTF-16 代理对。

    特别是,字符范围语法得到了正确的行为。

    /^[👍]$/.test("👍") //→ false
    /^[👍]$/u.test("👍") //→ true
    
  2. 使正则表达式在禁用 附件 B 扩展 时尽早抛出语法错误。

    fR1Mfp3/WlJci8Yq9ftnGzBJkg4mNrqLyR7oRkEMa2Mjc3K58cd1HK9TRTlEqA+BLK+BCM2x10LECo1Vqizt8oSavG/9B+4iu9v48yE/Dwc3dfT/8ODw/Au/IoZ0ibr5yleeCft1PsowJUAzyfV2LRIVqSklzzwYIrwreDEwhb3fIBDV4yfO0gH4cAFE5b3332GPnEpeF7c6+TVh8QeqKnWZE98UsC2BFelXvg8gdqHgcIhjrsRnk6OgK6mC8fCfrsX0+f2rRv0crGuvZ7vxNZgUi3QguevwowRzMI3migoDrow3Ny7b5ImowOeemYb7+05+7m01J4P7qz//BipxsI+h/zApyElAc5GpFgMkgqwWzSdRYhYOAg1cQ1x8JSiZ

    Q3qkz+0oMLKEK60A11534qyzHZ4sdKmq7FhO9aBMDDgABb+bRSEb7bIYkLMRJPHixx3VCxC5KiCIRxNxU+yqoU8GW9/6AZ2mg1vdOITW/a6Z1uKygkbVNQQS1ceAvVMkyP5lgUVkSZ5TP/DcMAfFA657PMUe8SYXiD1KxDJEtfrBe/1TgVQsahX3S/LZPGSMJRQGL7goHFSZNngkT4yoaSmHTQIV5yBGOkgwILVxz3iwz4nPOrE79mt0HFEK2N38

0cFLLCqIhBgE2lsKuOTD4RiWk2yW+43fPoqP1m6Til70Z2saf5GTGruSUoAyLaLHlAQiAWVgIXIxPyyR0sE+o/Hvs2sJUq3bnCYx123nPEc=

规则详情

Fgsu6tS5naQ0iqS4FiAK21/WZ4XeiJY7jOoUKIZf9psDSyfDLKaUaqohIcNu5MYsABxvW9Yl/7ojli2bJowyzz3lpjqxKDKfTg7pQUdSu/A=

53qbJC6xNcTpfWzDOxH3FbxQniXPcALMzc0838bz9bxwfaPpKG0ZV7pRGyxgA1aA

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

const a = /aaa/
const b = /bbb/gi
const c = new RegExp("ccc")
const d = new RegExp("ddd", "gi")

x8vS/D2xVZSiiHLs1PwUl6/TVEXV0uticb8dGcMm9rxiwxh8yRqnjwkHP0i+2Pam

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

const a = /aaa/u
const b = /bbb/giu
const c = new RegExp("ccc", "u")
const d = new RegExp("ddd", "giu")

// This rule ignores RegExp calls if the flags could not be evaluated to a static value.
function f(flags) {
    return new RegExp("eee", flags)
}

何时不使用

QjS6Zycbp5hb8/TfUdenytQ8iEKEmBae6MtbEORUnQ/jsWcJQNg6l+LueNVsZMHyP0cLiVE3Ml9kQFgf091TDvmbCPhOL4io2HElSNZhR4kkwzLYsvEe2LRYAKG5xRBiHwFX0AT9mm1/NQ7tLdhPkQ==