Require parenthesis around regex literals
Some problems reported by this rule are automatically fixable by the --fix
command line option
When a regular expression is used in certain situations, it can end up looking like a division operator. For example:
function a() {
return /foo/.test("bar");
}
This is used to disambiguate the slash operator and facilitates more readable code.
Example of incorrect code for this rule:
/*eslint wrap-regex: "error"*/
function a() {
return /foo/.test("bar");
}
Example of correct code for this rule:
/*eslint wrap-regex: "error"*/
function a() {
return (/foo/).test("bar");
}
This rule was introduced in ESLint v0.1.0.
© OpenJS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/latest/rules/wrap-regex