Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify rule S4138: Include warning about browser array-like collections in TypeScript #1303

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions rules/S4138/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
If you have an iterable, such as an array, set, or list, your best option for looping through its values is the ``++for of++`` syntax. Use a counter, and ... well you'll get the right behavior, but your code just isn't as clean or clear.

In a browser environment, `NodeList` and other array-like collections should work by default. If you are using TypeScript and seeing a type error, make sure your configuration is correct.

== Noncompliant Code Example

Expand All @@ -8,7 +9,7 @@ If you have an iterable, such as an array, set, or list, your best option for lo
const arr = [4, 3, 2, 1];

for (let i = 0; i < arr.length; i++) { // Noncompliant
console.log(arr[i]);
console.log(arr[i]);
}
----

Expand All @@ -19,8 +20,8 @@ for (let i = 0; i < arr.length; i++) { // Noncompliant
----
const arr = [4, 3, 2, 1];

for (let value of arr) {
console.log(value);
for (let value of arr) {
console.log(value);
}
----

Expand Down