Skip to content

Commit

Permalink
Run lint:fix for consisten styling
Browse files Browse the repository at this point in the history
Now that we have our stylistic plugin in eslint we can go ahead and
autofix everything.

This commit is the result of running `npm run lint:fix` on a prestine
checkout.
  • Loading branch information
stschulte committed Sep 3, 2024
1 parent bb93a5c commit 212340c
Show file tree
Hide file tree
Showing 9 changed files with 590 additions and 590 deletions.
20 changes: 10 additions & 10 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import eslint from "@eslint/js";
import stylistic from "@stylistic/eslint-plugin";
import gitignore from "eslint-config-flat-gitignore";
import perfectionist from "eslint-plugin-perfectionist"
import tseslint from "typescript-eslint";
import eslint from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import gitignore from 'eslint-config-flat-gitignore';
import perfectionist from 'eslint-plugin-perfectionist';
import tseslint from 'typescript-eslint';

export default tseslint.config(
gitignore(),
Expand All @@ -13,21 +13,21 @@ export default tseslint.config(
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
}
},
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
// disable type-aware linting on JS files
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
perfectionist.configs["recommended-natural"],
perfectionist.configs['recommended-natural'],
stylistic.configs.customize({
indent: 2,
quotes: "single",
quotes: 'single',
semi: true,
})
}),
);
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { CustomMatcher } from './matcher.js'
export type { CustomMatcher } from './matcher.js';
export {
toHaveReceivedCommand,
toHaveReceivedCommandOnce,
Expand All @@ -11,5 +11,5 @@ export {
toReceiveCommandTimes,
toReceiveCommandWith,
toReceiveLastCommandWith,
toReceiveNthCommandWith
} from "./matcher.js";
toReceiveNthCommandWith,
} from './matcher.js';
120 changes: 60 additions & 60 deletions src/matcher.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { MetadataBearer } from "@smithy/types";
import type { MetadataBearer } from '@smithy/types';
import type {
ExpectationResult,
MatcherState,
} from "@vitest/expect";
import type { AwsCommand, AwsStub } from "aws-sdk-client-mock";
} from '@vitest/expect';
import type { AwsCommand, AwsStub } from 'aws-sdk-client-mock';

import { ObjectContaining } from "@vitest/expect";
import { ObjectContaining } from '@vitest/expect';

import { notNull, ordinalOf } from "./utils.js";
import { notNull, ordinalOf } from './utils.js';

type AwsCommandConstructur<
Input extends object,
Output extends MetadataBearer
Output extends MetadataBearer,
> = new (input: Input) => AwsCommand<Input, Output>;

/*
Expand Down Expand Up @@ -41,38 +41,38 @@ interface BaseMatcher<R> {

toHaveReceivedCommandOnce<
Input extends object,
Ouptut extends MetadataBearer
Ouptut extends MetadataBearer,
>(
command: AwsCommandConstructur<Input, Ouptut>
): R;

toHaveReceivedCommandTimes<
Input extends object,
Ouptut extends MetadataBearer
Ouptut extends MetadataBearer,
>(
command: AwsCommandConstructur<Input, Ouptut>,
times: number
): R;

toHaveReceivedCommandWith<
Input extends object,
Ouptut extends MetadataBearer
Ouptut extends MetadataBearer,
>(
command: AwsCommandConstructur<Input, Ouptut>,
input: Partial<Input>
): R;

toHaveReceivedLastCommandWith<
Input extends object,
Ouptut extends MetadataBearer
Ouptut extends MetadataBearer,
>(
command: AwsCommandConstructur<Input, Ouptut>,
input: Partial<Input>
): R;

toHaveReceivedNthCommandWith<
Input extends object,
Ouptut extends MetadataBearer
Ouptut extends MetadataBearer,
>(
command: AwsCommandConstructur<Input, Ouptut>,
times: number,
Expand All @@ -84,12 +84,12 @@ interface BaseMatcher<R> {
* We define some aliases
*/
interface AliasMatcher<R> {
toReceiveCommand: BaseMatcher<R>["toHaveReceivedCommand"];
toReceiveCommandOnce: BaseMatcher<R>["toHaveReceivedCommandOnce"];
toReceiveCommandTimes: BaseMatcher<R>["toHaveReceivedCommandTimes"];
toReceiveCommandWith: BaseMatcher<R>["toHaveReceivedCommandWith"];
toReceiveLastCommandWith: BaseMatcher<R>["toHaveReceivedLastCommandWith"];
toReceiveNthCommandWith: BaseMatcher<R>["toHaveReceivedNthCommandWith"];
toReceiveCommand: BaseMatcher<R>['toHaveReceivedCommand'];
toReceiveCommandOnce: BaseMatcher<R>['toHaveReceivedCommandOnce'];
toReceiveCommandTimes: BaseMatcher<R>['toHaveReceivedCommandTimes'];
toReceiveCommandWith: BaseMatcher<R>['toHaveReceivedCommandWith'];
toReceiveLastCommandWith: BaseMatcher<R>['toHaveReceivedLastCommandWith'];
toReceiveNthCommandWith: BaseMatcher<R>['toHaveReceivedNthCommandWith'];
}

