56 lines
1.1 KiB
Plaintext
Raw Normal View History

2020-06-30 10:16:44 +02:00
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
2020-06-30 10:16:44 +02:00
[source,javascript,diff-id=1,diff-type=noncompliant]
2020-06-30 10:16:44 +02:00
----
function doSomething() {
for (let i = 0; i < 4; i++) { // Noncompliant, 4 is a magic number
2020-06-30 10:16:44 +02:00
// ...
}
}
----
==== Compliant solution
2020-06-30 10:16:44 +02:00
[source,javascript,diff-id=1,diff-type=compliant]
2020-06-30 10:16:44 +02:00
----
function doSomething() {
const numberOfCycles = 4;
for (let i = 0; i < numberOfCycles; i++) { // Compliant
2020-06-30 10:16:44 +02:00
// ...
}
}
----
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[]