Skip to content

fix: resolve SonarCloud critical issues and bugs#1509

Open
eran132 wants to merge 1 commit intohasadna:mainfrom
eran132:fix/sonarcloud-critical-bugs
Open

fix: resolve SonarCloud critical issues and bugs#1509
eran132 wants to merge 1 commit intohasadna:mainfrom
eran132:fix/sonarcloud-critical-bugs

Conversation

@eran132
Copy link
Copy Markdown

@eran132 eran132 commented Apr 13, 2026

Summary

Fixes critical issues and bugs identified by SonarCloud static analysis (see dashboard):

  • CRITICAL: Refactored LocationObservable to use a static factory method instead of launching async operations in the constructor
  • BUG: Fixed conditional value leak in BusToolTip JSX — route?.id && (...) could render 0 in the DOM when id is 0. Changed to route?.id != null
  • BUG: Fixed dead code in WorstLinesChart — template literal `${x}|${y}` || 'Unknown' is always truthy, so the 'Unknown' fallback was unreachable. Now checks values before interpolation

Skipped TimelinePage.ts false positive — Playwright's fixture use() was incorrectly flagged as a React Hook.

Test plan

  • TypeScript compiles clean
  • ESLint + Prettier + Stylelint pass with 0 warnings
  • Unit tests pass (9/9)

🤖 Generated with Claude Code

- Refactor LocationObservable to use static factory method instead of
  async operation in constructor (critical: S6637)
- Fix conditional value leak in BusToolTip JSX by using != null check
  instead of truthy check on route.id (bug: could render 0 in DOM)
- Fix dead code in WorstLinesChart where template literal was always
  truthy, making the || 'Unknown' fallback unreachable (bug: S3563)
- Skipped TimelinePage.ts false positive (Playwright fixture use()
  incorrectly flagged as React Hook)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@eran132 eran132 requested a review from AvivAbachi as a code owner April 13, 2026 22:42
Copilot AI review requested due to automatic review settings April 13, 2026 22:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Addresses SonarCloud-reported issues by fixing two React rendering edge cases and refactoring the vehicle-locations observable to avoid starting async work inside a constructor.

Changes:

  • Fix unreachable fallback logic in WorstLinesChart by only interpolating ids when required fields are present.
  • Prevent conditional value leakage in BusToolTip when route.id is 0 by checking for null/undefined explicitly.
  • Refactor LocationObservable to use a static factory (create) rather than performing async work in the constructor.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/pages/dashboard/WorstLinesChart/WorstLinesChart.tsx Makes the id derivation conditional so the 'Unknown' fallback is reachable.
src/pages/components/map-related/MapLayers/BusToolTip.tsx Fixes conditional JSX rendering to avoid rendering 0 into the DOM.
src/hooks/useVehicleLocations.ts Introduces a factory method to trigger async loading outside the constructor and updates cache initialization accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

({
id: `${item.lineRef}|${item.operatorRef?.operatorRef}` || 'Unknown',
id:
item.lineRef && item.operatorRef?.operatorRef
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new guard uses truthiness (item.lineRef && item.operatorRef?.operatorRef), which will treat valid numeric values like 0 as missing and return 'Unknown'. If these refs can be 0, switch to an explicit null/undefined check (e.g. != null) so 0 remains a valid id component.

Suggested change
item.lineRef && item.operatorRef?.operatorRef
item.lineRef != null && item.operatorRef?.operatorRef != null

Copilot uses AI. Check for mistakes.
Comment on lines +44 to 48
static create(query: VehicleLocationQuery) {
const instance = new LocationObservable()
void instance.#loadData(query)
return instance
}
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocationObservable now relies on the create() factory to start loading, but the default constructor is still publicly usable (within this module) and would create an instance that never loads data. Consider making the constructor private/protected (and optionally adding an explicit return type to create) to enforce correct initialization via the factory.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants