Skip to content

Convert ASSERTION_METHODS array to Set for O(1) lookup performance - #7727

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260808-050233-e8a35f98
Open

Convert ASSERTION_METHODS array to Set for O(1) lookup performance#7727
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260808-050233-e8a35f98

Conversation

@sonarqube-agent

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? This is a well-scoped, single-issue fix with clear automation guidance from SonarQube's explicit recommendation to use Set over array for membership checking. The change is localized to a specific file, has straightforward correctness verification, and provides measurable performance benefits for a commonly-used utility in the testing framework.

This change converts the ASSERTION_METHODS variable from an array literal to a Set in the cypress.ts testing helper, enabling O(1) existence checks via Set#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. • MINORView issue

Location: packages/analysis/src/jsts/rules/helpers/testing/cypress.ts:21

Why is this an issue?

Using Array#includes() for existence checks can lead to performance problems, especially with larger datasets.

What changed

Converts the ASSERTION_METHODS variable from an array literal to a Set by wrapping it with new Set(...). This directly addresses the code smell at line 21 of cypress.ts where the static analysis warns that ASSERTION_METHODS should be a Set and should use Set#has() instead of Array#includes() for existence checking, improving performance from O(n) to O(1).

--- a/packages/analysis/src/jsts/rules/helpers/testing/cypress.ts
+++ b/packages/analysis/src/jsts/rules/helpers/testing/cypress.ts
@@ -21,1 +21,1 @@ import ts from 'typescript';
-const ASSERTION_METHODS = ['should', 'and'];
+const ASSERTION_METHODS = new Set(['should', 'and']);

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


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ7yEuPOhshm9reY56Ah for typescript:S7776 rule

Generated by SonarQube Agent (task: 5b7e123f-babe-4525-b115-465c429693b7)
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.

1 participant