Skip to content

Commit edcb175

Browse files
eran132claude
andcommitted
fix: resolve remaining 59 SonarCloud issues
Applied all mechanical fixes that were missed in the first pass: - Readonly<> on 18 component prop types - globalThis over window (8 files) - Number.parseInt, Number.isNaN, replaceAll, codePointAt, .some(), .at() - ??= and ?? for cleaner assignments - useMemo for Context provider values - Extracted 3 inner components to top level - Added role/tabIndex/onKeyDown for accessibility - Changed <a> to <button> where used as button - Destructured useState, converted to top-level await Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 99669ac commit edcb175

39 files changed

Lines changed: 129 additions & 95 deletions

src/App.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import router from './routes'
55
import Preloader from './shared/Preloader'
66

77
if ('serviceWorker' in navigator) {
8-
navigator.serviceWorker
9-
.register('/service-worker.js')
10-
.then((reg) => console.log('Service Worker Registered', reg))
11-
.catch((err) => console.error('Service Worker Registration Failed', err))
8+
try {
9+
const reg = await navigator.serviceWorker.register('/service-worker.js')
10+
console.log('Service Worker Registered', reg)
11+
} catch (err) {
12+
console.error('Service Worker Registration Failed', err)
13+
}
1214
}
1315

1416
export const RoutedApp = () => {

src/api/agencyList.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ async function fetchAgencyList() {
2323
}
2424

2525
export function getAgencyList() {
26-
if (!agencyListPromise) {
27-
agencyListPromise = fetchAgencyList()
28-
}
26+
agencyListPromise ??= fetchAgencyList()
2927
return agencyListPromise
3028
}

src/api/gapsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const getGapsAsync = (
2626
dateTo: new Date(toTimestamp),
2727
limit,
2828
lineRef,
29-
operatorRef: parseInt(operatorId),
29+
operatorRef: Number.parseInt(operatorId),
3030
}).then((gaps) =>
3131
gaps.map((gap) => {
3232
return {

src/api/groupByService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ export function useGroupBy({
5858
dateFrom: number
5959
groupBy: groupByFields
6060
}) {
61-
const { isLoading, isError, data, error } = useQuery({
61+
const { isLoading, data, error } = useQuery({
6262
queryKey: ['groupBy', dateFrom, dateTo, groupBy],
6363
queryFn: () => fetchGroupBy({ dateFrom, dateTo, groupBy }),
6464
})
6565

66-
return [data ? data : [], isLoading, isError ? error : null] as const
66+
return [data ?? [], isLoading, error ?? null] as const
6767
}

src/api/gtfsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function getStopsForRouteAsync(
7070
rideStops.map(async (rideStop) => {
7171
if (
7272
!rideStop.gtfsStopId ||
73-
stops.find((b) => b.code === rideStop.gtfsStopCode?.toString())
73+
stops.some((b) => b.code === rideStop.gtfsStopCode?.toString())
7474
) {
7575
return
7676
}

src/hooks/useConstrainedFloatingButton.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ export function useConstrainedFloatingButton(
9696
intersectionObserver.observe(mapContainerRef.current)
9797
}
9898

99-
window.document
99+
globalThis.document
100100
.getElementsByClassName('ant-layout-content')
101101
.item(0)
102102
?.addEventListener('scroll', updateButtonPosition)
103-
window.addEventListener('resize', updateButtonPosition)
103+
globalThis.addEventListener('resize', updateButtonPosition)
104104

105105
return () => {
106106
if (intersectionObserver) {
107107
intersectionObserver.disconnect()
108108
}
109-
window.document
109+
globalThis.document
110110
.getElementsByClassName('ant-layout-content')
111111
.item(0)
112112
?.removeEventListener('scroll', updateButtonPosition)
113-
window.removeEventListener('resize', updateButtonPosition)
113+
globalThis.removeEventListener('resize', updateButtonPosition)
114114
}
115115
}, [mapContainerRef, buttonRef, isExpanded])
116116
}

src/hooks/useSingleLineData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const useSingleLineData = (
2121
) => {
2222
const { search, setSearch } = useContext(SearchContext)
2323
const [routes, setRoutes] = useState<BusRoute[] | undefined>(search.routes)
24-
const [routeKey, _setRouteKey] = useState<string | undefined>(search.routeKey)
24+
const [routeKey, setRouteKeyState] = useState<string | undefined>(search.routeKey)
2525
const [filteredPositions, setFilteredPositions] = useState<Point[]>([])
2626
const [plannedRouteStops, setPlannedRouteStops] = useState<BusStop[]>([])
2727
const [options, setOptions] = useState<{ value: string; label: string }[]>([])
@@ -37,7 +37,7 @@ export const useSingleLineData = (
3737

3838
const setRouteKey = useCallback(
3939
(routeKey?: string) => {
40-
_setRouteKey(routeKey)
40+
setRouteKeyState(routeKey)
4141
setSearch((prev) => ({ ...prev, routeKey }))
4242
},
4343
[setSearch],

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import './locale/allTranslations'
99
import './index.scss'
1010

1111
const persister = createAsyncStoragePersister({
12-
storage: window.localStorage,
12+
storage: globalThis.localStorage,
1313
})
1414

1515
const queryClient = new QueryClient({

src/layout/LayoutContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, FC, PropsWithChildren, useState } from 'react'
1+
import { createContext, FC, PropsWithChildren, useMemo, useState } from 'react'
22

33
export interface LayoutContextInterface {
44
setDrawerOpen: (isOpen: boolean) => void
@@ -7,6 +7,7 @@ export interface LayoutContextInterface {
77
export const LayoutCtx = createContext({} as LayoutContextInterface)
88
const LayoutContext: FC<PropsWithChildren> = ({ children }) => {
99
const [drawerOpen, setDrawerOpen] = useState(false)
10-
return <LayoutCtx.Provider value={{ drawerOpen, setDrawerOpen }}>{children}</LayoutCtx.Provider>
10+
const value = useMemo(() => ({ drawerOpen, setDrawerOpen }), [drawerOpen])
11+
return <LayoutCtx.Provider value={value}>{children}</LayoutCtx.Provider>
1112
}
1213
export default LayoutContext

src/layout/ThemeContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const ThemeContext = createContext<ThemeContextInterface>({} as ThemeContextInte
3232
export const ThemeProvider = ({ children }: PropsWithChildren) => {
3333
const [isDarkTheme, setIsDarkTheme] = useLocalStorage<boolean>(
3434
'isDarkTheme',
35-
window.matchMedia('(prefers-color-scheme: dark)').matches,
35+
globalThis.matchMedia('(prefers-color-scheme: dark)').matches,
3636
)
3737
const [language, setLanguage] = useLocalStorage<string>('language', 'he')
3838
const { i18n } = useTranslation()

0 commit comments

Comments
 (0)