Modify rule S6325: Adapt to LaYC
This commit is contained in:
parent
3b655b6b90
commit
2429edf9ce
@ -1,10 +1,6 @@
|
|||||||
== Why is this an issue?
|
== Why is this an issue?
|
||||||
|
|
||||||
Regular expression literals should be preferred over the `RegExp` constructor calls when the pattern is a literal. Simply using a regular expression literal is more concise and easier to read and does not require escaping like a string literal does.
|
Using regular expression literals is recommended over using the `RegExp` constructor calls if the pattern is a literal. Regular expression literals are shorter, more readable, and do not need to be escaped like string literals.
|
||||||
|
|
||||||
Using the `RegExp` constructor is suitable when the pattern is computed dynamically, e.g. when it is provided by the user.
|
|
||||||
|
|
||||||
=== Noncompliant code example
|
|
||||||
|
|
||||||
[source,javascript]
|
[source,javascript]
|
||||||
----
|
----
|
||||||
@ -15,7 +11,7 @@ new RegExp("\\d+");
|
|||||||
new RegExp(`qux|quuz`);
|
new RegExp(`qux|quuz`);
|
||||||
----
|
----
|
||||||
|
|
||||||
=== Compliant solution
|
Using the `RegExp` constructor is suitable when the pattern is computed dynamically, for example when it is provided by the user.
|
||||||
|
|
||||||
[source,javascript]
|
[source,javascript]
|
||||||
----
|
----
|
||||||
@ -26,3 +22,11 @@ new RegExp(`qux|quuz`);
|
|||||||
/qux|quuz/;
|
/qux|quuz/;
|
||||||
new RegExp(`Dear ${title},`);
|
new RegExp(`Dear ${title},`);
|
||||||
----
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp[MDN - RegExp]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user