Skip to content

Commit

Permalink
fix: [#4684] ESLint issues in botbuilder-dialogs-adaptive-runtime-int…
Browse files Browse the repository at this point in the history
…egration libraries (#4811)

* Fix issues in runtime-integration-azure-functions

* Fix issues in runtime-integration-express

* Fix issues in runtime-integration-restify
  • Loading branch information
ceciliaavila authored Dec 10, 2024
1 parent 7bbb868 commit 3b8fcab
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 63 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
"botbuilder": "4.1.6",
"botbuilder-dialogs-adaptive-runtime": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"eslint-plugin-only-warn": "^1.1.0",
"mime": "^4.0.4",
"zod": "^3.23.8"
},
"scripts": {
"build": "tsc -b",
"clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo",
"depcheck": "depcheck --config ../../.depcheckrc",
"lint": "eslint .",
"lint": "eslint . --config ../../eslint.config.cjs",
"postbuild": "downlevel-dts lib _ts3.4/lib --checksum"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

/* eslint-disable @typescript-eslint/no-explicit-any */

import * as z from 'zod';
import fs from 'fs';
import mime from 'mime';
Expand Down Expand Up @@ -62,7 +60,7 @@ const extensionContentTypes: Record<string, string> = {
export function makeTriggers(
runtimeServices: () => Promise<[ServiceCollection, Configuration]>,
applicationRoot: string,
options: Partial<Options> = {}
options: Partial<Options> = {},
): Record<string, AzureFunction> {
const resolvedOptions = TypedOptions.parse(Object.assign({}, defaultOptions, options));

Expand Down Expand Up @@ -106,8 +104,8 @@ export function makeTriggers(
name: z.string(),
enabled: z.boolean().optional(),
route: z.string(),
})
)
}),
),
) ?? [];

const adapterSetting = adapterSettings
Expand Down Expand Up @@ -137,7 +135,7 @@ export function makeTriggers(
res,
async (turnContext) => {
await bot.run(turnContext);
}
},
);
} catch (err) {
if (resolvedOptions.logErrors) {
Expand Down Expand Up @@ -167,7 +165,7 @@ export function makeTriggers(
authHeader,
conversationId,
activityId,
activity
activity,
);

const res = context.res as Response;
Expand Down Expand Up @@ -202,8 +200,8 @@ export function makeTriggers(
const contents = await new Promise((resolve, reject) =>
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFile(path.join(staticDirectory, filePath), 'utf8', (err, contents) =>
err ? reject(err) : resolve(contents)
)
err ? reject(err) : resolve(contents),
),
);

res.status(200);
Expand Down Expand Up @@ -235,11 +233,11 @@ export function makeTriggers(
export function triggers(
applicationRoot: string,
settingsDirectory: string,
options: Partial<Options> = {}
options: Partial<Options> = {},
): Record<string, AzureFunction> {
return makeTriggers(
memoize(() => getRuntimeServices(applicationRoot, settingsDirectory)),
applicationRoot,
options
options,
);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"build": "tsc -b",
"clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo",
"depcheck": "depcheck --config ../../.depcheckrc",
"lint": "eslint .",
"lint": "eslint . --config ../../eslint.config.cjs",
"postbuild": "downlevel-dts lib _ts3.4/lib --checksum"
},
"files": [
Expand All @@ -44,7 +44,6 @@
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"botframework-connector": "4.1.6",
"express": "^4.21.0",
"eslint-plugin-only-warn": "^1.1.0",
"zod": "^3.23.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const TypedOptions = z.object({
/**
* Used when creating ConnectorClients.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any

connectorClientOptions: z.object({}) as z.ZodObject<any, any, any, ConnectorClientOptions>,
});

Expand Down Expand Up @@ -71,7 +71,7 @@ const defaultOptions: Options = {
export async function start(
applicationRoot: string,
settingsDirectory: string,
options: Partial<Options> = {}
options: Partial<Options> = {},
): Promise<void> {
const [services, configuration] = await getRuntimeServices(applicationRoot, settingsDirectory, {
connectorClientOptions: options.connectorClientOptions,
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function makeApp(
configuration: Configuration,
applicationRoot: string,
options: Partial<Options> = {},
app: Application = express()
app: Application = express(),
): Promise<[Application, (callback?: () => void) => Server]> {
const configOverrides: Partial<Options> = {};

Expand All @@ -119,11 +119,10 @@ export async function makeApp(
}

if (res && !res.headersSent) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const statusCode = typeof (err as any)?.statusCode === 'number' ? (err as any).statusCode : 500;

res.status(statusCode).json({
message: err instanceof Error ? err.message : err ?? 'Internal server error',
message: err instanceof Error ? err.message : (err ?? 'Internal server error'),
});
}
};
Expand All @@ -146,7 +145,7 @@ export async function makeApp(
res.setHeader('Content-Type', contentType);
}
},
})
}),
);

app.post(resolvedOptions.messagingEndpointPath, async (req, res) => {
Expand All @@ -169,8 +168,8 @@ export async function makeApp(
name: z.string(),
enabled: z.boolean().optional(),
route: z.string(),
})
)
}),
),
) ?? [];

adapters
Expand Down Expand Up @@ -200,7 +199,7 @@ export async function makeApp(
// after the app starts listening for requests.
const server = app.listen(
resolvedOptions.port,
callback ?? (() => console.log(`server listening on port ${resolvedOptions.port}`))
callback ?? (() => console.log(`server listening on port ${resolvedOptions.port}`)),
);

server.on('upgrade', async (req, socket, head) => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
"botbuilder": "4.1.6",
"botbuilder-dialogs-adaptive-runtime": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"eslint-plugin-only-warn": "^1.1.0",
"restify": "^11.1.0",
"zod": "^3.23.8"
},
"scripts": {
"build": "tsc -b",
"clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo",
"depcheck": "depcheck --config ../../.depcheckrc",
"lint": "eslint .",
"lint": "eslint . --config ../../eslint.config.cjs",
"postbuild": "downlevel-dts lib _ts3.4/lib --checksum"
},
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function resolveOptions(options: Partial<Options>, configuration: Configur
export async function start(
applicationRoot: string,
settingsDirectory: string,
options: Partial<Options> = {}
options: Partial<Options> = {},
): Promise<void> {
const [services, configuration] = await getRuntimeServices(applicationRoot, settingsDirectory);

Expand Down Expand Up @@ -104,7 +104,7 @@ export async function makeServer(
configuration: Configuration,
applicationRoot: string,
options: Partial<Options> = {},
server = restify.createServer()
server = restify.createServer(),
): Promise<restify.Server> {
server.use(restify.plugins.acceptParser(server.acceptable));
server.use(restify.plugins.queryParser());
Expand All @@ -125,12 +125,11 @@ export async function makeServer(
}

if (res && !res.headersSent) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const statusCode = typeof (err as any)?.statusCode === 'number' ? (err as any).statusCode : 500;

res.status(statusCode);
res.json({
message: err instanceof Error ? err.message : err ?? 'Internal server error',
message: err instanceof Error ? err.message : (err ?? 'Internal server error'),
});
}
};
Expand All @@ -155,8 +154,8 @@ export async function makeServer(
name: z.string(),
enabled: z.boolean().optional(),
route: z.string(),
})
)
}),
),
) ?? [];

adapters
Expand Down Expand Up @@ -187,7 +186,7 @@ export async function makeServer(
res.setHeader('Content-Type', contentType);
}
},
})
}),
);

server.on('upgrade', async (req, socket, head) => {
Expand Down

0 comments on commit 3b8fcab

Please sign in to comment.