Regular expression should not be wrapped as a string at
- No tags
This rule applies when a regular expression literal is wrapped as a string at the first argument of
String.prototype.replace() accepts string or regular expression as the first argument. String argument is searched verbatim whereas matching pattern is searched for regular expression argument.
When a regular expression literal is wrapped with quotes like
'/\s+/g', it will be recognized as a string argument and searched literally. This is not likely to be a programmer's intent.
This rule also applies to the analogous
Noncompliant Code ExampleView with compliant examples side by side
foo = foo.replace('/\s+/g', '_'); // BAD_REGEXP_LITERAL_IN_STRING alarm because quotes are used.
Compliant Code ExampleView with noncompliant examples side by side
foo = foo.replace(/\s+/g, '_');
This rule was introduced in DeepScan 1.30.0.