Resolve 5 SonarQube issues across components and tests#709
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Resolve 5 SonarQube issues across components and tests#709sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZ4gULnbPbhjpGHKt4ck for typescript:S2699 rule - AZzc7Xbc7Egi-7Bbgag8 for typescript:S3358 rule - AZ4gULz1PbhjpGHKt4cl for typescript:S2699 rule - AZCX_zH4UB9YzXIX1wkI for typescript:S3358 rule - AZ2vZv68ZH2HqB6DnTPX for typescript:S6481 rule Generated by SonarQube Agent (task: df0e14bf-9dc8-4a88-91f1-431adcaad4ea)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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 PR fixes critical static analysis violations including two test cases missing assertions, nested ternary operations that reduced code readability, and a React context provider issue causing unnecessary re-renders. These fixes improve code quality, maintainability, and ensure proper test coverage across the codebase.
View Project in SonarCloud
Fixed Issues
typescript:S6481 - The object passed as the value prop to the Context provider changes every render. To fix this consider wrapping it in a useMemo hook. • MAJOR • View issue
Location:
src/components/unstyled/UnstyledChevronAccordion/UnstyledChevronAccordion.tsx:163Why is this an issue?
Whenever the
valueproperty of React context changes, React will rerender the context and all its child nodes and consumers. In JavaScript, things like object literals or function expressions will create a new identity every time they are evaluated. Such constructions should not be directly used as contextvaluebecause React will always consider they have changed. This can significantly impact performance.What changed
Adds the
useMemoimport from React, which is required by the newControlledAccordioncomponent that wraps the context provider value inuseMemoto prevent unnecessary re-renders caused by creating a new object literal on every render.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/owa/pupil/lesson/OakLessonNavItem/OakLessonNavItem.tsx:162Why is this an issue?
Nested ternaries are hard to read and can make the order of operations complex to understand.
What changed
This hunk replaces a nested ternary expression with an if/else-if/else chain. The original code used a ternary within a ternary (isDisabled && disabledBackgroundColor ? disabledBackgroundColor : progress === "not-started" ? notStartedBackgroundColor : backgroundColor), which violated the rule against nested ternary operations. By converting this to an explicit if/else-if/else block, the nested ternary is eliminated, making the code more readable and resolving the static analysis warning about extracting the nested ternary operation into an independent statement.
typescript:S2699 - Add at least one assertion to this test case. • BLOCKER • View issue
Location:
src/components/messaging-and-feedback/OakModalCenter/OakModalCenter.test.tsx:53Why is this an issue?
An assertion is a statement within the unit test that checks whether a particular condition is true or false. It defines the expected behavior of the unit being tested. Assertions are used to express the test’s expected outcome, and they are the criteria against which the actual output of the unit is evaluated.
What changed
Changes queryAllByTestId to queryByTestId, which is a supporting change for the assertion fix in hunk 2. queryByTestId returns null when no element is found, making it compatible with the .toBeNull() assertion that will be used to actually verify the test's expected outcome.
typescript:S2699 - Add at least one assertion to this test case. • BLOCKER • View issue
Location:
src/components/owa/OakCodeRenderer/OakCodeRenderer.test.tsx:19Why is this an issue?
An assertion is a statement within the unit test that checks whether a particular condition is true or false. It defines the expected behavior of the unit being tested. Assertions are used to express the test’s expected outcome, and they are the criteria against which the actual output of the unit is evaluated.
What changed
This hunk fixes a test case that had no effective assertion. The original code
expect(getByText("output")).toBeInTheDocumentwas merely referencing thetoBeInTheDocumentproperty without calling it as a function, meaning no assertion was actually executed. By adding parentheses to make ittoBeInTheDocument(), the matcher is now properly invoked, turning it into a real assertion that validates the test's expected outcome.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/internal-components/InternalShadowRoundButton/InternalShadowRoundButton.tsx:170Why is this an issue?
Nested ternaries are hard to read and can make the order of operations complex to understand.
What changed
This hunk extracts the nested ternary logic into a separate variable
iconColorFilter. The original code had a nested ternary:props.disabled ? disabledIconColor : defaultIconColor ? defaultIconColor : null, which violated the rule against nested ternary operations. By computing the value in a standalone statement usingdisabled ? disabledIconColor : defaultIconColor ?? null, the nested ternary is eliminated. The nullish coalescing operator (??) replaces the inner ternary (defaultIconColor ? defaultIconColor : null) in a cleaner, non-nested way.SonarQube Remediation Agent uses AI. Check for mistakes.