no-empty-class

禁止在正则表达式中使用空字符类。

¥Disallows empty character classes in regular expressions.

正则表达式中的空字符类不匹配任何内容,并且可能导致代码无法按预期工作。

¥Empty character classes in regular expressions do not match anything and can result in code that may not work as intended.

var foo = /^abc[]/;

规则详情

¥Rule Details

此规则旨在突出正则表达式中可能出现的拼写错误和意外行为,这些行为可能是由于使用空字符类而引起的。

¥This rule is aimed at highlighting possible typos and unexpected behavior in regular expressions which may arise from the use of empty character classes.

此规则的错误代码示例:

¥Examples of incorrect code for this rule:

var foo = /^abc[]/;

/^abc[]/.test(foo);

bar.match(/^abc[]/);

此规则的正确代码示例:

¥Examples of correct code for this rule:

var foo = /^abc/;

var foo = /^abc[a-z]/;

var bar = new RegExp("^abc[]");

版本

此规则是在 ESLint v0.0.9 中引入,并在 v1.0.0-rc-1 中删除。