type CustomMatcher<R = unknown> = AliasMatcher<R> & BaseMatcher<R>;
Expand All @@ -99,41 +99,41 @@ function formatCalls(
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>,
expectedCall: Record<string, any> | undefined,
message: string
message: string,
): string {
const calls = client.commandCalls(command);

return calls.length === 0
? message
: [
message,
"",
"Received:",
"",
...calls.flatMap((call, index) => {
message,
'',
'Received:',
'',
...calls.flatMap((call, index) => {
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const input = call.args[0].input;
return [
` ${ordinalOf(index + 1)} ${command.name} call`,
"",
expectedCall
? context.utils.diff(expectedCall, input, { omitAnnotationLines: true })
: context.utils
.stringify(input)
.split("\n")
.map(line => ` ${line}`)
.join("\n"),
""
].filter(notNull);
}),
`Number of calls: ${calls.length.toString()}`
].join("\n");
const input = call.args[0].input;
return [
` ${ordinalOf(index + 1)} ${command.name} call`,
'',
expectedCall
? context.utils.diff(expectedCall, input, { omitAnnotationLines: true })
: context.utils
.stringify(input)
.split('\n')
.map(line => ` ${line}`)
.join('\n'),
'',
].filter(notNull);
}),
`Number of calls: ${calls.length.toString()}`,
].join('\n');
}

const toHaveReceivedCommandTimes: CustomMatcherFn = function(
const toHaveReceivedCommandTimes: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>,
times: number
times: number,
) {
const { isNot } = this;
const callCount = client.commandCalls(command).length;
Expand All @@ -146,14 +146,14 @@ const toHaveReceivedCommandTimes: CustomMatcherFn = function(
: `expected "${command.name}" to be called ${times.toString()} times, but got ${callCount.toString()} times`;
return formatCalls(this, client, command, undefined, message);
},
pass
pass,
};
};
const toReceiveCommandTimes = toHaveReceivedCommandTimes;

const toHaveReceivedCommandOnce: CustomMatcherFn = function(
const toHaveReceivedCommandOnce: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>
command: AwsCommandConstructur<any, any>,
) {
const { isNot } = this;
const callCount = client.commandCalls(command).length;
Expand All @@ -165,14 +165,14 @@ const toHaveReceivedCommandOnce: CustomMatcherFn = function(
: `expected "${command.name}" to be called once, but got ${callCount.toString()} times`;
return formatCalls(this, client, command, undefined, message);
},
pass
pass,
};
};
const toReceiveCommandOnce = toHaveReceivedCommandOnce;

const toHaveReceivedCommand: CustomMatcherFn = function(
const toHaveReceivedCommand: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>
command: AwsCommandConstructur<any, any>,
) {
const { isNot } = this;
const callCount = client.commandCalls(command).length;
Expand All @@ -184,21 +184,21 @@ const toHaveReceivedCommand: CustomMatcherFn = function(
: `expected "${command.name}" to be called at least once`;
return formatCalls(this, client, command, undefined, message);
},
pass
pass,
};
};
const toReceiveCommand = toHaveReceivedCommand;

