Skip to content

Commit

Permalink
fix: eslint warnings & errors (#5261)
Browse files Browse the repository at this point in the history
## Explanation

This PR fixes ESlint warnings & errors for
`@metamask/profile-sync-controller`

## 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

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/profile-sync-controller`

- **FIXED**: ESlint warnings & errors

## 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
mathieuartu authored Feb 4, 2025
1 parent 11845aa commit d3d3d21
Show file tree
Hide file tree
Showing 53 changed files with 292 additions and 222 deletions.
30 changes: 14 additions & 16 deletions eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
"@typescript-eslint/no-base-to-string": 3,
"@typescript-eslint/no-duplicate-enum-values": 2,
"@typescript-eslint/no-unsafe-enum-comparison": 32,
"@typescript-eslint/no-unused-vars": 41,
"@typescript-eslint/no-unused-vars": 40,
"@typescript-eslint/prefer-promise-reject-errors": 33,
"@typescript-eslint/prefer-readonly": 138,
"@typescript-eslint/prefer-readonly": 123,
"import-x/namespace": 189,
"import-x/no-named-as-default": 1,
"import-x/no-named-as-default-member": 8,
"import-x/order": 202,
"jest/no-conditional-in-test": 113,
"jest/prefer-lowercase-title": 2,
"jest/prefer-strict-equal": 2,
"jsdoc/check-tag-names": 365,
"jsdoc/require-returns": 24,
"jsdoc/tag-lines": 327,
"n/no-unsupported-features/node-builtins": 4,
"n/prefer-global/text-encoder": 4,
"n/prefer-global/text-decoder": 4,
"prettier/prettier": 80,
"import-x/no-named-as-default-member": 7,
"import-x/order": 147,
"jest/no-conditional-in-test": 81,
"jsdoc/check-tag-names": 362,
"jsdoc/require-returns": 20,
"jsdoc/tag-lines": 281,
"n/no-unsupported-features/node-builtins": 2,
"n/prefer-global/text-encoder": 3,
"n/prefer-global/text-decoder": 3,
"prettier/prettier": 79,
"promise/always-return": 3,
"promise/catch-or-return": 2,
"promise/param-names": 8,
"promise/param-names": 6,
"no-empty-function": 2,
"no-shadow": 8,
"no-shadow": 6,
"no-unused-private-class-members": 5
}
4 changes: 4 additions & 0 deletions packages/profile-sync-controller/jest.environment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable n/prefer-global/text-encoder */
/* eslint-disable n/prefer-global/text-decoder */
const JSDOMEnvironment = require('jest-environment-jsdom');

/**
Expand All @@ -10,13 +12,15 @@ class CustomTestEnvironment extends JSDOMEnvironment {
async setup() {
await super.setup();

// eslint-disable-next-line no-shadow
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') {
// 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
Expand Up @@ -193,6 +193,7 @@ describe('authentication/authentication-controller - getBearerToken() tests', ()
const { messenger } = createMockAuthenticationMessenger();
mockAuthenticationFlowEndpoints();
const originalState = mockSignedInState();
// eslint-disable-next-line jest/no-conditional-in-test
if (originalState.sessionData) {
originalState.sessionData.accessToken = 'ACCESS_TOKEN_1';

Expand Down Expand Up @@ -222,6 +223,7 @@ describe('authentication/authentication-controller - getBearerToken() tests', ()

// Invalid/old state
const originalState = mockSignedInState();
// eslint-disable-next-line jest/no-conditional-in-test
if (originalState.sessionData) {
originalState.sessionData.accessToken = 'ACCESS_TOKEN_1';

Expand Down Expand Up @@ -280,6 +282,7 @@ describe('authentication/authentication-controller - getSessionProfile() tests',
const { messenger } = createMockAuthenticationMessenger();
mockAuthenticationFlowEndpoints();
const originalState = mockSignedInState();
// eslint-disable-next-line jest/no-conditional-in-test
if (originalState.sessionData) {
originalState.sessionData.profile.identifierId = 'ID_1';

Expand Down Expand Up @@ -310,6 +313,7 @@ describe('authentication/authentication-controller - getSessionProfile() tests',

// Invalid/old state
const originalState = mockSignedInState();
// eslint-disable-next-line jest/no-conditional-in-test
if (originalState.sessionData) {
originalState.sessionData.profile.identifierId = 'ID_1';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ export default class AuthenticationController extends BaseController<
AuthenticationControllerState,
AuthenticationControllerMessenger
> {
#metametrics: MetaMetricsAuth;
readonly #metametrics: MetaMetricsAuth;

#isUnlocked = false;

#keyringController = {
readonly #keyringController = {
setupLockedStateSubscriptions: () => {
const { isUnlocked } = this.messagingSystem.call(
'KeyringController:getState',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ export const MOCK_JWT =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
export const MOCK_LOGIN_RESPONSE: LoginResponse = {
token: MOCK_JWT,
// eslint-disable-next-line @typescript-eslint/naming-convention
expires_in: new Date().toString(),
profile: {
// eslint-disable-next-line @typescript-eslint/naming-convention
identifier_id: 'MOCK_IDENTIFIER',
// eslint-disable-next-line @typescript-eslint/naming-convention
profile_id: 'MOCK_PROFILE_ID',
},
};
Expand All @@ -52,9 +49,8 @@ export const getMockAuthLoginResponse = () => {

export const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;
export const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {
// eslint-disable-next-line @typescript-eslint/naming-convention
access_token: MOCK_ACCESS_TOKEN,
// eslint-disable-next-line @typescript-eslint/naming-convention

expires_in: new Date().getTime(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,20 @@ export async function getNonce(publicKey: string): Promise<string | null> {
*/
export type LoginResponse = {
token: string;
// eslint-disable-next-line @typescript-eslint/naming-convention

expires_in: string;
/**
* Contains anonymous information about the logged in profile.
*
* @property identifier_id - a deterministic unique identifier on the method used to sign in
* @property profile_id - a unique id for a given profile
* @property metametrics_id - an anonymous server id
* identifier_id - a deterministic unique identifier on the method used to sign in
*
* profile_id - a unique id for a given profile
*
* metametrics_id - an anonymous server id
*/
profile: {
// eslint-disable-next-line @typescript-eslint/naming-convention
identifier_id: string;
// eslint-disable-next-line @typescript-eslint/naming-convention

profile_id: string;
};
};
Expand Down Expand Up @@ -101,10 +102,9 @@ export async function login(
},
body: JSON.stringify({
signature,
// eslint-disable-next-line @typescript-eslint/naming-convention

raw_message: rawMessage,
metametrics: {
// eslint-disable-next-line @typescript-eslint/naming-convention
metametrics_id: clientMetaMetrics.metametricsId,
agent: clientMetaMetrics.agent,
},
Expand All @@ -130,9 +130,8 @@ export async function login(
* The Auth API Token Response Shape
*/
export type OAuthTokenResponse = {
// eslint-disable-next-line @typescript-eslint/naming-convention
access_token: string;
// eslint-disable-next-line @typescript-eslint/naming-convention

expires_in: number;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type nock from 'nock';

import { USER_STORAGE_FEATURE_NAMES } from '../../shared/storage-schema';
import { mockUserStorageMessenger } from './__fixtures__/mockMessenger';
import {
mockEndpointBatchUpsertUserStorage,
Expand All @@ -22,6 +21,7 @@ import * as AccountSyncControllerIntegrationModule from './account-syncing/contr
import * as NetworkSyncIntegrationModule from './network-syncing/controller-integration';
import type { UserStorageBaseOptions } from './services';
import UserStorageController, { defaultState } from './UserStorageController';
import { USER_STORAGE_FEATURE_NAMES } from '../../shared/storage-schema';

describe('user-storage/user-storage-controller - constructor() tests', () => {
const arrangeMocks = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ import type {
} from '@metamask/network-controller';
import type { HandleSnapRequest } from '@metamask/snaps-controllers';

import { createSHA256Hash } from '../../shared/encryption';
import type { UserStorageFeatureKeys } from '../../shared/storage-schema';
import {
type UserStoragePathWithFeatureAndKey,
type UserStoragePathWithFeatureOnly,
} from '../../shared/storage-schema';
import type { NativeScrypt } from '../../shared/types/encryption';
import { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';
import type {
AuthenticationControllerGetBearerToken,
AuthenticationControllerGetSessionProfile,
AuthenticationControllerIsSignedIn,
AuthenticationControllerPerformSignIn,
AuthenticationControllerPerformSignOut,
} from '../authentication/AuthenticationController';
import {
saveInternalAccountToUserStorage,
syncInternalAccountsWithUserStorage,
Expand All @@ -60,6 +45,21 @@ import {
getUserStorageAllFeatureEntries,
upsertUserStorage,
} from './services';
import { createSHA256Hash } from '../../shared/encryption';
import type { UserStorageFeatureKeys } from '../../shared/storage-schema';
import {
type UserStoragePathWithFeatureAndKey,
type UserStoragePathWithFeatureOnly,
} from '../../shared/storage-schema';
import type { NativeScrypt } from '../../shared/types/encryption';
import { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';
import type {
AuthenticationControllerGetBearerToken,
AuthenticationControllerGetSessionProfile,
AuthenticationControllerIsSignedIn,
AuthenticationControllerPerformSignIn,
AuthenticationControllerPerformSignOut,
} from '../authentication/AuthenticationController';

// TODO: fix external dependencies
export declare type NotificationServicesControllerDisableNotificationServices =
Expand Down Expand Up @@ -170,20 +170,23 @@ type ControllerConfig = {
/**
* Callback that fires when network sync adds a network
* This is used for analytics.
*
* @param profileId - ID for a given User (shared cross devices once authenticated)
* @param chainId - Chain ID for the network added (in hex)
*/
onNetworkAdded?: (profileId: string, chainId: string) => void;
/**
* Callback that fires when network sync updates a network
* This is used for analytics.
*
* @param profileId - ID for a given User (shared cross devices once authenticated)
* @param chainId - Chain ID for the network added (in hex)
*/
onNetworkUpdated?: (profileId: string, chainId: string) => void;
/**
* Callback that fires when network sync deletes a network
* This is used for analytics.
*
* @param profileId - ID for a given User (shared cross devices once authenticated)
* @param chainId - Chain ID for the network added (in hex)
*/
Expand Down Expand Up @@ -309,12 +312,12 @@ export default class UserStorageController extends BaseController<
> {
// This is replaced with the actual value in the constructor
// We will remove this once the feature will be released
#env = {
readonly #env = {
isAccountSyncingEnabled: false,
isNetworkSyncingEnabled: false,
};

#auth = {
readonly #auth = {
getBearerToken: async () => {
return await this.messagingSystem.call(
'AuthenticationController:getBearerToken',
Expand All @@ -341,9 +344,9 @@ export default class UserStorageController extends BaseController<
},
};

#config?: ControllerConfig;
readonly #config?: ControllerConfig;

#notificationServices = {
readonly #notificationServices = {
disableNotificationServices: async () => {
return await this.messagingSystem.call(
'NotificationServicesController:disableNotificationServices',
Expand All @@ -358,7 +361,7 @@ export default class UserStorageController extends BaseController<

#isUnlocked = false;

#keyringController = {
readonly #keyringController = {
setupLockedStateSubscriptions: () => {
const { isUnlocked } = this.messagingSystem.call(
'KeyringController:getState',
Expand All @@ -375,7 +378,7 @@ export default class UserStorageController extends BaseController<
},
};

#nativeScryptCrypto: NativeScrypt | undefined = undefined;
readonly #nativeScryptCrypto: NativeScrypt | undefined = undefined;

getMetaMetricsState: () => boolean;

Expand Down Expand Up @@ -755,6 +758,8 @@ export default class UserStorageController extends BaseController<

/**
* Utility to get the bearer token and storage key
*
* @returns the bearer token and storage key
*/
async #getStorageKeyAndBearerToken(): Promise<{
bearerToken: string;
Expand Down Expand Up @@ -881,6 +886,7 @@ export default class UserStorageController extends BaseController<

/**
* Saves an individual internal account to the user storage.
*
* @param internalAccount - The internal account to save
*/
async saveInternalAccountToUserStorage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ExternalEvents = NotNamespacedBy<

/**
* creates a custom user storage messenger, in case tests need different permissions
*
* @param props - overrides
* @param props.overrideEvents - override events
* @returns base messenger, and messenger. You can pass this into the mocks below to mock messenger calls
Expand Down Expand Up @@ -88,6 +89,7 @@ type OverrideMessengers = {

/**
* Jest Mock Utility to generate a mock User Storage Messenger
*
* @param overrideMessengers - override messengers if need to modify the underlying permissions
* @returns series of mocks to actions that can be called
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
MOCK_ENCRYPTED_STORAGE_DATA,
MOCK_STORAGE_DATA,
MOCK_STORAGE_KEY,
} from './mockStorage';
import type {
UserStoragePathWithFeatureAndKey,
UserStoragePathWithFeatureOnly,
Expand All @@ -11,11 +16,6 @@ import type {
GetUserStorageResponse,
} from '../services';
import { USER_STORAGE_ENDPOINT } from '../services';
import {
MOCK_ENCRYPTED_STORAGE_DATA,
MOCK_STORAGE_DATA,
MOCK_STORAGE_KEY,
} from './mockStorage';

type MockResponse = {
url: string;
Expand All @@ -38,6 +38,7 @@ export const getMockUserStorageEndpoint = (

/**
* Creates a mock GET user-storage response
*
* @param data - data to encrypt
* @returns a realistic GET Response Body
*/
Expand All @@ -52,6 +53,7 @@ export async function createMockGetStorageResponse(

/**
* Creates a mock GET ALL user-storage response
*
* @param dataArr - array of data to encrypt
* @returns a realistic GET ALL Response Body
*/
Expand All @@ -72,6 +74,7 @@ export async function createMockAllFeatureEntriesResponse(

/**
* Creates a mock user-storage api GET request
*
* @param path - path of the GET Url
* @returns mock GET API request. Can be used by e2e or unit mock servers
*/
Expand All @@ -87,6 +90,7 @@ export async function getMockUserStorageGetResponse(

/**
* Creates a mock user-storage api GET ALL request
*
* @param path - path of the GET url
* @param dataArr - data to encrypt
* @returns mock GET ALL API request. Can be used by e2e or unit mock servers
Expand Down
Loading

0 comments on commit d3d3d21

Please sign in to comment.