Fix five SonarQube issues in Oak components#711
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
Conversation
Fixed issues: - AZCX_zJRUB9YzXIX1wkp for typescript:S1871 rule - AZY6A9-rukQXIMm7iRsX for typescript:S6479 rule - AZY6A9-rukQXIMm7iRsY for typescript:S5843 rule - AZY6A9-rukQXIMm7iRsZ for typescript:S1854 rule - AZx19D7mQwuJZdSIM-HZ for typescript:S6847 rule Generated by SonarQube Agent (task: 6013b01d-3b36-416a-bbf9-350be6aedffb)
|
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 change fixes five MAJOR code quality issues across Oak components: converts non-interactive elements to proper buttons, removes useless variable assignments, stabilizes React list keys with content-based identifiers, simplifies overly complex regex patterns, and eliminates duplicate case blocks in switch statements. These fixes improve code maintainability, accessibility, and prevent potential bugs from DOM recreation and excessive complexity.
View Project in SonarCloud
Fixed Issues
typescript:S6847 - Non-interactive elements should not be assigned mouse or keyboard event listeners. • MAJOR • View issue
Location:
src/components/owa/OakListItem/OakListItem.tsx:151Why is this an issue?
Attaching event handlers to non-interactive HTML elements can lead to significant accessibility issues. These elements, such as
<div>and<span>, are not designed to interact with assistive technologies like screen readers, making it difficult for users with disabilities to navigate and interact with the website. Additionally, these elements may not be focusable or provide visual feedback when interacted with, resulting in a confusing and potentially frustrating user experience. Therefore, to maintain an accessible and user-friendly website, event handlers should be used exclusively with interactive elements.What changed
Adds imports for ReactNode and useCallback, which are needed by the new renderWrapper function and handleKeyDown callback that replace the non-interactive element's onClick handler with proper interactive elements (a or a with htmlFor).
typescript:S1854 - Remove this useless assignment to variable "isCheckingMatches". • MAJOR • View issue
Location:
src/components/owa/OakCodeRenderer/OakCodeRenderer.tsx:107Why is this an issue?
Dead stores refer to assignments made to local variables that are subsequently never used or immediately overwritten. Such assignments are unnecessary and don’t contribute to the functionality or clarity of the code. They may even negatively impact performance. Removing them enhances code cleanliness and readability. Even if the unnecessary operations do not do any harm in terms of the program’s correctness, they are - at best - a waste of computing resources.
What changed
Removes the
isCheckingMatchesvariable and replaceswhile (isCheckingMatches)withwhile (true). This eliminates the dead store toisCheckingMatchesthat was flagged as a useless assignment, since the variable was assignedfalsebut the loop was actually terminated by abreakstatement, making the assignment unnecessary.typescript:S6479 - Do not use Array index in keys • MAJOR • View issue
Location:
src/components/owa/OakCodeRenderer/OakCodeRenderer.tsx:36Why is this an issue?
To optimize the rendering of React list components, a unique identifier (UID) is required for each list item. This UID lets React identify the item throughout its lifetime. Avoid array indexes since the order of the items may change, which will cause keys to not match up between renders, recreating the DOM. It can negatively impact performance and may cause issues with the component state.
What changed
Changes the React list key from using only the array index (
key={index}) to a composite key that includes the content and the index (key={${part}-${index}}). This addresses the code smell about using plain array indexes as keys in React list rendering, which can cause unnecessary DOM recreation when list items are reordered.typescript:S5843 - Simplify this regular expression to reduce its complexity from 31 to the 20 allowed. • MAJOR • View issue
Location:
src/components/owa/OakCodeRenderer/OakCodeRenderer.tsx:62Why is this an issue?
A complex regular expression is one that exhibits several or all of the following characteristics. It can be quite lengthy, containing multiple nested or repeated groups, numerous alternations, extensive use of backreferences and escape characters, lookaheads, lookbehinds, and other advanced features. Additionally, complex regular expressions may lack proper comments and documentation, making them challenging to comprehend and maintain. Overly complicated regular expressions are hard to read and maintain and can easily cause hard-to-find bugs.
What changed
Splits the overly complex Python keywords regular expression into two smaller regexes. This hunk reduces the first regex to only contain keywords from 'and' through 'from', cutting the number of alternations roughly in half. This brings the complexity of this individual regex below the allowed threshold of 20, addressing the warning about excessive regex complexity.
typescript:S1871 - This case's code block is the same as the block for the case on line 185. • MAJOR • View issue
Location:
src/components/owa/pupil/lesson/OakLessonLayout/OakLessonLayout.tsx:227Why is this an issue?
When the same code is duplicated in two or more separate branches of a conditional, it can make the code harder to understand, maintain, and can potentially introduce bugs if one instance of the code is changed but others are not.
What changed
This hunk adds
case "review":as a fall-through case right aftercase "overview":(at line 185). By making the "review" case fall through to the "overview" case, both cases share the same code block, eliminating the duplicate code that was previously in a separate "review" case block. This directly addresses the code smell where the "review" case (previously at line 227) had an identical implementation to the "overview" case (at line 185).SonarQube Remediation Agent uses AI. Check for mistakes.