const toHaveReceivedCommandWith: CustomMatcherFn = function(
const toHaveReceivedCommandWith: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>,
input: Record<string, any>
input: Record<string, any>,
) {
const { isNot, utils } = this;
const calls = client.commandCalls(command);

const pass = calls.some(call =>
new ObjectContaining(input).asymmetricMatch(call.args[0].input)
new ObjectContaining(input).asymmetricMatch(call.args[0].input),
);

return {
Expand All @@ -208,18 +208,18 @@ const toHaveReceivedCommandWith: CustomMatcherFn = function(
: `expected "${command.name}" to be called with arguments: ${utils.printExpected(input)}`;
return formatCalls(this, client, command, input, message);
},
pass
pass,
};
};
const toReceiveCommandWith = toHaveReceivedCommandWith;
/*
*/
const toHaveReceivedNthCommandWith: CustomMatcherFn = function(
const toHaveReceivedNthCommandWith: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>,
times: number,
input: Record<string, any>
input: Record<string, any>,
) {
const { isNot, utils } = this;
const calls = client.commandCalls(command);
Expand All @@ -236,15 +236,15 @@ const toHaveReceivedNthCommandWith: CustomMatcherFn = function(
: `expected ${ordinalOf(times)} "${command.name}" to be called with arguments: ${utils.printExpected(input)}`;
return formatCalls(this, client, command, input, message);
},
pass
pass,
};
};
const toReceiveNthCommandWith = toHaveReceivedNthCommandWith;

const toHaveReceivedLastCommandWith: CustomMatcherFn = function(
const toHaveReceivedLastCommandWith: CustomMatcherFn = function (
client: AwsStub<any, any, any>,
command: AwsCommandConstructur<any, any>,
input: Record<string, any>
input: Record<string, any>,
) {
const { isNot, utils } = this;
const calls = client.commandCalls(command);
Expand All @@ -261,12 +261,12 @@ const toHaveReceivedLastCommandWith: CustomMatcherFn = function(
: `expected last "${command.name}" to be called with arguments: ${utils.printExpected(input)}`;
return formatCalls(this, client, command, input, message);
},
pass
pass,
};
};
const toReceiveLastCommandWith = toHaveReceivedLastCommandWith;

export type { CustomMatcher }
export type { CustomMatcher };
export {
toHaveReceivedCommand,
toHaveReceivedCommandOnce,
Expand All @@ -279,5 +279,5 @@ export {
toReceiveCommandTimes,
toReceiveCommandWith,
toReceiveLastCommandWith,
toReceiveNthCommandWith
toReceiveNthCommandWith,
};
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function ordinalOf(n: number): string {
const j = n % 10;
const k = n % 100;
const s = n.toString()
const s = n.toString();
if (j === 1 && k !== 11) return `${s}st`;
if (j === 2 && k !== 12) return `${s}nd`;
if (j === 3 && k !== 13) return `${s}rd`;
Expand Down
10 changes: 5 additions & 5 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, it } from "vitest";
import { expect, it } from 'vitest';

import {
toHaveReceivedCommand,
Expand All @@ -12,10 +12,10 @@ import {
toReceiveCommandTimes,
toReceiveCommandWith,
toReceiveLastCommandWith,
toReceiveNthCommandWith
} from "../src/index.js";
toReceiveNthCommandWith,
} from '../src/index.js';

it("should be able to extend with matchers", () => {
it('should be able to extend with matchers', () => {
expect.extend({
toHaveReceivedCommand,
toHaveReceivedCommandOnce,
Expand All @@ -28,6 +28,6 @@ it("should be able to extend with matchers", () => {
toReceiveCommandTimes,
toReceiveCommandWith,
toReceiveLastCommandWith,
toReceiveNthCommandWith
toReceiveNthCommandWith,
});
});
Loading

0 comments on commit 212340c

Please sign in to comment.