Skip to content

Commit 69dd293

Browse files
chore: Notification services controller lint cleanup (#7481)
## Explanation * **What is the current state of things and why does it need to change?** The `packages/notification-services-controller` contained ESLint suppressions for `@typescript-eslint/explicit-function-return-type` and `@typescript-eslint/prefer-nullish-coalescing`. These suppressions indicated areas where type safety and modern JavaScript practices were not fully enforced, leading to potential maintainability issues and reduced code clarity. * **What is the solution your changes offer and how does it work?** This PR addresses these suppressions by: 1. Adding explicit return types to functions in `NotificationServicesPushController.test.ts`, `NotificationServicesPushController.ts`, and `__fixtures__/mockServices.ts` to satisfy the `@typescript-eslint/explicit-function-return-type` rule. 2. Replacing a logical OR (`||`) with the nullish coalescing operator (`??`) in `NotificationServicesPushController.test.ts` to fix the `@typescript-eslint/prefer-nullish-coalescing` rule. 3. Removing the corresponding entries for these files and rules from `eslint-suppressions.json`. * **Are there any changes whose purpose might not obvious to those unfamiliar with the domain?** No, the changes are straightforward type annotations and a minor logical operator update. ## References * Fixes ASSETS-2100 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them --- <a href="https://cursor.com/background-agent?bcId=bc-3ab73ae3-3c32-47f2-84e5-d8b16738a68d"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/open-in-cursor-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/open-in-cursor-light.svg"><img alt="Open in Cursor" src="https://cursor.com/open-in-cursor.svg"></picture></a>&nbsp;<a href="https://cursor.com/agents?id=bc-3ab73ae3-3c32-47f2-84e5-d8b16738a68d"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/open-in-web-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/open-in-web-light.svg"><img alt="Open in Web" src="https://cursor.com/open-in-web.svg"></picture></a> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds explicit return types across NotificationServicesPushController code/tests, adopts nullish coalescing in tests, and removes related ESLint suppressions. > > - **Notification Services Push Controller**: > - Add explicit return types to `#getAndAssertBearerToken`, `#updatePushState`, `subscribeToPushNotifications`, `enablePushNotifications`, `disablePushNotifications`, and `updateTriggerPushNotifications` in `NotificationServicesPushController.ts`. > - **Tests**: > - Add explicit return types to helpers (`mockErrorLog`, `arrangeServicesMocks`, `arrangeMockMessenger`, `mockAuthBearerTokenCall`) and improve Jest typings in `NotificationServicesPushController.test.ts`. > - Use nullish coalescing (`??`) for config defaults. > - **Mocks**: > - Add return type to `mockEndpointUpdatePushNotificationLinks` in `__fixtures__/mockServices.ts`. > - **ESLint**: > - Remove suppressions for `@typescript-eslint/explicit-function-return-type` and `@typescript-eslint/prefer-nullish-coalescing` entries related to these files in `eslint-suppressions.json`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit f5e64a1. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 30c8a38 commit 69dd293

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

eslint-suppressions.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,24 +1593,6 @@
15931593
"count": 70
15941594
}
15951595
},
1596-
"packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts": {
1597-
"@typescript-eslint/explicit-function-return-type": {
1598-
"count": 4
1599-
},
1600-
"@typescript-eslint/prefer-nullish-coalescing": {
1601-
"count": 1
1602-
}
1603-
},
1604-
"packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts": {
1605-
"@typescript-eslint/explicit-function-return-type": {
1606-
"count": 6
1607-
}
1608-
},
1609-
"packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts": {
1610-
"@typescript-eslint/explicit-function-return-type": {
1611-
"count": 1
1612-
}
1613-
},
16141596
"packages/notification-services-controller/src/NotificationServicesPushController/services/services.ts": {
16151597
"@typescript-eslint/naming-convention": {
16161598
"count": 1

packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.test.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ const MOCK_FCM_TOKEN = 'mockFcmToken';
1616
const MOCK_ADDRESSES = ['0x123', '0x456', '0x789'];
1717

1818
// Testing util to clean up verbose logs when testing errors
19-
const mockErrorLog = () =>
19+
const mockErrorLog = (): jest.SpyInstance =>
2020
jest.spyOn(log, 'error').mockImplementation(jest.fn());
2121

2222
describe('NotificationServicesPushController', () => {
23-
const arrangeServicesMocks = (token?: string) => {
23+
const arrangeServicesMocks = (
24+
token?: string,
25+
): {
26+
activatePushNotificationsMock: jest.SpyInstance;
27+
deactivatePushNotificationsMock: jest.SpyInstance;
28+
} => {
2429
const activatePushNotificationsMock = jest
2530
.spyOn(services, 'activatePushNotifications')
2631
.mockResolvedValue(token ?? MOCK_FCM_TOKEN);
@@ -359,8 +364,12 @@ function arrangeMockMessenger(
359364
state?: Partial<NotificationServicesPushController['state']>;
360365
}
361366
>,
362-
) {
363-
const { state: stateOverride, ...configOverride } = controllerConfig || {};
367+
): {
368+
controller: NotificationServicesPushController;
369+
initialState: NotificationServicesPushController['state'];
370+
messenger: NotificationServicesPushControllerMessenger;
371+
} {
372+
const { state: stateOverride, ...configOverride } = controllerConfig ?? {};
364373

365374
const config: ControllerConfig = {
366375
isPushFeatureEnabled: true,
@@ -403,7 +412,14 @@ function arrangeMockMessenger(
403412
*/
404413
function mockAuthBearerTokenCall(
405414
messenger: NotificationServicesPushControllerMessenger,
406-
) {
415+
): jest.Mock<
416+
ReturnType<
417+
AuthenticationController.AuthenticationControllerGetBearerToken['handler']
418+
>,
419+
Parameters<
420+
AuthenticationController.AuthenticationControllerGetBearerToken['handler']
421+
>
422+
> {
407423
type Fn =
408424
AuthenticationController.AuthenticationControllerGetBearerToken['handler'];
409425
const mockAuthGetBearerToken = jest

packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export default class NotificationServicesPushController extends BaseController<
225225
});
226226
}
227227

228-
async #getAndAssertBearerToken() {
228+
async #getAndAssertBearerToken(): Promise<string> {
229229
const bearerToken = await this.messenger.call(
230230
'AuthenticationController:getBearerToken',
231231
);
@@ -239,7 +239,7 @@ export default class NotificationServicesPushController extends BaseController<
239239
return bearerToken;
240240
}
241241

242-
#updatePushState(command: StateCommand) {
242+
#updatePushState(command: StateCommand): void {
243243
if (command.type === 'enable') {
244244
this.update((state) => {
245245
state.isPushEnabled = true;
@@ -266,7 +266,7 @@ export default class NotificationServicesPushController extends BaseController<
266266
}
267267
}
268268

269-
public async subscribeToPushNotifications() {
269+
public async subscribeToPushNotifications(): Promise<void> {
270270
if (!this.#config.isPushFeatureEnabled) {
271271
return;
272272
}
@@ -296,7 +296,7 @@ export default class NotificationServicesPushController extends BaseController<
296296
*
297297
* @param addresses - An array of addresses to enable push notifications for.
298298
*/
299-
public async enablePushNotifications(addresses: string[]) {
299+
public async enablePushNotifications(addresses: string[]): Promise<void> {
300300
if (!this.#config.isPushFeatureEnabled) {
301301
return;
302302
}
@@ -351,7 +351,7 @@ export default class NotificationServicesPushController extends BaseController<
351351
* Disables push notifications for the application.
352352
* This removes the registration token on this device, and ensures we unsubscribe from any listeners
353353
*/
354-
public async disablePushNotifications() {
354+
public async disablePushNotifications(): Promise<void> {
355355
if (!this.#config.isPushFeatureEnabled) {
356356
return;
357357
}
@@ -394,7 +394,9 @@ export default class NotificationServicesPushController extends BaseController<
394394
* @param addresses - An array of addresses that should trigger push notifications.
395395
* @deprecated - this is not used anymore and will most likely be removed
396396
*/
397-
public async updateTriggerPushNotifications(addresses: string[]) {
397+
public async updateTriggerPushNotifications(
398+
addresses: string[],
399+
): Promise<void> {
398400
if (!this.#config.isPushFeatureEnabled) {
399401
return;
400402
}

packages/notification-services-controller/src/NotificationServicesPushController/__fixtures__/mockServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type MockReply = {
99

1010
export const mockEndpointUpdatePushNotificationLinks = (
1111
mockReply?: MockReply,
12-
) => {
12+
): nock.Scope => {
1313
const mockResponse = getMockUpdatePushNotificationLinksResponse();
1414
const reply = mockReply ?? {
1515
status: 204,

0 commit comments

Comments
 (0)