Skip to content

Commit

Permalink
linting fixes and removal of any type use in some tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Maj committed Sep 15, 2024
1 parent 0563c3f commit b40e790
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
56 changes: 29 additions & 27 deletions src/App-built-in-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ class FakeReceiver implements Receiver {
this.bolt = bolt;
};

public start = sinon.fake((...params: any[]): Promise<unknown> => Promise.resolve([...params]));
public start = sinon.fake(
(...params: Parameters<typeof App.prototype.start>): Promise<unknown> => Promise.resolve([...params]),
);

public stop = sinon.fake((...params: any[]): Promise<unknown> => Promise.resolve([...params]));
public stop = sinon.fake(
(...params: Parameters<typeof App.prototype.stop>): Promise<unknown> => Promise.resolve([...params]),
);

public async sendEvent(event: ReceiverEvent): Promise<void> {
return this.bolt?.processEvent(event);
Expand Down Expand Up @@ -176,12 +180,13 @@ describe('App built-in middleware and mechanism', () => {

it('throws errors which can be caught by upstream async listeners', async () => {
const thrownError = new Error('Error handling the message :(');
let caughtError;
// biome-ignore lint/suspicious/noExplicitAny: errors can be anything
let caughtError: any;

app.use(async ({ next }) => {
try {
await next();
} catch (err: any) {
} catch (err) {
caughtError = err;
}
});
Expand Down Expand Up @@ -209,16 +214,16 @@ describe('App built-in middleware and mechanism', () => {
*/
const assertOrderMiddleware =
(orderDown: number, orderUp: number) =>
async ({ next }: { next?: NextFn }) => {
await delay(10);
middlewareCount += 1;
assert.equal(middlewareCount, orderDown);
if (next !== undefined) {
await next();
}
middlewareCount += 1;
assert.equal(middlewareCount, orderUp);
};
async ({ next }: { next?: NextFn }) => {
await delay(10);
middlewareCount += 1;
assert.equal(middlewareCount, orderDown);
if (next !== undefined) {
await next();
}
middlewareCount += 1;
assert.equal(middlewareCount, orderUp);
};

app.use(assertOrderMiddleware(1, 8));
app.message(message, assertOrderMiddleware(3, 6), assertOrderMiddleware(4, 5));
Expand Down Expand Up @@ -257,9 +262,7 @@ describe('App built-in middleware and mechanism', () => {

it('should, on error, call the global error handler, extended', async () => {
const error = new Error('Everything is broke, you probably should restart, if not then good luck');
// Need to change value of private property for testing purposes
// Accessing through bracket notation because it is private
// eslint-disable-next-line @typescript-eslint/dot-notation
// biome-ignore lint/complexity/useLiteralKeys: Accessing through bracket notation because it is private (for testing purposes)
app['extendedErrorHandler'] = true;

app.use(() => {
Expand All @@ -280,23 +283,22 @@ describe('App built-in middleware and mechanism', () => {

await fakeReceiver.sendEvent(dummyReceiverEvent);

// Need to change value of private property for testing purposes
// Accessing through bracket notation because it is private
// eslint-disable-next-line @typescript-eslint/dot-notation
// biome-ignore lint/complexity/useLiteralKeys: Accessing through bracket notation because it is private (for testing purposes)
app['extendedErrorHandler'] = false;
});

it('with a default global error handler, rejects App#ProcessEvent', async () => {
const error = new Error('The worst has happened, bot is beyond saving, always hug servers');
let actualError;
// biome-ignore lint/suspicious/noExplicitAny: errors can be anything
let actualError: any;

app.use(() => {
throw error;
});

try {
await fakeReceiver.sendEvent(dummyReceiverEvent);
} catch (err: any) {
} catch (err) {
actualError = err;
}

Expand Down Expand Up @@ -360,10 +362,10 @@ describe('App built-in middleware and mechanism', () => {
});

it('should detect invalid event names', async () => {
app.event('app_mention', async () => {});
app.event('message', async () => {});
assert.throws(() => app.event('message.channels', async () => {}), 'Although the document mentions');
assert.throws(() => app.event(/message\..+/, async () => {}), 'Although the document mentions');
app.event('app_mention', async () => { });
app.event('message', async () => { });
assert.throws(() => app.event('message.channels', async () => { }), 'Although the document mentions');
assert.throws(() => app.event(/message\..+/, async () => { }), 'Although the document mentions');
});

// https://github.com/slackapi/bolt-js/issues/1457
Expand Down Expand Up @@ -569,7 +571,7 @@ async function importApp(
function withNoopWebClient(): Override {
return {
'@slack/web-api': {
WebClient: class {},
WebClient: class { },
},
};
}
Expand Down
16 changes: 8 additions & 8 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export type ErrorHandler = (error: CodedError) => Promise<void>;

export type ExtendedErrorHandler = (args: ExtendedErrorHandlerArgs) => Promise<void>;

export interface AnyErrorHandler extends ErrorHandler, ExtendedErrorHandler { }
export interface AnyErrorHandler extends ErrorHandler, ExtendedErrorHandler {}

// Used only in this file
type MessageEventMiddleware<CustomContext extends StringIndexed = StringIndexed> = Middleware<
Expand Down Expand Up @@ -596,8 +596,8 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
if (invalidEventName) {
throw new AppInitializationError(
`Although the document mentions "${eventNameOrPattern}",` +
'it is not a valid event type. Use "message" instead. ' +
'If you want to filter message events, you can use event.channel_type for it.',
'it is not a valid event type. Use "message" instead. ' +
'If you want to filter message events, you can use event.channel_type for it.',
);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -1178,7 +1178,7 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
context,
client,
logger: this.logger,
next: () => { },
next: () => {},
} as AnyMiddlewareArgs & AllMiddlewareArgs),
);
});
Expand Down Expand Up @@ -1270,7 +1270,7 @@ export default class App<AppCustomContext extends StringIndexed = StringIndexed>
// Using default receiver HTTPReceiver, signature verification enabled, missing signingSecret
throw new AppInitializationError(
'signingSecret is required to initialize the default receiver. Set signingSecret or use a ' +
'custom receiver. You can find your Signing Secret in your Slack App Settings.',
'custom receiver. You can find your Signing Secret in your Slack App Settings.',
);
}
this.logger.debug('Initializing HTTPReceiver');
Expand Down Expand Up @@ -1364,9 +1364,9 @@ function runAuthTestForBotToken(
return authorization.botUserId !== undefined && authorization.botId !== undefined
? Promise.resolve({ botUserId: authorization.botUserId, botId: authorization.botId })
: client.auth.test({ token: authorization.botToken }).then((result) => ({
botUserId: result.user_id as string,
botId: result.bot_id as string,
}));
botUserId: result.user_id as string,
botId: result.bot_id as string,
}));
}

// the shortened type, which is supposed to be used only in this source file
Expand Down
4 changes: 1 addition & 3 deletions src/types/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ export type StringIndexed = Record<string, any>;
/**
* Type function which allows either types `T` or `U`, but not both.
*/
export type XOR<T, U> = T | U extends Record<string, unknown>
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U;
export type XOR<T, U> = T | U extends Record<string, unknown> ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
16 changes: 8 additions & 8 deletions types-tests/message.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import App from '../src/App';
import { expectError, expectNotType, expectType } from 'tsd';
import type {
MessageEvent,
GenericMessageEvent,
AllMessageEvents,
BotMessageEvent,
MessageRepliedEvent,
EKMAccessDeniedMessageEvent,
GenericMessageEvent,
MeMessageEvent,
MessageChangedEvent,
MessageDeletedEvent,
MessageEvent,
MessageRepliedEvent,
ThreadBroadcastMessageEvent,
MessageChangedEvent,
EKMAccessDeniedMessageEvent,
AllMessageEvents,
} from '..';
import { expectError, expectNotType, expectType } from 'tsd';
import App from '../src/App';

const app = new App({ token: 'TOKEN', signingSecret: 'Signing Secret' });

Expand Down

0 comments on commit b40e790

Please sign in to comment.