fix: replace for loop with for-of loop in dbSchemaChallenge_1.ts#17
Open
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
Open
fix: replace for loop with for-of loop in dbSchemaChallenge_1.ts#17sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
sonarqube-agent[bot] wants to merge 1 commit intomasterfrom
Conversation
Fixed issues: - AZWU-tYyYJSZqVQVbSdY for typescript:S4138 rule Generated by SonarQube Agent (task: a92c7fe3-5764-422c-9956-fd4eee497b80)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaced a traditional index-based for loop with a for-of loop to improve code readability and eliminate unnecessary counter variables. This change addresses a SonarQube code smell (S4138) and follows modern JavaScript best practices for iterating through arrays.
View Project in SonarCloud
Fixed Issues
typescript:S4138 - Expected a `for-of` loop instead of a `for` loop with this simple iteration. • MINOR • View issue
Location:
data/static/codefixes/dbSchemaChallenge_1.ts:8Why is this an issue?
for...ofstatements are used to iterate over the values of an iterable object. Iterables are objects implementing the@@iteratormethod, 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 index-based
forloop (for (let i = 0; i < products.length; i++)) with afor...ofloop (for (const product of products)), and updates the loop body to reference the iteration variableproductdirectly instead of usingproducts[i]. This addresses the code smell about preferringfor...ofover a simpleforloop when iterating through an iterable object like an array, improving readability and eliminating the unnecessary counter variable.SonarQube Remediation Agent uses AI. Check for mistakes.