Skip to content

Commit 14dabe6

Browse files
committed
style(validation): apply stricter linting
1 parent cfd57af commit 14dabe6

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

packages/validation/src/middleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import { validate } from './validate.js';
105105
* @param options.ajv - Optional Ajv instance to use for validation, if not provided a new instance will be created.
106106
*/
107107
const validator = (options: ValidatorOptions) => {
108-
const before: MiddlewareFn = async (request) => {
108+
const before: MiddlewareFn = (request) => {
109109
if (options.inboundSchema) {
110110
const originalEvent = structuredClone(request.event);
111111
try {
@@ -125,7 +125,7 @@ const validator = (options: ValidatorOptions) => {
125125
}
126126
};
127127

128-
const after = async (handler: MiddyLikeRequest) => {
128+
const after = (handler: MiddyLikeRequest) => {
129129
if (options.outboundSchema) {
130130
try {
131131
handler.response = validate({

packages/validation/tests/unit/decorator.test.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ const outboundSchema = {
2121
};
2222

2323
describe('Decorator: validator', () => {
24-
it('should validate inbound and outbound successfully', async () => {
24+
it('should validate inbound and outbound successfully', () => {
2525
// Prepare
2626
class TestClass {
2727
@validator({ inboundSchema, outboundSchema })
28-
async multiply(input: { value: number }): Promise<{ result: number }> {
28+
multiply(input: { value: number }): { result: number } {
2929
return { result: input.value * 2 };
3030
}
3131
}
3232
const instance = new TestClass();
3333
const input = { value: 5 };
3434

3535
// Act
36-
const output = await instance.multiply(input);
36+
const output = instance.multiply(input);
3737

3838
// Assess
3939
expect(output).toEqual({ result: 10 });
4040
});
4141

42-
it('should throw error on inbound validation failure', async () => {
42+
it('should throw error on inbound validation failure', () => {
4343
// Prepare
4444
class TestClass {
4545
@validator({ inboundSchema, outboundSchema })
46-
async multiply(input: { value: number }): Promise<{ result: number }> {
46+
multiply(input: { value: number }): { result: number } {
4747
return { result: input.value * 2 };
4848
}
4949
}
@@ -53,76 +53,72 @@ describe('Decorator: validator', () => {
5353
};
5454

5555
// Act & Assess
56-
await expect(instance.multiply(invalidInput)).rejects.toThrow(
57-
SchemaValidationError
58-
);
56+
expect(instance.multiply(invalidInput)).toThrow(SchemaValidationError);
5957
});
6058

61-
it('should throw error on outbound validation failure', async () => {
59+
it('should throw error on outbound validation failure', () => {
6260
// Prepare
6361
class TestClassInvalid {
6462
@validator({ inboundSchema, outboundSchema })
65-
async multiply(_input: { value: number }) {
63+
multiply(_input: { value: number }) {
6664
return { result: 'invalid' };
6765
}
6866
}
6967
const instance = new TestClassInvalid();
7068

7169
// Act & Assess
72-
await expect(instance.multiply({ value: 5 })).rejects.toThrow(
73-
SchemaValidationError
74-
);
70+
expect(instance.multiply({ value: 5 })).toThrow(SchemaValidationError);
7571
});
7672

77-
it('should no-op when no schemas are provided', async () => {
73+
it('should no-op when no schemas are provided', () => {
7874
// Prepare
7975
class TestClassNoOp {
8076
@validator({})
81-
async echo(input: unknown): Promise<unknown> {
77+
echo(input: unknown): unknown {
8278
return input;
8379
}
8480
}
8581
const instance = new TestClassNoOp();
8682
const data = { foo: 'bar' };
8783

8884
// Act
89-
const result = await instance.echo(data);
85+
const result = instance.echo(data);
9086

9187
// Assess
9288
expect(result).toEqual(data);
9389
});
9490

95-
it('should validate inbound only', async () => {
91+
it('should validate inbound only', () => {
9692
// Prepare
9793
class TestClassInbound {
9894
@validator({ inboundSchema })
99-
async process(input: { value: number }): Promise<{ data: string }> {
95+
process(input: { value: number }): { data: string } {
10096
return { data: JSON.stringify(input) };
10197
}
10298
}
10399
const instance = new TestClassInbound();
104100
const input = { value: 10 };
105101

106102
// Act
107-
const output = await instance.process(input);
103+
const output = instance.process(input);
108104

109105
// Assess
110106
expect(output).toEqual({ data: JSON.stringify(input) });
111107
});
112108

113-
it('should validate outbound only', async () => {
109+
it('should validate outbound only', () => {
114110
// Prepare
115111
class TestClassOutbound {
116112
@validator({ outboundSchema })
117-
async process(_input: { text: string }): Promise<{ result: number }> {
113+
process(_input: { text: string }): { result: number } {
118114
return { result: 42 };
119115
}
120116
}
121117
const instance = new TestClassOutbound();
122118
const input = { text: 'hello' };
123119

124120
// Act
125-
const output = await instance.process(input);
121+
const output = instance.process(input);
126122

127123
// Assess
128124
expect(output).toEqual({ result: 42 });

packages/validation/tests/unit/middleware.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const outboundSchema = {
2222
additionalProperties: false,
2323
};
2424

25-
const baseHandler = async (event: { inputValue: unknown }) => {
25+
const baseHandler = (event: { inputValue: unknown }) => {
2626
return {
2727
outputValue: event.inputValue,
2828
};

0 commit comments

Comments
 (0)