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
Open
Conversation
Fixed issues: - AZWU-tY5YJSZqVQVbSde for typescript:S4138 rule Generated by SonarQube Agent (task: 3b9543d7-5948-460a-ae0f-899110588c63)
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 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. • MINOR • View issue
Location:
data/static/codefixes/dbSchemaChallenge_2_correct.ts:10Why 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
forloop (for (let i = 0; i < products.length; i++)) with afor...ofloop (for (const product of products)), and updates the loop body to use the iteratedproductvariable directly instead of indexing withproducts[i]. This directly addresses the code smell warning that afor...ofloop should be used instead of aforloop when performing simple iteration over an iterable array.SonarQube Remediation Agent uses AI. Check for mistakes.