Skip to content

Commit

Permalink
refactor: resolve notification-services lint warnings (#5293)
Browse files Browse the repository at this point in the history
## Explanation

Resolves ESLint warnings in the notification services controller. This
does not change any code that impacts users.

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

### `@metamask/notification-services-controller`

- _There is no user facing changes_

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
  • Loading branch information
Prithpal-Sooriya authored Feb 6, 2025
1 parent 5a84609 commit db856fc
Show file tree
Hide file tree
Showing 38 changed files with 89 additions and 185 deletions.
108 changes: 0 additions & 108 deletions eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -447,114 +447,6 @@
"packages/network-controller/tests/provider-api-tests/no-block-param.ts": {
"jest/no-conditional-in-test": 2
},
"packages/notification-services-controller/jest.environment.js": {
"n/no-unsupported-features/node-builtins": 1,
"n/prefer-global/text-encoder": 1,
"n/prefer-global/text-decoder": 1,
"no-shadow": 2
},
"packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mock-raw-notifications.ts": {
"jsdoc/tag-lines": 22
},
"packages/notification-services-controller/src/NotificationServicesController/__fixtures__/mockResponses.ts": {
"import-x/order": 2
},
"packages/notification-services-controller/src/NotificationServicesController/__fixtures__/test-utils.ts": {
"@typescript-eslint/no-unused-vars": 1
},
"packages/notification-services-controller/src/NotificationServicesController/index.ts": {
"@typescript-eslint/consistent-type-exports": 2
},
"packages/notification-services-controller/src/NotificationServicesController/processors/process-feature-announcement.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/processors/process-notifications.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/processors/process-notifications.ts": {
"import-x/order": 3
},
"packages/notification-services-controller/src/NotificationServicesController/processors/process-onchain-notifications.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/processors/process-snap-notifications.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts": {
"jsdoc/tag-lines": 1
},
"packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/feature-announcement.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/feature-announcement/index.ts": {
"@typescript-eslint/consistent-type-exports": 3
},
"packages/notification-services-controller/src/NotificationServicesController/types/index.ts": {
"@typescript-eslint/consistent-type-exports": 5
},
"packages/notification-services-controller/src/NotificationServicesController/types/notification/index.ts": {
"@typescript-eslint/consistent-type-exports": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/index.ts": {
"@typescript-eslint/consistent-type-exports": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/on-chain-notification.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/on-chain-notification/schema.ts": {
"jsdoc/check-tag-names": 21,
"jsdoc/tag-lines": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/snaps/index.ts": {
"@typescript-eslint/consistent-type-exports": 1
},
"packages/notification-services-controller/src/NotificationServicesController/types/user-storage/index.ts": {
"@typescript-eslint/consistent-type-exports": 1
},
"packages/notification-services-controller/src/NotificationServicesController/utils/utils.test.ts": {
"import-x/order": 1
},
"packages/notification-services-controller/src/NotificationServicesController/utils/utils.ts": {
"@typescript-eslint/no-unsafe-enum-comparison": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/NotificationServicesPushController.ts": {
"@typescript-eslint/no-unused-vars": 1,
"@typescript-eslint/prefer-readonly": 2,
"import-x/order": 1,
"jsdoc/check-tag-names": 1
},
"packages/notification-services-controller/src/NotificationServicesPushController/index.ts": {
"@typescript-eslint/consistent-type-exports": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/services/push/push-web.test.ts": {
"import-x/order": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/services/push/push-web.ts": {
"@typescript-eslint/no-unused-vars": 1,
"jsdoc/tag-lines": 1
},
"packages/notification-services-controller/src/NotificationServicesPushController/services/services.test.ts": {
"import-x/order": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/services/services.ts": {
"import-x/order": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/types/index.ts": {
"@typescript-eslint/consistent-type-exports": 1
},
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts": {
"import-x/order": 2
},
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts": {
"@typescript-eslint/no-unused-vars": 1,
"import-x/order": 1
},
"packages/permission-controller/src/Permission.ts": {
"prettier/prettier": 11
},
Expand Down
4 changes: 4 additions & 0 deletions packages/notification-services-controller/jest.environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ class CustomTestEnvironment extends JSDOMEnvironment {
async setup() {
await super.setup();

// jest runs in a node environment, so need to polyfil webAPIs
// eslint-disable-next-line no-shadow, n/prefer-global/text-encoder, n/prefer-global/text-decoder
const { TextEncoder, TextDecoder } = require('util');
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
this.global.ArrayBuffer = ArrayBuffer;
this.global.Uint8Array = Uint8Array;

if (typeof this.global.crypto === 'undefined') {
// jest runs in a node environment, so need to polyfil webAPIs
// eslint-disable-next-line n/no-unsupported-features/node-builtins
this.global.crypto = require('crypto').webcrypto;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { TRIGGER_TYPES } from '../constants/notification-schema';
import type { OnChainRawNotification } from '../types/on-chain-notification/on-chain-notification';

/**
* Mocking Utility - create a mock Eth sent notification
*
* @returns Mock raw Eth sent notification
*/
export function createMockNotificationEthSent(): OnChainRawNotification {
Expand Down Expand Up @@ -39,6 +39,7 @@ export function createMockNotificationEthSent(): OnChainRawNotification {

/**
* Mocking Utility - create a mock Eth Received notification
*
* @returns Mock raw Eth Received notification
*/
export function createMockNotificationEthReceived(): OnChainRawNotification {
Expand Down Expand Up @@ -74,6 +75,7 @@ export function createMockNotificationEthReceived(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC20 sent notification
*
* @returns Mock raw ERC20 sent notification
*/
export function createMockNotificationERC20Sent(): OnChainRawNotification {
Expand Down Expand Up @@ -115,6 +117,7 @@ export function createMockNotificationERC20Sent(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC20 received notification
*
* @returns Mock raw ERC20 received notification
*/
export function createMockNotificationERC20Received(): OnChainRawNotification {
Expand Down Expand Up @@ -156,6 +159,7 @@ export function createMockNotificationERC20Received(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC721 sent notification
*
* @returns Mock raw ERC721 sent notification
*/
export function createMockNotificationERC721Sent(): OnChainRawNotification {
Expand Down Expand Up @@ -200,6 +204,7 @@ export function createMockNotificationERC721Sent(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC721 received notification
*
* @returns Mock raw ERC721 received notification
*/
export function createMockNotificationERC721Received(): OnChainRawNotification {
Expand Down Expand Up @@ -244,6 +249,7 @@ export function createMockNotificationERC721Received(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC1155 sent notification
*
* @returns Mock raw ERC1155 sent notification
*/
export function createMockNotificationERC1155Sent(): OnChainRawNotification {
Expand Down Expand Up @@ -288,6 +294,7 @@ export function createMockNotificationERC1155Sent(): OnChainRawNotification {

/**
* Mocking Utility - create a mock ERC1155 received notification
*
* @returns Mock raw ERC1155 received notification
*/
export function createMockNotificationERC1155Received(): OnChainRawNotification {
Expand Down Expand Up @@ -332,6 +339,7 @@ export function createMockNotificationERC1155Received(): OnChainRawNotification

/**
* Mocking Utility - create a mock MetaMask Swaps notification
*
* @returns Mock raw MetaMask Swaps notification
*/
export function createMockNotificationMetaMaskSwapsCompleted(): OnChainRawNotification {
Expand Down Expand Up @@ -382,6 +390,7 @@ export function createMockNotificationMetaMaskSwapsCompleted(): OnChainRawNotifi

/**
* Mocking Utility - create a mock RocketPool Stake Completed notification
*
* @returns Mock raw RocketPool Stake Completed notification
*/
export function createMockNotificationRocketPoolStakeCompleted(): OnChainRawNotification {
Expand Down Expand Up @@ -431,6 +440,7 @@ export function createMockNotificationRocketPoolStakeCompleted(): OnChainRawNoti

/**
* Mocking Utility - create a mock RocketPool Un-staked notification
*
* @returns Mock raw RocketPool Un-staked notification
*/
export function createMockNotificationRocketPoolUnStakeCompleted(): OnChainRawNotification {
Expand Down Expand Up @@ -480,6 +490,7 @@ export function createMockNotificationRocketPoolUnStakeCompleted(): OnChainRawNo

/**
* Mocking Utility - create a mock Lido Stake Completed notification
*
* @returns Mock raw Lido Stake Completed notification
*/
export function createMockNotificationLidoStakeCompleted(): OnChainRawNotification {
Expand Down Expand Up @@ -529,6 +540,7 @@ export function createMockNotificationLidoStakeCompleted(): OnChainRawNotificati

/**
* Mocking Utility - create a mock Lido Withdrawal Requested notification
*
* @returns Mock raw Lido Withdrawal Requested notification
*/
export function createMockNotificationLidoWithdrawalRequested(): OnChainRawNotification {
Expand Down Expand Up @@ -578,6 +590,7 @@ export function createMockNotificationLidoWithdrawalRequested(): OnChainRawNotif

/**
* Mocking Utility - create a mock Lido Withdrawal Completed notification
*
* @returns Mock raw Lido Withdrawal Completed notification
*/
export function createMockNotificationLidoWithdrawalCompleted(): OnChainRawNotification {
Expand Down Expand Up @@ -627,6 +640,7 @@ export function createMockNotificationLidoWithdrawalCompleted(): OnChainRawNotif

/**
* Mocking Utility - create a mock Lido Withdrawal Ready notification
*
* @returns Mock raw Lido Withdrawal Ready notification
*/
export function createMockNotificationLidoReadyToBeWithdrawn(): OnChainRawNotification {
Expand Down Expand Up @@ -663,6 +677,7 @@ export function createMockNotificationLidoReadyToBeWithdrawn(): OnChainRawNotifi

/**
* Mocking Utility - create a mock Aave V3 Health Factor notification
*
* @returns Mock raw Aave V3 Health Factor notification
*/
export function createMockNotificationAaveV3HealthFactor(): OnChainRawNotification {
Expand All @@ -687,6 +702,7 @@ export function createMockNotificationAaveV3HealthFactor(): OnChainRawNotificati

/**
* Mocking Utility - create a mock ENS Expiration notification
*
* @returns Mock raw ENS Expiration notification
*/
export function createMockNotificationEnsExpiration(): OnChainRawNotification {
Expand All @@ -712,6 +728,7 @@ export function createMockNotificationEnsExpiration(): OnChainRawNotification {

/**
* Mocking Utility - create a mock Lido Staking Rewards notification
*
* @returns Mock raw Lido Staking Rewards notification
*/
export function createMockNotificationLidoStakingRewards(): OnChainRawNotification {
Expand Down Expand Up @@ -739,6 +756,7 @@ export function createMockNotificationLidoStakingRewards(): OnChainRawNotificati

/**
* Mocking Utility - create a mock Notional Loan Expiration notification
*
* @returns Mock raw Notional Loan Expiration notification
*/
export function createMockNotificationNotionalLoanExpiration(): OnChainRawNotification {
Expand Down Expand Up @@ -769,6 +787,7 @@ export function createMockNotificationNotionalLoanExpiration(): OnChainRawNotifi

/**
* Mocking Utility - create a mock Rocketpool Staking Rewards notification
*
* @returns Mock raw Rocketpool Staking Rewards notification
*/
export function createMockNotificationRocketpoolStakingRewards(): OnChainRawNotification {
Expand Down Expand Up @@ -796,6 +815,7 @@ export function createMockNotificationRocketpoolStakingRewards(): OnChainRawNoti

/**
* Mocking Utility - create a mock SparkFi Health Factor notification
*
* @returns Mock raw SparkFi Health Factor notification
*/
export function createMockNotificationSparkFiHealthFactor(): OnChainRawNotification {
Expand All @@ -820,6 +840,7 @@ export function createMockNotificationSparkFiHealthFactor(): OnChainRawNotificat

/**
* Mocking Utility - creates an array of raw on-chain notifications
*
* @returns Array of raw on-chain notifications
*/
export function createMockRawOnChainNotifications(): OnChainRawNotification[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createMockFeatureAnnouncementAPIResult } from './mock-feature-announcements';
import { createMockRawOnChainNotifications } from './mock-raw-notifications';
import { FEATURE_ANNOUNCEMENT_API } from '../services/feature-announcements';
import {
NOTIFICATION_API_LIST_ENDPOINT,
NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
TRIGGER_API_BATCH_ENDPOINT,
} from '../services/onchain-notifications';
import { createMockFeatureAnnouncementAPIResult } from './mock-feature-announcements';
import { createMockRawOnChainNotifications } from './mock-raw-notifications';

type MockResponse = {
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const waitFor = async (
assertionFn();
clearInterval(intervalId);
resolve();
} catch (error) {
} catch {
if (Date.now() - startTime >= timeoutMs) {
clearInterval(intervalId);
reject(new Error(`waitFor: timeout reached after ${timeoutMs}ms`));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Compute } from '../types/type-utils';

/* eslint-disable @typescript-eslint/naming-convention */
export enum TRIGGER_TYPES {
FEATURES_ANNOUNCEMENT = 'features_announcement',
METAMASK_SWAP_COMPLETED = 'metamask_swap_completed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const NotificationServicesController = Controller;
export { Controller };
export default NotificationServicesController;
export * from './NotificationServicesController';
export * as Types from './types';
export * from './types';
export type * as Types from './types';
export type * from './types';
export * as Processors from './processors';
export * from './processors';
export * as Constants from './constants';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createMockFeatureAnnouncementRaw } from '../__fixtures__/mock-feature-announcements';
import { TRIGGER_TYPES } from '../constants/notification-schema';
import {
isFeatureAnnouncementRead,
processFeatureAnnouncement,
} from './process-feature-announcement';
import { createMockFeatureAnnouncementRaw } from '../__fixtures__/mock-feature-announcements';
import { TRIGGER_TYPES } from '../constants/notification-schema';

describe('process-feature-announcement - isFeatureAnnouncementRead()', () => {
const MOCK_NOTIFICATION_ID = 'MOCK_NOTIFICATION_ID';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { processNotification } from './process-notifications';
import { createMockFeatureAnnouncementRaw } from '../__fixtures__/mock-feature-announcements';
import { createMockNotificationEthSent } from '../__fixtures__/mock-raw-notifications';
import { createMockSnapNotification } from '../__fixtures__/mock-snap-notification';
import type { TRIGGER_TYPES } from '../constants/notification-schema';
import { processNotification } from './process-notifications';

describe('process-notifications - processNotification()', () => {
// More thorough tests are found in the specific process
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
isFeatureAnnouncementRead,
processFeatureAnnouncement,
} from './process-feature-announcement';
import { processOnChainNotification } from './process-onchain-notifications';
import { processSnapNotification } from './process-snap-notifications';
import { TRIGGER_TYPES } from '../constants/notification-schema';
import type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';
import type {
Expand All @@ -6,12 +12,6 @@ import type {
} from '../types/notification/notification';
import type { OnChainRawNotification } from '../types/on-chain-notification/on-chain-notification';
import type { RawSnapNotification } from '../types/snaps';
import {
isFeatureAnnouncementRead,
processFeatureAnnouncement,
} from './process-feature-announcement';
import { processOnChainNotification } from './process-onchain-notifications';
import { processSnapNotification } from './process-snap-notifications';

const isOnChainNotification = (
n: RawNotificationUnion,
Expand Down
Loading

0 comments on commit db856fc

Please sign in to comment.