no-invalid-regexp
NOTE: this rule is part of the
recommended
rule set.Enable full set in
deno.json
:{ "lint": { "rules": { "tags": ["recommended"] } } }
Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
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-invalid-regexp"], "exclude": ["no-invalid-regexp"] } } }
不允许在 RegExp 构造函数中指定无效的正则表达式。
指定无效的正则表达式字面量将在编译时导致 SyntaxError,然而在 RegExp 构造函数中指定无效的正则表达式字符串则只会在运行时被发现。
无效:
const invalidRegExp = new RegExp(")");
有效:
const goodRegExp = new RegExp(".");