Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable @typescript-eslint/no-explicit-any as an error rule #23531

Merged
merged 30 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a009d3b
Enable `@typescript-eslint/no-explicit-any` as an error rule
MajorLift Mar 15, 2024
1f4e38b
Mark existing `any` usage with `eslint-disable` directive and TODO co…
MajorLift Mar 15, 2024
24ec73e
Fix existing `any` instance that can't be eslint-disabled due to pret…
MajorLift Mar 15, 2024
4790538
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 21, 2024
eada4b8
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 21, 2024
d767134
Annotate 23 new `any` instances with `eslint-disable` directive
MajorLift Mar 22, 2024
2f39c15
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 22, 2024
5858f72
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 22, 2024
ad9e2a1
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 22, 2024
e9b74d3
Annotate 10 new `any` instances with `eslint-disable` directive
MajorLift Mar 22, 2024
f80c827
Fix missing TODOs
MajorLift Mar 22, 2024
1080b2a
Merge branch 'develop' into 240315-enable-no-explicit-any
DDDDDanica Mar 25, 2024
61f9f7a
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 25, 2024
038435e
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
54be33c
Annotate 2 new `any` instances with `eslint-disable` directives
MajorLift Mar 26, 2024
485ad2c
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
295013f
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
9ce2b48
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
f8cb2b3
Annotate 4 new `any` instances with `eslint-disable` directives
MajorLift Mar 26, 2024
a43a4bd
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
b3bd6bc
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
324d053
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 26, 2024
c277ce3
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
0a169f5
Annotate 2 new `any` instances with `eslint-disable` directives
MajorLift Mar 27, 2024
fe8831b
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
a155bb3
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
294ff60
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
663d802
Fix lockfile
MajorLift Mar 27, 2024
134b0f7
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
2976bca
Merge branch 'develop' into 240315-enable-no-explicit-any
MajorLift Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module.exports = {
path.resolve(__dirname, '.eslintrc.typescript-compat.js'),
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
// this rule is new, but we didn't use it before, so it's off now
'@typescript-eslint/no-duplicate-enum-values': 'off',
'@typescript-eslint/no-shadow': [
Expand Down
22 changes: 22 additions & 0 deletions app/scripts/controllers/decrypt-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const createMessengerMock = () =>
registerInitialEventPayload: jest.fn(),
publish: jest.fn(),
call: jest.fn(),
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any as jest.Mocked<DecryptMessageControllerMessenger>);

const createDecryptMessageManagerMock = <T>() =>
Expand All @@ -57,6 +59,8 @@ const createDecryptMessageManagerMock = <T>() =>
hub: {
on: jest.fn(),
},
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any as jest.Mocked<T>);

