Eslint参考手册
规则 | Rules
wrap-regex
The --fix
option on the command line can automatically fix some of the problems reported by this rule.
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");
}
Rule Details
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");
}
Version
This rule was introduced in ESLint 0.1.0.
Resources
- Rule source
- Documentation source
© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/wrap-regex
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |