Convert ASSERTION_METHODS array to Set for O(1) lookup performance - #7727
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Convert ASSERTION_METHODS array to Set for O(1) lookup performance#7727sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ7yEuPOhshm9reY56Ah for typescript:S7776 rule Generated by SonarQube Agent (task: 5b7e123f-babe-4525-b115-465c429693b7)
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.
This change converts the
ASSERTION_METHODSvariable from an array literal to aSetin the cypress.ts testing helper, enabling O(1) existence checks viaSet#has()instead of O(n)Array#includes()operations. This performance improvement addresses a SonarQube code smell and aligns the code with recommended best practices for membership testing.View Project in SonarCloud
Fixed Issues
typescript:S7776 - `ASSERTION_METHODS` should be a `Set`, and use `ASSERTION_METHODS.has()` to check existence or non-existence. • MINOR • View issue
Location:
packages/analysis/src/jsts/rules/helpers/testing/cypress.ts:21Why is this an issue?
Using
Array#includes()for existence checks can lead to performance problems, especially with larger datasets.What changed
Converts the
ASSERTION_METHODSvariable from an array literal to aSetby wrapping it withnew Set(...). This directly addresses the code smell at line 21 of cypress.ts where the static analysis warns thatASSERTION_METHODSshould be aSetand should useSet#has()instead ofArray#includes()for existence checking, improving performance from O(n) to O(1).SonarQube Remediation Agent uses AI. Check for mistakes.