no-div-regex
在正则表达式的开头明确禁止等号
正则表达式字面量开头的字符 /= 可能会与除法赋值运算符混淆。
🌐 Characters /= at the beginning of a regular expression literal can be confused with a division assignment operator.
function bar() { return /=foo/; }
规则详情
🌐 Rule Details
此规则禁止在正则表达式字面量开头的斜杠(/)之后使用等号(=),因为字符 /= 可能会被误认为是除法赋值运算符。
🌐 This rule forbids equal signs (=) after the slash (/) at the beginning of a regular expression literal, because the characters /= can be confused with a division assignment operator.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
在线运行
/*eslint no-div-regex: "error"*/
function bar() { return /=foo/; }
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
在线运行
/*eslint no-div-regex: "error"*/
function bar() { return /[=]foo/; }
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
相关规则
版本
此规则是在 ESLint v0.1.0 中引入。