Extract nested ternary operations into independent statements#712
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Extract nested ternary operations into independent statements#712sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZu2815v3HG28QKD5-no for typescript:S3358 rule - AZZdbsnyGqSXlvld7x1e for typescript:S3358 rule - AZZjFi7yv83E0IyiIbLd for typescript:S3358 rule - AZCX_zKqUB9YzXIX1wlD for typescript:S3358 rule - AZCX_zMnUB9YzXIX1wlk for typescript:S3358 rule Generated by SonarQube Agent (task: 44502f58-8bf5-46a3-a751-5373b558a6e5)
|
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 resolves 5 SonarQube MAJOR issues by extracting nested ternary expressions into separate variables and helper functions. Nested ternary operations reduce code readability and maintainability, so extracting them into clearly-named independent statements makes the codebase easier to understand and less prone to logic errors.
View Project in SonarCloud
Fixed Issues
typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/owa/OakSaveCount/OakSaveCount.tsx:53Why 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 expression
count === 1 ? "" : "s"into a separate variableunitSuffix. By computing the pluralization suffix in an independent statement before the template literal, it eliminates the nested ternary that was flagged as hard to read. This is the first part of the fix — defining the extracted variable.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/owa/teacher/OakUnitListItem/OakUnitListItem.tsx:140Why is this an issue?
Nested ternaries are hard to read and can make the order of operations complex to understand.
What changed
Introduces an if/else if/else block to compute the
indexBoxBackgroundvariable, replacing the nested ternary logic that was previously inlined in two JSX locations. By pre-computing the background value using clear conditional statements, this hunk eliminates the need for nested ternary expressions in the JSX, directly addressing the 'nested ternary operation' code smell at both locations where it appeared.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/internal-components/InternalShadowIconButton/InternalShadowIconButton.tsx:164Why 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
defaultColorFilter. The original code had a nested ternary (props.disabled ? disabledIconColor : defaultIconColor ? defaultIconColor : null) which violated the rule against nested ternary operations. By pre-computing the value usingdefaultIconColor || nullinstead of a nested ternary (defaultIconColor ? defaultIconColor : null), this hunk eliminates the nested ternary and makes the code more readable.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/owa/teacher/OakUnitListItem/OakUnitListItem.tsx:227Why is this an issue?
Nested ternaries are hard to read and can make the order of operations complex to understand.
What changed
Introduces an if/else if/else block to compute the
indexBoxBackgroundvariable, replacing the nested ternary logic that was previously inlined in two JSX locations. By pre-computing the background value using clear conditional statements, this hunk eliminates the need for nested ternary expressions in the JSX, directly addressing the 'nested ternary operation' code smell at both locations where it appeared.typescript:S3358 - Extract this nested ternary operation into an independent statement. • MAJOR • View issue
Location:
src/components/layout-and-structure/OakGridArea/OakGridArea.tsx:85Why is this an issue?
Nested ternaries are hard to read and can make the order of operations complex to understand.
What changed
Introduces a helper function
resolveResponsiveValuethat encapsulates theArray.isArray(value) ? value[index] : valuelogic into a single reusable function. This eliminates the need for nested ternary expressions in the calling code, where previously the array check was nested inside another ternary, violating the rule against nested ternary operations.SonarQube Remediation Agent uses AI. Check for mistakes.