Skip to content

[internal] Fix maintainability and reliability issues raised by SonarQube#268

Open
dozro wants to merge 11 commits intoSableClient:devfrom
dozro:sonarqube/maintainability-2026-03-14
Open

[internal] Fix maintainability and reliability issues raised by SonarQube#268
dozro wants to merge 11 commits intoSableClient:devfrom
dozro:sonarqube/maintainability-2026-03-14

Conversation

@dozro
Copy link
Contributor

@dozro dozro commented Mar 14, 2026

Description

This pull request focuses on code consistency and minor improvements across multiple UI components. The main themes are enforcing immutability by using Readonly for props, improving array creation patterns for clarity, and standardizing string and regex manipulation with replaceAll. There are also minor logic and readability enhancements.

Immutability and Type Safety Improvements:

  • Converted component props to use Readonly<T> in various components (e.g., SetupVerification, RecoveryKeyDisplay, RenderMessageContentInternal, EmojiSidebar, StickerSidebar, EmojiGroupHolder, EmojiBoard, MenuOptions, EventItem, RenderBody, PreviewImage, PreviewVideo, UploadCardRenderer, DescriptionEditor) to ensure props are not mutated and improve type safety.
    Array Handling and Code Consistency:

  • Replaced Array.from(Array(...).keys()) with Array.from(new Array(...).keys()) for clarity and consistency in date and time pickers.

  • Simplified array creation in EmoticonAutocomplete using spread syntax for better readability.

String and Regex Handling Enhancements:

  • Standardized usage of replaceAll for string and regex replacement operations to improve code clarity and future-proofing. This affects recovery key display, custom HTML processing, and reply formatting.

Logic and Readability Improvements:

  • Used Number.parseInt instead of parseInt for explicitness and consistency.
  • Improved logic for heading level clamping and date selection using Math.min for clarity.
  • Corrected conditional logic for time picker variant selection.
  • Improved mapping of array elements by passing explicit arguments in mapping functions for better readability and future extensibility.

Type and Optional Parameter Cleanups:

  • Removed unnecessary undefined from optional type definitions for cleaner code.

These changes collectively improve code maintainability, readability, and type safety without introducing major feature changes.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

dozro added 10 commits March 14, 2026 16:37
fixed sonarqube issues:
- React props should be read-only (typescript:S6759)
- Spacing between inline elements should be explicit (typescript:S6772)
fixed issues:
- typescript:S7781
- typescript:S6759
- typescript:S7773
- typescript:S4158
- Number static methods and properties should be preferred over global equivalents (typescript:S7773)
- Function references should not be passed directly to iterator methods (typescript:S7727)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- "RegExp.exec()" should be preferred over "String.match()" (typescript:S6594)
- React props should be read-only (typescript:S6759)
- Prefer `Math.min()` to simplify ternary expressions (typescript:S7766)
- Optional property declarations should not use both '?' and 'undefined' syntax (typescript:S4782)
- Built-in constructors should be called consistently with or without "new" (typescript:S7723)
- Built-in constructors should be called consistently with or without "new" (typescript:S7723)
- Negated conditions should be avoided when an else clause is present (typescript:S7735)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- Use ".some()" instead of ".filter().length" checks or ".find()" for existence testing (typescript:S7754)
- React props should be read-only (typescript:S6759)
- Number static methods and properties should be preferred over global equivalents (typescript:S7773)
- The return value of "useState" should be destructured and named symmetrically (typescript:S6754)
- Optional chaining should be preferred (typescript:S6582)
- Arrays used only for existence checks should be Sets (typescript:S7776)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
- Strings should use "replaceAll()" instead of "replace()" with global regex (typescript:S7781)
- Existence checks should use ".includes()" instead of ".indexOf()" or ".lastIndexOf()" (typescript:S7765)
- Use "globalThis" instead of "window", "self", or "global" (typescript:S7764)
- Use "globalThis" instead of "window", "self", or "global" (typescript:S7764)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
- Unicode-aware string methods should be used for proper character handling (typescript:S7758)
@dozro dozro requested a review from a team March 14, 2026 17:31
@dozro dozro changed the title Fix maintainability and reliability issues raised by SonarQube [internal] Fix maintainability and reliability issues raised by SonarQube Mar 14, 2026
@7w1 7w1 added the internal label Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants