modify_S2639_layc_js_only (#2122)
Made some updates to rule text for Java, Javascript, and the general description for the other languages. ## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone --------- Co-authored-by: Elena Vilchik <elena.vilchik@sonarsource.com>
This commit is contained in:
parent
cfb6eb88f4
commit
09e3db2ac9
@ -1,22 +1,20 @@
|
||||
== Why is this an issue?
|
||||
|
||||
Empty character classes in regular expressions don't match anything.
|
||||
|
||||
This is likely a sign that the regular expression does not work as intended.
|
||||
|
||||
=== Noncompliant code example
|
||||
Character classes in regular expressions allow you to define sets of characters for matching, for example `[abc]` will match `a`, `b` or `c`.
|
||||
|
||||
[source,javascript]
|
||||
----
|
||||
/^foo[]/.test("foobar"); // false
|
||||
/^foo[]/.test(str); // Noncompliant, always returns "false"
|
||||
----
|
||||
|
||||
=== Compliant solution
|
||||
An empty character class (`[]`) will not match any character because the set of matching characters is empty. So the regular expression will not work as you intended.
|
||||
|
||||
[source,javascript]
|
||||
----
|
||||
/^foo/.test("foobar"); // true
|
||||
----
|
||||
== Resources
|
||||
|
||||
=== Documentation
|
||||
|
||||
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes[MDN web docs: Character classes]
|
||||
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions[MDN web docs: Regular expressions]
|
||||
|
||||
ifdef::env-github,rspecator-view[]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user