Skip to content

Commit 56dd88d

Browse files
Safaa OugunirSafaa Ougunir
authored andcommitted
feat: add Js rule GCI3
1 parent 458ab17 commit 56dd88d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Deleted
1717

18+
## [2.2.3] - 2025-05-20
19+
20+
### Added
21+
22+
- []() Add JS variant of rule GCI3 - Avoid getting size collection in loops
23+
1824
## [2.2.2] - 2025-03-13
1925

2026
### Added
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
== Why is this an issue?
2+
When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration, this saves CPU cycles, and therefore consumes less power.
3+
[source,js,data-diff-id="2",data-diff-type="noncompliant"]
4+
----
5+
for (let i = 0; i < array.length; i++) {
6+
console.log(array[array.length]); // Noncompliant
7+
}
8+
----
9+
[source,js,data-diff-id="2",data-diff-type="compliant"]
10+
----
11+
const arrayLength = array.length; // Fetch the length once
12+
for (let i = 0; i < arrayLength; i++) {
13+
console.log(array[arrayLength]); // Compliant
14+
}

0 commit comments

Comments
 (0)