Use a regular expression literal instead of the 'RegExp' constructor.
17 `No matches could be found for module entry point ${moduleEntryPoint}`
18);
19
20const DIST_REGEXP = new RegExp('(.*)dist');21export const getModuleFolder = (name: string): string => {
22 const moduleEntryPoint = resolver(name);
23 const match = moduleEntryPoint.match(DIST_REGEXP)?.pop();
Description
When a regular expression is known in advance, it is considered a best practice to avoid the string literal notation on top of the regular expression notation, and use regular expression literals instead of the constructor function.
// bad practice:
const number = new RegExp("^\d\.$");
// recommended:
const number_ = /^\d\.$/;
Regex literals are easier to read and do not require a call to the RegExp
constructor at runtime.
Bad Practice
new RegExp("abc");
new RegExp("abc", "u");
RegExp("abc");
RegExp("abc", "u");
new RegExp("\d\d\.\d\d\.\d\d\d\d");
RegExp(`^\d\.$`);
new RegExp(String.raw`^\d\.$`);
Recommended
/abc/;
/abc/u;
/\d\d\.\d\d\.\d\d\d\d/;
/^\d\.$/;
// RegExp constructor is allowed for dynamically generated regular expressions
new RegExp(pattern);
RegExp("abc", flags);
new RegExp(prefix + "abc");
RegExp(`${prefix}abc`);
new RegExp(String.raw`^\d\. ${sufix}`);