禁止空字符类
注意:此规则是
recommended
规则集的一部分。在
deno.json
中启用完整集合{ "lint": { "rules": { "tags": ["recommended"] } } }
使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
通过将此规则添加到
deno.json
中的 include
或 exclude
数组中,可以将其显式地包含或排除在当前标签中的规则之外。{ "lint": { "rules": { "include": ["no-empty-character-class"], "exclude": ["no-empty-character-class"] } } }
禁止在正则表达式中使用空字符类。
正则表达式字符类是括号中的一系列字符,例如 [abc]
。如果括号中未提供任何内容,则它将不匹配任何内容,这很可能是拼写错误或笔误。
无效示例
/^abc[]/.test("abcdefg"); // false, as `d` does not match an empty character class
"abcdefg".match(/^abc[]/); // null
有效示例
// Without a character class
/^abc/.test("abcdefg"); // true
"abcdefg".match(/^abc/); // ["abc"]
// With a valid character class
/^abc[a-z]/.test("abcdefg"); // true
"abcdefg".match(/^abc[a-z]/); // ["abcd"]