describe('DecryptMessageController', () => {
Expand All @@ -81,6 +85,8 @@ describe('DecryptMessageController', () => {

const mockMessengerAction = (
action: string,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
callback: (actionName: string, ...args: any[]) => any,
) => {
messengerMock.call.mockImplementation((actionName, ...rest) => {
Expand All @@ -100,9 +106,17 @@ describe('DecryptMessageController', () => {
);

decryptMessageController = new MockDecryptMessageController({
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getState: getStateMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
keyringController: keyringControllerMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: messengerMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metricsEvent: metricsEventMock as any,
} as DecryptMessageControllerOptions);
});
Expand All @@ -116,6 +130,8 @@ describe('DecryptMessageController', () => {
decryptMessageController.update(() => ({
unapprovedDecryptMsgs: {
[messageIdMock]: messageMock,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
unapprovedDecryptMsgCount: 1,
}));
Expand All @@ -131,6 +147,8 @@ describe('DecryptMessageController', () => {
it('should add unapproved messages', async () => {
await decryptMessageController.newRequestDecryptMessage(
messageMock,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
undefined as any,
);

Expand Down Expand Up @@ -220,6 +238,8 @@ describe('DecryptMessageController', () => {
const messageToDecrypt = {
...messageMock,
data: messageDataMock,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
decryptMessageManagerMock.getMessage.mockReturnValue(messageToDecrypt);
mockMessengerAction(
Expand Down Expand Up @@ -271,6 +291,8 @@ describe('DecryptMessageController', () => {
it('should be able to reject all unapproved messages', async () => {
decryptMessageManagerMock.getUnapprovedMessages.mockReturnValue({
[messageIdMock]: messageMock,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any);

await decryptMessageController.rejectUnapproved('reason to cancel');
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/controllers/decrypt-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ export type DecryptMessageControllerMessenger = RestrictedControllerMessenger<
>;

export type DecryptMessageControllerOptions = {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getState: () => any;
messenger: DecryptMessageControllerMessenger;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metricsEvent: (payload: any, options?: any) => void;
};

Expand All @@ -132,8 +136,12 @@ export default class DecryptMessageController extends BaseController<
> {
hub: EventEmitter;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _getState: () => any;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _metricsEvent: (payload: any, options?: any) => void;

private _decryptMessageManager: DecryptMessageManager;
Expand Down Expand Up @@ -363,6 +371,8 @@ export default class DecryptMessageController extends BaseController<
) {
messageManager.subscribe((state: MessageManagerState<AbstractMessage>) => {
const newMessages = this._migrateMessages(
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.unapprovedMessages as any,
);
this.update((draftState) => {
Expand Down
30 changes: 30 additions & 0 deletions app/scripts/controllers/encryption-public-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const messageMock = {
status: 'unapproved',
type: 'testType',
rawSig: undefined,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any as AbstractMessage;

const coreMessageMock = {
Expand All @@ -56,6 +58,8 @@ const createMessengerMock = () =>
registerActionHandler: jest.fn(),
publish: jest.fn(),
call: jest.fn(),
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any as jest.Mocked<EncryptionPublicKeyControllerMessenger>);

const createEncryptionPublicKeyManagerMock = <T>() =>
Expand All @@ -71,6 +75,8 @@ const createEncryptionPublicKeyManagerMock = <T>() =>
hub: {
on: jest.fn(),
},
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any as jest.Mocked<T>);

describe('EncryptionPublicKeyController', () => {
Expand All @@ -96,10 +102,20 @@ describe('EncryptionPublicKeyController', () => {
);

encryptionPublicKeyController = new EncryptionPublicKeyController({
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messenger: messengerMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getEncryptionPublicKey: getEncryptionPublicKeyMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getAccountKeyringType: getAccountKeyringTypeMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getState: getStateMock as any,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metricsEvent: metricsEventMock as any,
} as EncryptionPublicKeyControllerOptions);
});
Expand All @@ -120,6 +136,8 @@ describe('EncryptionPublicKeyController', () => {
encryptionPublicKeyController.update(() => ({
unapprovedEncryptionPublicKeyMsgs: {
[messageIdMock]: messageMock,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
unapprovedEncryptionPublicKeyMsgCount: 1,
}));
Expand All @@ -140,11 +158,15 @@ describe('EncryptionPublicKeyController', () => {
[messageIdMock2]: messageMock,
};
encryptionPublicKeyManagerMock.getUnapprovedMessages.mockReturnValueOnce(
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messages as any,
);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
encryptionPublicKeyController.update(() => ({
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
unapprovedEncryptionPublicKeyMsgs: messages as any,
}));
});
Expand Down Expand Up @@ -353,6 +375,8 @@ describe('EncryptionPublicKeyController', () => {
const mockListener = jest.fn();

encryptionPublicKeyController.hub.on('updateBadge', mockListener);
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(encryptionPublicKeyManagerMock.hub.on as any).mock.calls[0][1]();

expect(mockListener).toHaveBeenCalledTimes(1);
Expand All @@ -361,6 +385,8 @@ describe('EncryptionPublicKeyController', () => {
it('requires approval on unapproved message event from EncryptionPublicKeyManager', () => {
messengerMock.call.mockResolvedValueOnce({});

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(encryptionPublicKeyManagerMock.hub.on as any).mock.calls[1][1](
messageParamsMock,
);
Expand All @@ -379,12 +405,16 @@ describe('EncryptionPublicKeyController', () => {

it('updates state on EncryptionPublicKeyManager state change', async () => {
await encryptionPublicKeyManagerMock.subscribe.mock.calls[0][0]({
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
unapprovedMessages: { [messageIdMock]: coreMessageMock as any },
unapprovedMessagesCount: 3,
});

expect(encryptionPublicKeyController.state).toEqual({
unapprovedEncryptionPublicKeyMsgs: {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[messageIdMock]: stateMessageMock as any,
},
unapprovedEncryptionPublicKeyMsgCount: 3,
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/controllers/encryption-public-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export type EncryptionPublicKeyControllerOptions = {
messenger: EncryptionPublicKeyControllerMessenger;
getEncryptionPublicKey: (address: string) => Promise<string>;
getAccountKeyringType: (account: string) => Promise<string>;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getState: () => any;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
metricsEvent: (payload: any, options?: any) => void;
};

Expand All @@ -105,10 +109,14 @@ export default class EncryptionPublicKeyController extends BaseController<

private _getAccountKeyringType: (account: string) => Promise<string>;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _getState: () => any;

private _encryptionPublicKeyManager: EncryptionPublicKeyManager;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _metricsEvent: (payload: any, options?: any) => void;

/**
Expand Down Expand Up @@ -352,6 +360,8 @@ export default class EncryptionPublicKeyController extends BaseController<
) {
messageManager.subscribe((state: MessageManagerState<AbstractMessage>) => {
const newMessages = this._migrateMessages(
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
state.unapprovedMessages as any,
);
this.update((draftState) => {
Expand Down
26 changes: 26 additions & 0 deletions app/scripts/controllers/mmi-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type UpdateCustodianTransactionsParameters = {
txList: string[];
custodyController: CustodyController;
transactionUpdateController: TransactionUpdateController;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
txStateManager: any;
getPendingNonce: (address: string) => Promise<number>;
setTxHash: (txId: string, txHash: string) => void;
Expand All @@ -58,6 +60,8 @@ export default class MMIController extends EventEmitter {

public mmiConfigurationController: MmiConfigurationController;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public keyringController: any;

public preferencesController: PreferencesController;
Expand All @@ -68,8 +72,12 @@ export default class MMIController extends EventEmitter {

private custodyController: CustodyController;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private getState: () => any;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private getPendingNonce: (address: string) => Promise<any>;

private accountTracker: AccountTracker;
Expand All @@ -78,28 +86,42 @@ export default class MMIController extends EventEmitter {

private networkController: NetworkController;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private permissionController: any;

private signatureController: SignatureController;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private messenger: any;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private platform: any;

// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private extension: any;

private updateTransactionHash: (txId: string, txHash: string) => void;

public trackTransactionEvents: (
args: { transactionMeta: TransactionMeta },
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
event: any,
) => void;

private txStateManager: {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTransactions: (query?: any, opts?: any, fullTx?: boolean) => any[];
setTxStatusSigned: (txId: string) => void;
setTxStatusSubmitted: (txId: string) => void;
setTxStatusFailed: (txId: string) => void;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
updateTransaction: (txMeta: any) => void;
};

Expand Down Expand Up @@ -171,6 +193,8 @@ export default class MMIController extends EventEmitter {

async trackTransactionEventFromCustodianEvent(
txMeta: TransactionMeta,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
event: any,
) {
// transactionMetricsRequest parameter is already bound in the constructor
Expand Down Expand Up @@ -322,6 +346,8 @@ export default class MMIController extends EventEmitter {
string,
{
name: string;
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
custodianDetails: any;
labels: Label[];
token: string;
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/lib/AbstractPetnamesBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ function createNameControllerMock(state: NameControllerState) {
function createMessengerMock(): jest.Mocked<PetnamesBridgeMessenger> {
return {
subscribe: jest.fn(),
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
}

Expand Down
6 changes: 6 additions & 0 deletions app/scripts/lib/AccountIdentitiesPetnamesBridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,22 @@ function createNameControllerMock(
return {
state,
setName: jest.fn(),
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
}

function simulateSubscribe(
messenger: jest.Mocked<AccountIdentitiesPetnamesBridgeMessenger>,
stateChange: AccountsControllerState,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
patch: any[],
) {
const listener = messenger.subscribe.mock.calls[0][1] as (
stateChange: AccountsControllerState,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
patch: any[],
) => void;
listener(stateChange, patch);
Expand Down
Loading
Loading