Skip to content

Commit 83d37dc

Browse files
authored
Enable @typescript-eslint/no-explicit-any (#3660)
This rule is disabled in our shared ESLint rules, but we want to enable it in this repo. Since there are many, many violations at the moment, this commit adds `eslint-ignore` directives to each violation. This way we can prohibit the use of `any` going forward and then correct each existing violation as we have time. To automatically add these ignore directives, I used [`eslint-interactive`](https://github.com/mizdra/eslint-interactive), which is also useful for getting a quick summary of violations. This commit also adds this tool so that we can use it going forward.
1 parent aea9bac commit 83d37dc

File tree

109 files changed

+1877
-45
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1877
-45
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ module.exports = {
4242
project: ['./tsconfig.packages.json'],
4343
},
4444
rules: {
45+
// Enable rules that are disabled in `@metamask/eslint-config-typescript`
46+
'@typescript-eslint/no-explicit-any': 'error',
47+
4548
// TODO: auto-fix breaks stuff
4649
'@typescript-eslint/promise-function-async': 'off',
4750

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"eslint": "^8.44.0",
6363
"eslint-config-prettier": "^8.5.0",
6464
"eslint-import-resolver-typescript": "^2.5.0",
65+
"eslint-interactive": "^10.8.0",
6566
"eslint-plugin-import": "2.26.0",
6667
"eslint-plugin-jest": "^27.1.5",
6768
"eslint-plugin-jsdoc": "^39.9.1",

packages/accounts-controller/src/AccountsController.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ describe('AccountsController', () => {
251251
status: SnapStatus.Running,
252252
},
253253
},
254+
// TODO: Replace `any` with type
255+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
254256
} as any as SnapControllerState;
255257
const accountsController = setupAccountsController({
256258
initialState: {
@@ -291,6 +293,8 @@ describe('AccountsController', () => {
291293
status: SnapStatus.Running,
292294
},
293295
},
296+
// TODO: Replace `any` with type
297+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
294298
} as any as SnapControllerState;
295299
const accountsController = setupAccountsController({
296300
initialState: {
@@ -331,6 +335,8 @@ describe('AccountsController', () => {
331335
status: SnapStatus.Running,
332336
},
333337
},
338+
// TODO: Replace `any` with type
339+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
334340
} as any as SnapControllerState;
335341
const accountsController = setupAccountsController({
336342
initialState: {

packages/approval-controller/src/ApprovalController.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ function getApprovalCountParamsError() {
197197
* @returns An Error.
198198
*/
199199
function getError(message: string, code?: number) {
200+
// TODO: Replace `any` with type
201+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
200202
const err: any = {
201203
name: 'Error',
202204
message,
@@ -242,14 +244,20 @@ describe('approval controller', () => {
242244
describe('add', () => {
243245
it('validates input', () => {
244246
expect(() =>
247+
// TODO: Replace `any` with type
248+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
245249
approvalController.add({ id: null, origin: 'bar.baz' } as any),
246250
).toThrow(getInvalidIdError());
247251

252+
// TODO: Replace `any` with type
253+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
248254
expect(() => approvalController.add({ id: 'foo' } as any)).toThrow(
249255
getInvalidOriginError(),
250256
);
251257

252258
expect(() =>
259+
// TODO: Replace `any` with type
260+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
253261
approvalController.add({ id: 'foo', origin: true } as any),
254262
).toThrow(getInvalidOriginError());
255263

@@ -258,6 +266,8 @@ describe('approval controller', () => {
258266
id: 'foo',
259267
origin: 'bar.baz',
260268
type: {},
269+
// TODO: Replace `any` with type
270+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
261271
} as any),
262272
).toThrow(getInvalidTypeError(errorCodes.rpc.internal));
263273

@@ -266,6 +276,8 @@ describe('approval controller', () => {
266276
id: 'foo',
267277
origin: 'bar.baz',
268278
type: '',
279+
// TODO: Replace `any` with type
280+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
269281
} as any),
270282
).toThrow(getInvalidTypeError(errorCodes.rpc.internal));
271283

@@ -275,6 +287,8 @@ describe('approval controller', () => {
275287
origin: 'bar.baz',
276288
type: 'type',
277289
requestData: 'foo',
290+
// TODO: Replace `any` with type
291+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
278292
} as any),
279293
).toThrow(getInvalidRequestDataError());
280294

@@ -284,6 +298,8 @@ describe('approval controller', () => {
284298
origin: 'bar.baz',
285299
type: 'type',
286300
requestState: 'foo',
301+
// TODO: Replace `any` with type
302+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
287303
} as any),
288304
).toThrow(getInvalidRequestStateError());
289305
});
@@ -493,16 +509,24 @@ describe('approval controller', () => {
493509

494510
expect(approvalController.get('fizz')).toBeUndefined();
495511

512+
// TODO: Replace `any` with type
513+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
496514
expect((approvalController as any).get()).toBeUndefined();
497515

516+
// TODO: Replace `any` with type
517+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
498518
expect(approvalController.get({} as any)).toBeUndefined();
499519
});
500520
});
501521

502522
describe('getApprovalCount', () => {
523+
// TODO: Replace `any` with type
524+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
503525
let addWithCatch: (args: any) => void;
504526

505527
beforeEach(() => {
528+
// TODO: Replace `any` with type
529+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
506530
addWithCatch = (args: any) => {
507531
approvalController.add(args).catch(() => undefined);
508532
};
@@ -518,10 +542,14 @@ describe('approval controller', () => {
518542
);
519543

520544
expect(() =>
545+
// TODO: Replace `any` with type
546+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
521547
approvalController.getApprovalCount({ origin: null } as any),
522548
).toThrow(getApprovalCountParamsError());
523549

524550
expect(() =>
551+
// TODO: Replace `any` with type
552+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
525553
approvalController.getApprovalCount({ type: false } as any),
526554
).toThrow(getApprovalCountParamsError());
527555
});
@@ -636,6 +664,8 @@ describe('approval controller', () => {
636664
it('gets the total approval count', () => {
637665
expect(approvalController.getTotalApprovalCount()).toBe(0);
638666

667+
// TODO: Replace `any` with type
668+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
639669
const addWithCatch = (args: any) => {
640670
approvalController.add(args).catch(() => undefined);
641671
};
@@ -664,6 +694,8 @@ describe('approval controller', () => {
664694
});
665695
expect(approvalController.getTotalApprovalCount()).toBe(0);
666696

697+
// TODO: Replace `any` with type
698+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
667699
const addWithCatch = (args: any) => {
668700
approvalController.add(args).catch(() => undefined);
669701
};
@@ -692,19 +724,27 @@ describe('approval controller', () => {
692724
getInvalidHasParamsError(),
693725
);
694726

727+
// TODO: Replace `any` with type
728+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
695729
expect(() => approvalController.has({ id: true } as any)).toThrow(
696730
getInvalidHasIdError(),
697731
);
698732

733+
// TODO: Replace `any` with type
734+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
699735
expect(() => approvalController.has({ origin: true } as any)).toThrow(
700736
getInvalidHasOriginError(),
701737
);
702738

739+
// TODO: Replace `any` with type
740+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
703741
expect(() => approvalController.has({ type: true } as any)).toThrow(
704742
getInvalidHasTypeError(),
705743
);
706744

707745
expect(() =>
746+
// TODO: Replace `any` with type
747+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
708748
approvalController.has({ origin: 'foo', type: true } as any),
709749
).toThrow(getInvalidHasTypeError());
710750
});
@@ -1341,6 +1381,8 @@ describe('approval controller', () => {
13411381
* @param methodCallback - A callback to invoke the result method.
13421382
*/
13431383
async function endsSpecifiedFlowTemplate(
1384+
// TODO: Replace `any` with type
1385+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13441386
methodCallback: (flowId: string) => Promise<any>,
13451387
) {
13461388
approvalController.startFlow({ id: FLOW_ID_MOCK });
@@ -1365,6 +1407,8 @@ describe('approval controller', () => {
13651407
* @param methodCallback - A callback to invoke the result method.
13661408
*/
13671409
async function doesNotThrowIfAddingRequestFails(
1410+
// TODO: Replace `any` with type
1411+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13681412
methodCallback: () => Promise<any>,
13691413
) {
13701414
jest.spyOn(global.console, 'info');
@@ -1389,6 +1433,8 @@ describe('approval controller', () => {
13891433
* @param methodCallback - A callback to invoke the result method.
13901434
*/
13911435
async function doesNotThrowIfEndFlowFails(
1436+
// TODO: Replace `any` with type
1437+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
13921438
methodCallback: () => Promise<any>,
13931439
) {
13941440
jest.spyOn(global.console, 'info');
@@ -1425,6 +1471,8 @@ describe('approval controller', () => {
14251471
});
14261472

14271473
it('only includes relevant options in request data', async () => {
1474+
// TODO: Replace `any` with type
1475+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14281476
(approvalController as any).success({
14291477
...SUCCESS_OPTIONS_MOCK,
14301478
extra: 'testValue',
@@ -1483,6 +1531,8 @@ describe('approval controller', () => {
14831531
});
14841532

14851533
it('only includes relevant options in request data', async () => {
1534+
// TODO: Replace `any` with type
1535+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14861536
(approvalController as any).error({
14871537
...ERROR_OPTIONS_MOCK,
14881538
extra: 'testValue',

packages/approval-controller/src/ApprovalController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,8 @@ export class ApprovalController extends BaseController<
751751
this.update((draftState) => {
752752
// Typecast: ts(2589)
753753
draftState.pendingApprovals[opts.id].requestState =
754+
// TODO: Replace `any` with type
755+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
754756
opts.requestState as any;
755757
});
756758
}
@@ -839,6 +841,8 @@ export class ApprovalController extends BaseController<
839841
await this.#result(APPROVAL_TYPE_RESULT_SUCCESS, opts, {
840842
message: opts.message,
841843
header: opts.header,
844+
// TODO: Replace `any` with type
845+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
842846
} as any);
843847
return {};
844848
}
@@ -856,6 +860,8 @@ export class ApprovalController extends BaseController<
856860
await this.#result(APPROVAL_TYPE_RESULT_ERROR, opts, {
857861
error: opts.error,
858862
header: opts.header,
863+
// TODO: Replace `any` with type
864+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
859865
} as any);
860866
return {};
861867
}
@@ -998,6 +1004,8 @@ export class ApprovalController extends BaseController<
9981004

9991005
this.update((draftState) => {
10001006
// Typecast: ts(2589)
1007+
// TODO: Replace `any` with type
1008+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
10011009
draftState.pendingApprovals[id] = approval as any;
10021010
draftState.pendingApprovalCount = Object.keys(
10031011
draftState.pendingApprovals,

packages/assets-controllers/src/AccountTrackerController.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ describe('AccountTrackerController', () => {
8686
controller.refresh = sinon.stub();
8787

8888
preferences.setFeatureFlag('foo', true);
89+
// TODO: Replace `any` with type
90+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8991
expect((controller.refresh as any).called).toBe(true);
9092
});
9193

packages/assets-controllers/src/AssetsContractController.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ async function setupAssetContractControllers() {
7373
({
7474
...network.getNetworkClientById(networkClientId),
7575
provider,
76+
// TODO: Replace `any` with type
77+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7678
} as any),
7779
});
7880

packages/assets-controllers/src/AssetsContractController.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export const MISSING_PROVIDER_ERROR =
6262
// Convert to a `type` in a future major version.
6363
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
6464
export interface AssetsContractConfig extends BaseConfig {
65+
// TODO: Replace `any` with type
66+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6567
provider: any;
6668
ipfsGateway: string;
6769
chainId: Hex;
@@ -87,6 +89,8 @@ export class AssetsContractController extends BaseControllerV1<
8789
AssetsContractConfig,
8890
BaseState
8991
> {
92+
// TODO: Replace `any` with type
93+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9094
private _provider?: any;
9195

9296
/**
@@ -155,6 +159,8 @@ export class AssetsContractController extends BaseControllerV1<
155159
*
156160
* @property provider - Provider used to create a new underlying Web3 instance
157161
*/
162+
// TODO: Replace `any` with type
163+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
158164
set provider(provider: any) {
159165
this._provider = provider;
160166
}

0 commit comments

Comments
 (0)