Versions

wrap-regex

Require parenthesis around regex literals

🔧 Fixable

Some problems reported by this rule are automatically fixable by the --fix command line option

当正则表达式在某些情况下被使用时,它可能最终看起来像一个除法运算符。比如:

function a() {
    return /foo/.test("bar");
}

规则细节

这用于消除斜线运算符的歧义,并有利于提高代码的可读性。

使用此规则的错误示例:

Open in Playground
/*eslint wrap-regex: "error"*/

function a() {
    return /foo/.test("bar");
}

使用此规则的正确示例:

Open in Playground
/*eslint wrap-regex: "error"*/

function a() {
    return (/foo/).test("bar");
}

Version

This rule was introduced in ESLint v0.1.0.

Resources

更改语言