noEmptyCharacterClassInRegex
¥Summary
-
规则生效日期:
v1.3.0¥Rule available since:
v1.3.0 -
诊断类别:
lint/correctness/noEmptyCharacterClassInRegex¥Diagnostic Category:
lint/correctness/noEmptyCharacterClassInRegex -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
¥Same as
no-empty-character-class
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noEmptyCharacterClassInRegex": "error" } } }}¥Description
禁止正则表达式文字中的空字符类。
¥Disallow empty character classes in regular expression literals.
空字符类不匹配任何内容。相比之下,否定的空类匹配任何字符。它们通常是打字错误的结果。
¥Empty character classes don’t match anything. In contrast, negated empty classes match any character. They are often the result of a typing mistake.
¥Examples
¥Invalid
/^a[]/.test("a"); // falsecode-block.js:1:4 lint/correctness/noEmptyCharacterClassInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The regular expression includes this empty character class.
> 1 │ /^a[]/.test(“a”); // false
│ ^^
2 │
ℹ Empty character classes don’t match anything.
If you want to match against [, escape it \[.
Otherwise, remove the character class or fill it.
/^a[^]/.test("ax"); // truecode-block.js:1:4 lint/correctness/noEmptyCharacterClassInRegex ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The regular expression includes this negated empty character class.
> 1 │ /^a[^]/.test(“ax”); // true
│ ^^^
2 │
ℹ Negated empty character classes match anything.
If you want to match against [, escape it \[.
Otherwise, remove the character class or fill it.
¥Valid
/^a[xy]/.test("ay"); // true/^a[^xy]/.test("ab"); // true/^a\[]/.test("a[]"); // true¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号