Skip to content

Commit 793011d

Browse files
committed
Enable no-explicit-any rule
We now ensure that we get rid of most `any` in our codebase.
1 parent 6deb719 commit 793011d

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

eslint.config.js

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ export default tseslint.config(
1616
tsconfigRootDir: import.meta.dirname,
1717
},
1818
},
19-
rules: {
20-
'@typescript-eslint/no-explicit-any': 'off',
21-
},
2219
},
2320
{
2421
// disable type-aware linting on JS files

src/matcher.ts

+30-31
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ interface BaseMatcher<R> {
9191

9292
type CustomMatcher<R = unknown> = AliasMatcher<R> & BaseMatcher<R>;
9393

94-
function formatCalls(
94+
function formatCalls<Input extends object, Output extends MetadataBearer>(
9595
context: MatcherState,
96-
client: AwsStub<any, any, any>,
97-
command: AwsCommandConstructur<any, any> | undefined,
98-
expectedCall: Record<string, any> | undefined,
96+
client: AwsStub<Input, Output, unknown>,
97+
command: AwsCommandConstructur<Input, Output> | undefined,
98+
expectedCall: Record<string, unknown> | undefined,
9999
message: string,
100100
): string {
101101
const clientName = client.clientName();
@@ -112,7 +112,6 @@ function formatCalls(
112112
const arg = call.args[0];
113113
const name = command?.name ?? `${clientName} with ${arg.constructor.name}`;
114114

115-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
116115
const input = arg.input;
117116

118117
return [
@@ -132,10 +131,10 @@ function formatCalls(
132131
].join('\n');
133132
}
134133

135-
function toHaveReceivedCommandTimes(
134+
function toHaveReceivedCommandTimes<Input extends object, Output extends MetadataBearer>(
136135
this: MatcherState,
137-
client: AwsStub<any, any, any>,
138-
command: AwsCommandConstructur<any, any>,
136+
client: AwsStub<Input, Output, unknown>,
137+
command: AwsCommandConstructur<Input, Output>,
139138
times: number,
140139
): ExpectationResult {
141140
const { isNot } = this;
@@ -154,10 +153,10 @@ function toHaveReceivedCommandTimes(
154153
};
155154
const toReceiveCommandTimes = toHaveReceivedCommandTimes;
156155

157-
function toHaveReceivedCommandOnce(
156+
function toHaveReceivedCommandOnce<Input extends object, Output extends MetadataBearer>(
158157
this: MatcherState,
159-
client: AwsStub<any, any, any>,
160-
command: AwsCommandConstructur<any, any>,
158+
client: AwsStub<Input, Output, unknown>,
159+
command: AwsCommandConstructur<Input, Output>,
161160
): ExpectationResult {
162161
const { isNot } = this;
163162
const callCount = client.commandCalls(command).length;
@@ -174,10 +173,10 @@ function toHaveReceivedCommandOnce(
174173
};
175174
const toReceiveCommandOnce = toHaveReceivedCommandOnce;
176175

177-
function toHaveReceivedCommand(
176+
function toHaveReceivedCommand<Input extends object, Output extends MetadataBearer>(
178177
this: MatcherState,
179-
client: AwsStub<any, any, any>,
180-
command: AwsCommandConstructur<any, any>,
178+
client: AwsStub<Input, Output, unknown>,
179+
command: AwsCommandConstructur<Input, Output>,
181180
): ExpectationResult {
182181
const { isNot } = this;
183182
const callCount = client.commandCalls(command).length;
@@ -194,11 +193,11 @@ function toHaveReceivedCommand(
194193
};
195194
const toReceiveCommand = toHaveReceivedCommand;
196195

197-
function toHaveReceivedCommandWith(
196+
function toHaveReceivedCommandWith<Input extends object, Output extends MetadataBearer>(
198197
this: MatcherState,
199-
client: AwsStub<any, any, any>,
200-
command: AwsCommandConstructur<any, any>,
201-
input: Record<string, any>,
198+
client: AwsStub<Input, Output, unknown>,
199+
command: AwsCommandConstructur<Input, Output>,
200+
input: Record<string, unknown>,
202201
): ExpectationResult {
203202
const { isNot, utils } = this;
204203
const calls = client.commandCalls(command);
@@ -219,11 +218,11 @@ function toHaveReceivedCommandWith(
219218
};
220219
const toReceiveCommandWith = toHaveReceivedCommandWith;
221220

222-
function toHaveReceivedCommandExactlyOnceWith(
221+
function toHaveReceivedCommandExactlyOnceWith<Input extends object, Output extends MetadataBearer>(
223222
this: MatcherState,
224-
client: AwsStub<any, any, any>,
225-
command: AwsCommandConstructur<any, any>,
226-
input: Record<string, any>,
223+
client: AwsStub<Input, Output, unknown>,
224+
command: AwsCommandConstructur<Input, Output>,
225+
input: Record<string, unknown>,
227226
): ExpectationResult {
228227
const { isNot, utils } = this;
229228
const calls = client.commandCalls(command);
@@ -246,12 +245,12 @@ function toHaveReceivedCommandExactlyOnceWith(
246245
};
247246
const toReceiveCommandExactlyOnceWith = toHaveReceivedCommandExactlyOnceWith;
248247

249-
function toHaveReceivedNthCommandWith(
248+
function toHaveReceivedNthCommandWith<Input extends object, Output extends MetadataBearer>(
250249
this: MatcherState,
251-
client: AwsStub<any, any, any>,
252-
command: AwsCommandConstructur<any, any>,
250+
client: AwsStub<Input, Output, unknown>,
251+
command: AwsCommandConstructur<Input, Output>,
253252
times: number,
254-
input: Record<string, any>,
253+
input: Record<string, unknown>,
255254
): ExpectationResult {
256255
const { isNot, utils } = this;
257256
const calls = client.commandCalls(command);
@@ -273,11 +272,11 @@ function toHaveReceivedNthCommandWith(
273272
};
274273
const toReceiveNthCommandWith = toHaveReceivedNthCommandWith;
275274

276-
function toHaveReceivedLastCommandWith(
275+
function toHaveReceivedLastCommandWith<Input extends object, Output extends MetadataBearer>(
277276
this: MatcherState,
278-
client: AwsStub<any, any, any>,
279-
command: AwsCommandConstructur<any, any>,
280-
input: Record<string, any>,
277+
client: AwsStub<Input, Output, unknown>,
278+
command: AwsCommandConstructur<Input, Output>,
279+
input: Record<string, unknown>,
281280
): ExpectationResult {
282281
const { isNot, utils } = this;
283282
const calls = client.commandCalls(command);
@@ -301,7 +300,7 @@ const toReceiveLastCommandWith = toHaveReceivedLastCommandWith;
301300

302301
function toHaveReceivedAnyCommand(
303302
this: MatcherState,
304-
client: AwsStub<any, any, any>,
303+
client: AwsStub<object, MetadataBearer, unknown>,
305304
) {
306305
const { isNot } = this;
307306
const calls = client.calls();

tests/vitest.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-empty-object-type */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
23
import 'vitest';
34

45
import { CustomMatcher } from '../src/matcher.ts';

0 commit comments

Comments
 (0)