Skip to content

Commit

Permalink
fix: [#4684] ESLint issues in botbuilder-ai (#4790)
Browse files Browse the repository at this point in the history
* Fix eslint issues in botbuilder-ai

* Add build step to lint GitHub action
  • Loading branch information
ceciliaavila authored Nov 22, 2024
1 parent ba67046 commit c92f998
Show file tree
Hide file tree
Showing 37 changed files with 209 additions and 219 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ jobs:
- name: yarn
run: yarn --frozen-lockfile

- name: yarn build
run: yarn build

- name: yarn lint
run: yarn lint
11 changes: 0 additions & 11 deletions libraries/botbuilder-ai/eslint.config.cjs

This file was deleted.

3 changes: 1 addition & 2 deletions libraries/botbuilder-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"botbuilder-dialogs-declarative": "4.1.6",
"botframework-connector": "4.1.6",
"eslint-plugin-only-warn": "^1.1.0",
"lodash": "^4.17.21",
"node-fetch": "^2.7.0",
"url-parse": "^1.5.10",
Expand All @@ -51,7 +50,7 @@
"build:rollup": "yarn clean && yarn build && api-extractor run --verbose --local",
"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",
"test": "npm-run-all build test:mocha",
"test:mocha": "nyc mocha tests",
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/custom.window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

declare global {
interface Window {} // eslint-disable-line @typescript-eslint/no-empty-interface
interface Window {} // eslint-disable-line @typescript-eslint/no-empty-object-type
}

export type window = Window;
20 changes: 10 additions & 10 deletions libraries/botbuilder-ai/src/customQuestionAnswering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface QnAMakerClient {
turnContext: TurnContext,
options?: QnAMakerOptions,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>
telemetryMetrics?: Record<string, number>,
): Promise<QnAMakerResult[]>;

/**
Expand All @@ -59,7 +59,7 @@ export interface QnAMakerClient {
turnContext: TurnContext,
options?: QnAMakerOptions,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>
telemetryMetrics?: Record<string, number>,
): Promise<QnAMakerResults>;

/**
Expand Down Expand Up @@ -111,7 +111,7 @@ export interface QnAMakerTelemetryClient {
context: TurnContext,
options?: QnAMakerOptions,
telemetryProperties?: { [key: string]: string },
telemetryMetrics?: { [key: string]: number }
telemetryMetrics?: { [key: string]: number },
): Promise<QnAMakerResult[]>;
}

Expand Down Expand Up @@ -142,7 +142,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
private readonly endpoint: QnAMakerEndpoint,
options: QnAMakerOptions = {},
telemetryClient?: BotTelemetryClient,
logPersonalInformation?: boolean
logPersonalInformation?: boolean,
) {
if (!endpoint) {
throw new TypeError('QnAMaker requires valid QnAMakerEndpoint.');
Expand Down Expand Up @@ -215,7 +215,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
context: TurnContext,
options?: QnAMakerOptions,
telemetryProperties?: { [key: string]: string },
telemetryMetrics?: { [key: string]: number }
telemetryMetrics?: { [key: string]: number },
): Promise<QnAMakerResult[]> {
if (!context) {
throw new TypeError('QnAMaker.getAnswers() requires a TurnContext.');
Expand Down Expand Up @@ -243,7 +243,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
context: TurnContext,
options: QnAMakerOptions,
telemetryProperties: { [key: string]: string },
telemetryMetrics: { [key: string]: number }
telemetryMetrics: { [key: string]: number },
): Promise<QnAMakerResults> {
if (!context) {
throw new TypeError('CustomQuestionAnswering.getAnswersRaw() requires a TurnContext.');
Expand All @@ -266,7 +266,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
context: TurnContext,
options: QnAMakerOptions,
telemetryProperties: { [key: string]: string },
telemetryMetrics: { [key: string]: number }
telemetryMetrics: { [key: string]: number },
): Promise<QnAMakerResults> {
const question: string = this.getTrimmedMessageText(context);
const userId = context?.activity?.from?.id;
Expand Down Expand Up @@ -327,13 +327,13 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
qnaResults: QnAMakerResult[],
turnContext: TurnContext,
telemetryProperties?: { [key: string]: string },
telemetryMetrics?: { [key: string]: number }
telemetryMetrics?: { [key: string]: number },
): Promise<void> {
const [properties, metrics] = await this.fillQnAEvent(
qnaResults,
turnContext,
telemetryProperties,
telemetryMetrics
telemetryMetrics,
);

this.telemetryClient.trackEvent({
Expand All @@ -357,7 +357,7 @@ export class CustomQuestionAnswering implements QnAMakerClient, QnAMakerTelemetr
qnaResults: QnAMakerResult[],
turnContext: TurnContext,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>
telemetryMetrics?: Record<string, number>,
): Promise<[Record<string, string>, Record<string, number>]> {
const properties: Record<string, string> = {
[QnATelemetryConstants.knowledgeBaseIdProperty]: this.endpoint.knowledgeBaseId,
Expand Down
6 changes: 2 additions & 4 deletions libraries/botbuilder-ai/src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/**
* @module botbuilder
*/
Expand All @@ -8,7 +6,7 @@
* Licensed under the MIT License.
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
const window = require('./custom.window');

/**
Expand All @@ -18,7 +16,7 @@ const window = require('./custom.window');
*/
export function getFetch() {
if (global) {
return (global.fetch = require('node-fetch'));
return (global.fetch = require('node-fetch')); // eslint-disable-line @typescript-eslint/no-require-imports
}

return window?.fetch;
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/instanceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ export interface InstanceData {
/**
* Any extra properties.
*/
[propName: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
[propName: string]: any;
}
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/intentData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface IntentData {
/**
* Any extra properties.
*/
[propName: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
[propName: string]: any;
}
3 changes: 2 additions & 1 deletion libraries/botbuilder-ai/src/luisAdaptivePredictionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export interface LuisAdaptivePredictionOptionsConfiguration {
* Converts optional parameters for a LUIS prediction request.
*/
export class LuisAdaptivePredictionOptionsConverter
implements Converter<LuisAdaptivePredictionOptionsConfiguration, LuisAdaptivePredictionOptions> {
implements Converter<LuisAdaptivePredictionOptionsConfiguration, LuisAdaptivePredictionOptions>
{
/**
* Converts the provided options configuration into an object of [LuisAdaptivePredictionOptions](xref:botbuilder-ai.LuisAdaptivePredictionOptions) type.
*
Expand Down
8 changes: 4 additions & 4 deletions libraries/botbuilder-ai/src/luisAdaptiveRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe
* The flag to indicate in personal information should be logged in telemetry.
*/
logPersonalInformation: BoolExpression = new BoolExpression(
'=settings.runtimeSettings.telemetry.logPersonalInformation'
'=settings.runtimeSettings.telemetry.logPersonalInformation',
);

/**
Expand Down Expand Up @@ -140,7 +140,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe
dialogContext: DialogContext,
activity: Activity,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>
telemetryMetrics?: Record<string, number>,
): Promise<RecognizerResult> {
// Validate passed in activity matches turn activity
const context = dialogContext.context;
Expand All @@ -167,7 +167,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe
dialogContext,
'LuisResult',
this.fillRecognizerResultTelemetryProperties(result, telemetryProperties, dialogContext),
telemetryMetrics
telemetryMetrics,
);

return result;
Expand Down Expand Up @@ -231,7 +231,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe
protected fillRecognizerResultTelemetryProperties(
recognizerResult: RecognizerResult,
telemetryProperties: { [key: string]: string },
dialogContext: DialogContext
dialogContext: DialogContext,
): { [key: string]: string } {
const logPersonalInfo = this.logPersonalInformation.tryGetValue(dialogContext.state);
const applicationId = this.applicationId.tryGetValue(dialogContext.state);
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/luisBotComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class LuisBotComponent extends BotComponent {
},
];
},
})
}),
);
}
}
25 changes: 12 additions & 13 deletions libraries/botbuilder-ai/src/luisRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export interface LuisRecognizerTelemetryClient {
recognize(
context: TurnContext,
telemetryProperties?: { [key: string]: string },
telemetryMetrics?: { [key: string]: number }
telemetryMetrics?: { [key: string]: number },
): Promise<RecognizerResult>;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ const UnsafeLuisRecognizerUnion = z.custom<LuisRecognizerOptionsV3 | LuisRecogni
z.record(z.unknown()).safeParse(val).success,
{
message: 'LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions',
}
},
);

/**
Expand Down Expand Up @@ -301,7 +301,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
constructor(
application: LuisApplication | string,
options?: LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions,
includeApiResults?: boolean
includeApiResults?: boolean,
) {
if (typeof application === 'string') {
const parsedEndpoint: Url = Url(application);
Expand Down Expand Up @@ -440,7 +440,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
context: DialogContext | TurnContext,
telemetryProperties?: Record<string, string>,
telemetryMetrics?: Record<string, number>,
options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions
options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions,
): Promise<RecognizerResult>;

/**
Expand All @@ -451,7 +451,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
*/
async recognize(
utterance: string,
options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions
options?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions,
): Promise<RecognizerResult>;

/**
Expand All @@ -465,7 +465,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
| LuisRecognizerOptionsV3
| LuisPredictionOptions,
maybeTelemetryMetrics?: Record<string, number>,
maybeOptions?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions
maybeOptions?: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions,
): Promise<RecognizerResult> {
// This type check, when true, logically implies that the function is being invoked as the two-argument string + optional options overload variant.
if (typeof contextOrUtterance === 'string') {
Expand Down Expand Up @@ -544,7 +544,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
recognizerResult: RecognizerResult,
turnContext: TurnContext,
telemetryProperties?: { [key: string]: string },
telemetryMetrics?: { [key: string]: number }
telemetryMetrics?: { [key: string]: number },
): Promise<void> {
await this.fillTelemetryProperties(recognizerResult, turnContext, telemetryProperties).then((props) => {
this.telemetryClient.trackEvent({
Expand All @@ -566,7 +566,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
protected async fillTelemetryProperties(
recognizerResult: RecognizerResult,
turnContext: TurnContext,
telemetryProperties?: { [key: string]: string }
telemetryProperties?: { [key: string]: string },
): Promise<{ [key: string]: string }> {
const [firstIntent, secondIntent] = LuisRecognizer.sortedIntents(recognizerResult);

Expand Down Expand Up @@ -617,7 +617,6 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
// If the `error` received is a azure-cognitiveservices-luis-runtime error,
// it may have a `response` property and `response.statusCode`.
// If these properties exist, we should populate the error with a correct and informative error message.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const response: Record<'status', number> = (error as any).response;

if (response?.status) {
Expand Down Expand Up @@ -660,7 +659,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
// Merges the default options set by the Recognizer contructor with the 'user' options passed into the 'recognize' method
private setLuisPredictionOptions(
defaultOptions: LuisPredictionOptions,
userOptions: LuisPredictionOptions
userOptions: LuisPredictionOptions,
): LuisPredictionOptions {
return Object.assign(defaultOptions, userOptions);
}
Expand All @@ -669,19 +668,19 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
private validateLuisApplication(): void {
if (!this.application.applicationId) {
throw new Error(
`Invalid \`applicationId\` value detected: ${this.application.applicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".`
`Invalid \`applicationId\` value detected: ${this.application.applicationId}\nPlease make sure your applicationId is a valid LUIS Application Id, e.g. "b31aeaf3-3511-495b-a07f-571fc873214b".`,
);
}
if (!this.application.endpointKey) {
throw new Error(
`Invalid \`endpointKey\` value detected: ${this.application.endpointKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".`
`Invalid \`endpointKey\` value detected: ${this.application.endpointKey}\nPlease make sure your endpointKey is a valid LUIS Endpoint Key, e.g. "048ec46dc58e495482b0c447cfdbd291".`,
);
}
}

// Builds a LuisRecognizer Strategy depending on the options passed
private buildRecognizer(
userOptions: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions
userOptions: LuisRecognizerOptionsV2 | LuisRecognizerOptionsV3 | LuisPredictionOptions,
): LuisRecognizerV3 | LuisRecognizerV2 {
if (isLuisRecognizerOptionsV3(userOptions)) {
return new LuisRecognizerV3(this.application, userOptions);
Expand Down
5 changes: 4 additions & 1 deletion libraries/botbuilder-ai/src/luisRecognizerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export abstract class LuisRecognizerInternal {
* @param {LuisApplication} application An object conforming to the [LuisApplication](xref:botbuilder-ai.LuisApplication) definition.
* @param {LuisRecognizerOptions} _options Optional. Options object used to control predictions. Should conform to the [LuisRecognizerOptions](xref:botbuilder-ai.LuisRecognizerOptions) definition.
*/
constructor(public application: LuisApplication, _options?: LuisRecognizerOptions) {
constructor(
public application: LuisApplication,
_options?: LuisRecognizerOptions,
) {
if (!application) {
throw new Error('Null Application\n');
}
Expand Down
Loading

0 comments on commit c92f998

Please sign in to comment.