Tibor Blenessy 7e46053974
Modify S109 for JS: document exclusions (#3380)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)

---------

Co-authored-by: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com>
2023-10-30 08:17:25 +00:00

56 lines
1.1 KiB
Plaintext

include::../description.adoc[]
=== Exceptions
- the following numbers used in arithmetic operations: -1, 0, 1, as well as powers of 2 and 10
- time-related constants such as 24 and 60 are excluded
- numbers used in JSX elements are excluded
- enum values, default values, and other assignments are excluded
- arguments to `parseInt()` and `JSON.stringify()` are excluded
- numbers used in bitwise operations are excluded
include::../how-to-fix-it.adoc[]
=== Code examples
==== Noncompliant code example
[source,javascript,diff-id=1,diff-type=noncompliant]
----
function doSomething() {
for (let i = 0; i < 4; i++) { // Noncompliant, 4 is a magic number
// ...
}
}
----
==== Compliant solution
[source,javascript,diff-id=1,diff-type=compliant]
----
function doSomething() {
const numberOfCycles = 4;
for (let i = 0; i < numberOfCycles; i++) { // Compliant
// ...
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]