简中文档

no-empty-character-class

NOTE: this rule is part of the 推荐 rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["推荐"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["no-empty-character-class"],
      "exclude": ["no-empty-character-class"]
    }
  }
}

不允许在正则表达式中使用空字符类。

正则表达式字符类是一系列用方括号括起来的字符,例如 [abc]。如果方括号内没有任何内容,它将不会匹配任何东西,这很可能是一个拼写错误或失误。

无效:

/^abc[]/.test("abcdefg"); // false,因为 `d` 不匹配空字符类
"abcdefg".match(/^abc[]/); // null

有效:

// 没有字符类
/^abc/.test("abcdefg"); // true
"abcdefg".match(/^abc/); // ["abc"]

// 有一个有效的字符类
/^abc[a-z]/.test("abcdefg"); // true
"abcdefg".match(/^abc[a-z]/); // ["abcd"]

你找到了你需要的东西吗?

编辑此页面
隐私政策