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:
cynthiabethea 2023-06-15 15:56:08 +01:00 committed by GitHub
parent cfb6eb88f4
commit 09e3db2ac9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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[]