deno.com

禁止无效正则表达式

注意:此规则是 recommended 规则集的一部分。
deno.json 中启用完整集合
{
  "lint": {
    "rules": {
      "tags": ["recommended"]
    }
  }
}
使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
此规则可以通过将其添加到 deno.json 中的 includeexclude 数组中,从当前标签中包含或排除。
{
  "lint": {
    "rules": {
      "include": ["no-invalid-regexp"],
      "exclude": ["no-invalid-regexp"]
    }
  }
}

禁止在 RegExp 构造函数中指定无效的正则表达式。

指定无效的正则表达式字面量会在编译时导致 SyntaxError,然而在 RegExp 构造函数中指定无效的正则表达式字符串只会在运行时被发现。

无效示例

const invalidRegExp = new RegExp(")");

有效示例

const goodRegExp = new RegExp(".");

您找到所需内容了吗?

隐私政策