Skip to content

Commit af2ad32

Browse files
fix(chore): fix sonar code smells (#122)
* fix(chore): fixing sonar smells resolving sonar smells to improve quality gate GH-111 * fix(chore): fix sonar code smells Resolving sonar code smells to improve quality gate GH-111 * fix(chore): fix sonar code smells Resolving sonar smells to improve quality gate GH-111 --------- Co-authored-by: Raghav <[email protected]>
1 parent 2a7eec3 commit af2ad32

File tree

8 files changed

+55
-55
lines changed

8 files changed

+55
-55
lines changed

.sonarcloud.properties

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Path to sources
2+
sonar.sources=src
3+
sonar.exclusions=src/__tests__/**
4+
#sonar.inclusions=
5+
# Path to tests
6+
sonar.tests=src/__tests__
7+
#sonar.test.exclusions=
8+
#sonar.test.inclusions=
9+
# Source encoding
10+
sonar.sourceEncoding=UTF-8
11+
# Exclusions for copy-paste detection
12+
#sonar.cpd.exclusions=

src/providers/push/apns/apns.provider.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import {inject, Provider} from '@loopback/core';
2+
import {AnyObject} from '@loopback/repository';
23
import {HttpErrors} from '@loopback/rest';
34
import apns from '@parse/node-apn';
45
import {ApnsBinding} from './keys';
56
import {ApnsConfigType, ApnsMessage, ApnsSubscriberType} from './types';
6-
// sonarignore:start
7-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8-
export class ApnsProvider implements Provider<any> {
9-
// sonarignore:end
7+
8+
export class ApnsProvider implements Provider<AnyObject> {
109
constructor(
1110
@inject(ApnsBinding.Config, {
1211
optional: true,
@@ -37,7 +36,8 @@ export class ApnsProvider implements Provider<any> {
3736
);
3837
}
3938

40-
if (message.receiver.to.length > 500) {
39+
const maxReceivers = 500;
40+
if (message.receiver.to.length > maxReceivers) {
4141
throw new HttpErrors.BadRequest(
4242
'Message receiver count cannot exceed 500 !',
4343
);
@@ -47,9 +47,12 @@ export class ApnsProvider implements Provider<any> {
4747
}
4848
}
4949
getMainNote(message: ApnsMessage) {
50+
const expiresIn = 3600; // seconds
51+
const floor = 1000;
52+
const defaultBadgeCount = 3;
5053
const note = new apns.Notification();
51-
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
52-
note.badge = this.apnsConfig?.options.badge ?? 3;
54+
note.expiry = Math.floor(Date.now() / floor) + expiresIn; // Expires 1 hour from now.
55+
note.badge = this.apnsConfig?.options.badge ?? defaultBadgeCount;
5356
note.alert = message.body;
5457
note.payload = {messageFrom: message.options.messageFrom};
5558
// The topic is usually the bundle identifier of your application.

src/providers/push/apns/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {AnyObject} from '@loopback/repository';
12
import {ProviderOptions} from '@parse/node-apn';
23
import {
34
PushMessage,
@@ -20,12 +21,7 @@ export interface ApnsConfigType {
2021

2122
export interface ApnsMessage extends PushMessage {
2223
receiver: ApnsReceiver;
23-
// sonarignore:start
24-
options: {
25-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26-
[key: string]: any;
27-
};
28-
// sonarignore:end
24+
options: AnyObject;
2925
}
3026
export interface ApnsReceiver extends PushReceiver {
3127
to: ApnsSubscriber[];

src/providers/push/fcm/fcm.provider.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class FcmProvider implements Provider<FcmNotification> {
2222
fcmService: admin.app.App;
2323

2424
initialValidations(message: FcmMessage) {
25+
const maxReceivers = 500;
2526
if (
2627
message.receiver.to.length === 0 &&
2728
!message.options.topic &&
@@ -31,8 +32,7 @@ export class FcmProvider implements Provider<FcmNotification> {
3132
'Message receiver, topic or condition not found in request !',
3233
);
3334
}
34-
35-
if (message.receiver.to.length > 500) {
35+
if (message.receiver.to.length > maxReceivers) {
3636
throw new HttpErrors.BadRequest(
3737
'Message receiver count cannot exceed 500 !',
3838
);
@@ -69,11 +69,12 @@ export class FcmProvider implements Provider<FcmNotification> {
6969
...generalMessageObj,
7070
data: {...message.options.data},
7171
};
72-
promises.push(
73-
this.fcmService
74-
.messaging()
75-
.sendMulticast(msgToTransfer, (message.options.dryRun = false)),
76-
);
72+
73+
const dryRun = message.options.dryRun ?? false;
74+
const sendPromise = this.fcmService
75+
.messaging()
76+
.sendMulticast(msgToTransfer, dryRun);
77+
promises.push(sendPromise);
7778
}
7879
return promises;
7980
}
@@ -94,11 +95,11 @@ export class FcmProvider implements Provider<FcmNotification> {
9495
data: {...message.options.data},
9596
};
9697

97-
promises.push(
98-
this.fcmService
99-
.messaging()
100-
.send(msgToTransfer, (message.options.dryRun = false)),
101-
);
98+
const dryRun = message.options.dryRun ?? false;
99+
const sendPromise = this.fcmService
100+
.messaging()
101+
.send(msgToTransfer, dryRun);
102+
promises.push(sendPromise);
102103
});
103104
}
104105

@@ -123,11 +124,11 @@ export class FcmProvider implements Provider<FcmNotification> {
123124
...generalMessageObj,
124125
data: {...message.options.data},
125126
};
126-
promises.push(
127-
this.fcmService
128-
.messaging()
129-
.send(msgToTransfer, (message.options.dryRun = false)),
130-
);
127+
const dryRun = message.options.dryRun ?? false;
128+
const sendPromise = this.fcmService
129+
.messaging()
130+
.send(msgToTransfer, dryRun);
131+
promises.push(sendPromise);
131132
});
132133
}
133134

src/providers/push/fcm/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ export interface FcmMessage extends PushMessage {
3636
webpush?: admin.messaging.WebpushConfig;
3737
apns?: admin.messaging.ApnsConfig;
3838
fcmOptions?: admin.messaging.FcmOptions;
39-
// sonarignore:start
40-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
41-
[key: string]: any;
42-
// sonarignore:end
39+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
40+
[key: string]: any; //NOSONAR
4341
};
4442
}
4543

src/providers/push/pubnub/pubnub.provider.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import {inject, Provider} from '@loopback/core';
22
import {HttpErrors} from '@loopback/rest';
33
import Pubnub from 'pubnub';
44
import {Aps, MessageConfig, PnApns, TargetsType} from '.';
5-
import {PayloadType} from './types';
65
import {Config} from '../../../types';
76
import {PubnubBindings} from './keys';
8-
import {PubNubMessage, PubNubNotification, PubNubSubscriberType} from './types';
7+
import {
8+
PayloadType,
9+
PubNubMessage,
10+
PubNubNotification,
11+
PubNubSubscriberType,
12+
} from './types';
913

1014
export class PubNubProvider implements Provider<PubNubNotification> {
1115
constructor(
@@ -56,10 +60,6 @@ export class PubNubProvider implements Provider<PubNubNotification> {
5660
aps: apsData,
5761
pnPush: targetTypeData,
5862
};
59-
// const generalMessageObj = {
60-
// pn_gcm: pn_gcm,
61-
// pn_apns: Object.assign(pn_apns, message.options),
62-
// };
6363
return {pnGcm: pnGcm, pnApns: Object.assign(pnApns, message.options)};
6464
}
6565
getPublishConfig(message: PubNubMessage) {

src/providers/push/socketio/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {AnyObject} from '@loopback/repository';
12
import {
23
PushMessage,
34
PushNotification,
@@ -32,10 +33,5 @@ export interface SocketConfig {
3233
* Path represents the default socket server endpoint
3334
*/
3435
defaultPath: string;
35-
options: {
36-
// sonarignore:start
37-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
38-
[key: string]: any;
39-
// sonarignore:end
40-
};
36+
options: AnyObject;
4137
}

src/types.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {AnyObject} from '@loopback/repository';
12
export interface INotification {
23
publish(message: Message): Promise<void>;
34
}
@@ -22,20 +23,13 @@ export interface Config {
2223
options?: MessageOptions;
2324
}
2425

25-
export interface MessageOptions {
26-
// sonarignore:start
27-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
28-
[key: string]: any;
29-
// sonarignore:end
30-
}
26+
export type MessageOptions = AnyObject;
3127

3228
export interface Subscriber {
3329
id: string;
3430
name?: string;
35-
// sonarignore:start
3631
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37-
[key: string]: any;
38-
// sonarignore:end
32+
[key: string]: any; //NOSONAR
3933
}
4034

4135
export interface Receiver {

0 commit comments

Comments
 (0)