Skip to content

Commit

Permalink
fix for RegExp() without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Mar 3, 2024
1 parent 7eaf8b4 commit ebe11f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/no-misleading-character-class.js
Expand Up @@ -205,11 +205,14 @@ const kinds = Object.keys(findCharacterSequences);
* or the node's `regex` property.
* The purpose of this method is to provide a replacement for `getStaticValue` on Node.js 18, where `getStaticValue` returns `null` if a regular expression literal contains the `v` flag.
* A limitation of this method is that it can only detect a regular expression if the specified node is itself a regular expression literal node.
* @param {ASTNode} node The node to be inspected.
* @param {ASTNode|null|undefined} node The node to be inspected.
* @param {Scope} [initialScope] Optional scope to start finding variables. If this scope was given, this tries to resolve identifier references which are in the given node as much as possible.
* @returns {{ value: any } | { value: undefined, optional?: true } | { regex: { pattern: string, flags: string } } | null} The static value of the node, or `null`.
*/
function getStaticValueOrRegex(node, initialScope) {
if (!node) {
return null;
}
if (node.type === "Literal" && node.regex) {
return { regex: node.regex };
}
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/no-misleading-character-class.js
Expand Up @@ -40,6 +40,7 @@ ruleTester.run("no-misleading-character-class", rule, {
"var r = /πŸ‡―πŸ‡΅/",
"var r = /[JP]/",
"var r = /πŸ‘¨β€πŸ‘©β€πŸ‘¦/",
"new RegExp()",
"var r = RegExp(/[πŸ‘]/u)",
"const regex = /[πŸ‘]/u; new RegExp(regex);",
{
Expand Down

0 comments on commit ebe11f8

Please sign in to comment.