Skip to content

Commit 1b889c3

Browse files
fix: resolve SonarCloud code smells in TypeScript conversions
- Replace deprecated e.returnValue with e.preventDefault() in beforeunload handler - Convert WebWorker class to factory function to fix constructor return issue - Export both createWebWorker and WebWorker for backward compatibility - Address 'Unexpected class with only a constructor' code smell - Address 'Unexpected return statement in constructor' code smell Co-Authored-By: [email protected] <[email protected]>
1 parent c846534 commit 1b889c3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/components/AppStart/unload/addBeforeUnloadEventListener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function addBeforeUnloadEventListener(store: PlainReduxStore) {
1111

1212
if (store.getState().offline.outbox.length > 0) {
1313
const msg = 'Unsaved events!';
14-
e.returnValue = msg;
14+
e.preventDefault();
1515
return msg;
1616
}
1717
return undefined;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export class WebWorker {
2-
constructor(worker: string) {
3-
const code = worker.toString();
4-
const blob = new Blob([`(${code})()`]);
5-
return new Worker(URL.createObjectURL(blob));
6-
}
1+
export function createWebWorker(worker: string): Worker {
2+
const code = worker.toString();
3+
const blob = new Blob([`(${code})()`]);
4+
return new Worker(URL.createObjectURL(blob));
75
}
6+
7+
export const WebWorker = createWebWorker;

src/core_modules/capture-core-utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ export { pipe } from './misc/pipe';
33
export { buildUrl } from './misc';
44
export { makeCancelable as makeCancelablePromise } from './cancelablePromise';
55
export { chunk } from './chunk';
6-
export { WebWorker } from './WebWorker';
6+
export { createWebWorker, WebWorker } from './WebWorker';
77
export { useFeature, featureAvailable, FEATURES } from './featuresSupport';
88
export type { CaptureClientEvent } from './types/global';

0 commit comments

Comments
 (0)