Skip to content

Commit 4507871

Browse files
chore: Notification controller eslint cleanup (#7484)
## Explanation This PR addresses and removes ESLint suppressions in three files within `packages/notification-services-controller/src/NotificationServicesPushController`. The goal is to improve code quality and consistency by adhering to established linting rules. The changes include: * **Adding explicit return types** to functions to satisfy `@typescript-eslint/explicit-function-return-type`. * **Using the nullish coalescing operator (`??`)** to fix `@typescript-eslint/prefer-nullish-coalescing`. * **Renaming short, non-descriptive identifiers** (e.g., `num` to `numericValue`, `t` to `translate`, `n` to `notification`) to resolve `id-denylist` and `id-length` violations. * **Refactoring generic type parameters** (e.g., `N` to `TNotification`, `K` to `TriggerType`/`TKey`) for better clarity and to fix `@typescript-eslint/naming-convention`. * **Adding an `eslint-disable` comment** with an explanation for the `registration_token` property in `services.ts`. Its `snake_case` naming is dictated by an external API contract, making a code change impractical. * **Removing all corresponding entries** from `eslint-suppressions.json`. ## References * Fixes ASSETS-2100 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate (Functional tests pass, coverage thresholds are a separate issue) - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] 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-9abd1f11-e0c0-4df0-bb89-cfd2727b98b5"><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-9abd1f11-e0c0-4df0-bb89-cfd2727b98b5"><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] > Tightens TypeScript types and naming in NotificationServicesPushController utilities/services, adds a justified snake_case exception for `registration_token`, and removes related ESLint suppressions. > > - **Notification Services (push)**: > - `utils/get-notification-data.ts`: > - Add explicit return types (`calcTokenAmount: BigNumber`, `getLeadingZeroCount: number`, `formatAmount: string`, `getAmount: string`). > - Use nullish coalescing in parsing; type `handleShouldEllipse` and options. > - Rename params/vars for clarity (e.g., `num` → `numericValue`). > - `utils/get-notification-message.ts`: > - Strengthen generics and parameter names (`N/K` → `TNotification/TKey`, `n` → `notification`, `t` → `translate`). > - Add explicit return types across helpers and message creators; type `getChainSymbol`. > - `services/services.ts`: > - Document API contract and add ESLint naming exception for `registration_token` in `PushTokenRequest`. > - **Lint**: > - Remove corresponding entries from `eslint-suppressions.json` for the updated files. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8dfbc12. 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 6410b13 commit 4507871

File tree

4 files changed

+133
-126
lines changed

4 files changed

+133
-126
lines changed

eslint-suppressions.json

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,33 +1578,6 @@
15781578
"count": 70
15791579
}
15801580
},
1581-
"packages/notification-services-controller/src/NotificationServicesPushController/services/services.ts": {
1582-
"@typescript-eslint/naming-convention": {
1583-
"count": 1
1584-
}
1585-
},
1586-
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-data.ts": {
1587-
"@typescript-eslint/explicit-function-return-type": {
1588-
"count": 5
1589-
},
1590-
"@typescript-eslint/prefer-nullish-coalescing": {
1591-
"count": 1
1592-
},
1593-
"id-denylist": {
1594-
"count": 1
1595-
}
1596-
},
1597-
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts": {
1598-
"@typescript-eslint/explicit-function-return-type": {
1599-
"count": 5
1600-
},
1601-
"@typescript-eslint/naming-convention": {
1602-
"count": 2
1603-
},
1604-
"id-length": {
1605-
"count": 9
1606-
}
1607-
},
16081581
"packages/phishing-controller/src/BulkTokenScan.test.ts": {
16091582
"@typescript-eslint/explicit-function-return-type": {
16101583
"count": 2

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export type RegToken = {
1818
*/
1919
export type PushTokenRequest = {
2020
addresses: string[];
21+
// API response uses snake_case for this property
22+
// eslint-disable-next-line @typescript-eslint/naming-convention
2123
registration_token: {
2224
token: string;
2325
platform: 'extension' | 'mobile' | 'portfolio';

packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-data.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const defaultFormatOptions = {
1515
* @param decimals - The number of decimals to use for the calculation.
1616
* @returns The calculated token amount.
1717
*/
18-
export function calcTokenAmount(value: string, decimals: number) {
18+
export function calcTokenAmount(value: string, decimals: number): BigNumber {
1919
const multiplier = Math.pow(10, Number(decimals || 0));
2020
return new BigNumber(String(value)).div(multiplier);
2121
}
@@ -28,14 +28,14 @@ export function calcTokenAmount(value: string, decimals: number) {
2828
* fractional part of the number. This is useful for determining the precision
2929
* of very small numbers.
3030
*
31-
* @param num - The number to analyze, which can be in the form
31+
* @param numericValue - The number to analyze, which can be in the form
3232
* of a number or a string.
3333
* @returns The count of leading zeros in the fractional part of the number.
3434
*/
35-
export const getLeadingZeroCount = (num: number | string) => {
36-
const numToString = new BigNumber(num, 10).toString(10);
35+
export const getLeadingZeroCount = (numericValue: number | string): number => {
36+
const numToString = new BigNumber(numericValue, 10).toString(10);
3737
const fractionalPart = numToString.split('.')[1] ?? '';
38-
return fractionalPart.match(/^0*/u)?.[0]?.length || 0;
38+
return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;
3939
};
4040

4141
/**
@@ -50,15 +50,18 @@ export const getLeadingZeroCount = (num: number | string) => {
5050
* @param opts - The options to use when formatting
5151
* @returns The formatted number
5252
*/
53-
export const formatAmount = (numericAmount: number, opts?: FormatOptions) => {
53+
export const formatAmount = (
54+
numericAmount: number,
55+
opts?: FormatOptions,
56+
): string => {
5457
// create options with defaults
5558
const options = { ...defaultFormatOptions, ...opts };
5659

5760
const leadingZeros = getLeadingZeroCount(numericAmount);
5861
const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;
5962
const isLargeNumber = numericAmount > 999;
6063

61-
const handleShouldEllipse = (decimalPlaces: number) =>
64+
const handleShouldEllipse = (decimalPlaces: number): boolean =>
6265
Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;
6366

6467
if (isLargeNumber) {
@@ -87,7 +90,7 @@ export const getAmount = (
8790
amount: string,
8891
decimals: string,
8992
options?: FormatOptions,
90-
) => {
93+
): string => {
9194
if (!amount || !decimals) {
9295
return '';
9396
}

0 commit comments

Comments
 (0)