Skip to content

fix: use for-of loop instead of traditional for loop in dbSchemaChallenge_2_correct.ts#18

Open
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
remediate-master-20260330-075802-32cfbedd
Open

fix: use for-of loop instead of traditional for loop in dbSchemaChallenge_2_correct.ts#18
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
remediate-master-20260330-075802-32cfbedd

Conversation

@sonarqube-agent
Copy link
Copy Markdown

Replaced a traditional for loop with a for-of loop to improve code clarity and follow modern JavaScript best practices. This change addresses a SonarQube code smell warning and makes the iteration logic more readable by directly using the array element instead of manual index access.

View Project in SonarCloud


Fixed Issues

typescript:S4138 - Expected a `for-of` loop instead of a `for` loop with this simple iteration. • MINORView issue

Location: data/static/codefixes/dbSchemaChallenge_2_correct.ts:10

Why is this an issue?

for...of statements are used to iterate over the values of an iterable object. Iterables are objects implementing the @@iterator method, which returns an object conforming to the iterator protocol. JavaScript provides many built-in iterables that can and should be used with this looping statement.

What changed

Replaces the traditional for loop (for (let i = 0; i < products.length; i++)) with a for...of loop (for (const product of products)), and updates the loop body to use the iterated product variable directly instead of indexing with products[i]. This directly addresses the code smell warning that a for...of loop should be used instead of a for loop when performing simple iteration over an iterable array.

--- a/data/static/codefixes/dbSchemaChallenge_2_correct.ts
+++ b/data/static/codefixes/dbSchemaChallenge_2_correct.ts
@@ -10,3 +10,3 @@ module.exports = function searchProducts () {
-        for (let i = 0; i < products.length; i++) {
-          products[i].name = req.__(products[i].name)
-          products[i].description = req.__(products[i].description)
+        for (const product of products) {
+          product.name = req.__(product.name)
+          product.description = req.__(product.description)

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZWU-tY5YJSZqVQVbSde for typescript:S4138 rule

Generated by SonarQube Agent (task: 3b9543d7-5948-460a-ae0f-899110588c63)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants