Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ESLint issues in botbuilder-dialogs #4832

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions libraries/botbuilder-dialogs/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const onlyWarn = require("eslint-plugin-only-warn");
const sharedConfig = require("../../eslint.config.cjs")
const sharedConfig = require('../../eslint.config.cjs');

module.exports = [
...sharedConfig,
{
ignores: ["**/vendor/"],
ignores: ['**/vendor/'],
},
{
plugins: {
"only-warn": onlyWarn,
},
}];
];
3 changes: 1 addition & 2 deletions libraries/botbuilder-dialogs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"@microsoft/recognizers-text-suite": "1.1.4",
"botbuilder-core": "4.1.6",
"botbuilder-dialogs-adaptive-runtime-core": "4.1.6",
"botframework-connector": "4.1.6",
"eslint-plugin-only-warn": "^1.1.0",
"botframework-connector": "4.1.6",
"globalize": "^1.7.0",
"lodash": "^4.17.21",
"uuid": "^10.0.0",
Expand Down
8 changes: 4 additions & 4 deletions libraries/botbuilder-dialogs/scripts/gen-cldr-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function main() {
await exec(
process.platform === 'win32' ? 'npm.cmd' : 'npm',
['i', `${cldrDataPackageName}@${cldrDataPackageVersion}`, '--no-save'],
{ cwd: tempDirectory, env: process.env }
{ cwd: tempDirectory, env: process.env },
);
} catch (err) {
plog('Could not install cldr-data');
Expand All @@ -88,17 +88,17 @@ async function main() {
numbersDirectoryPaths.forEach((v) => {
fs.copyFileSync(
path.join(cldrDataDirectory, v, numbersFileName),
path.join(vendorDirectory, v, numbersFileName)
path.join(vendorDirectory, v, numbersFileName),
);
});

fs.copyFileSync(
path.join(cldrDataDirectory, supplementalDirectoryName, likelySubtagsFileName),
path.join(vendorDirectory, supplementalDirectoryName, likelySubtagsFileName)
path.join(vendorDirectory, supplementalDirectoryName, likelySubtagsFileName),
);
fs.copyFileSync(
path.join(cldrDataDirectory, supplementalDirectoryName, numberingSystemsFileName),
path.join(vendorDirectory, supplementalDirectoryName, numberingSystemsFileName)
path.join(vendorDirectory, supplementalDirectoryName, numberingSystemsFileName),
);
} catch (err) {
plog('Could not copy files');
Expand Down
8 changes: 4 additions & 4 deletions libraries/botbuilder-dialogs/src/choices/choiceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class ChoiceFactory {
choices: (string | Choice)[],
text?: string,
speak?: string,
options?: ChoiceFactoryOptions
options?: ChoiceFactoryOptions,
): Partial<Activity> {
const channelId: string =
typeof channelOrContext === 'string' ? channelOrContext : channel.getChannelId(channelOrContext);
Expand Down Expand Up @@ -150,7 +150,7 @@ export class ChoiceFactory {
title: choice.value,
type: ActionTypes.ImBack,
value: choice.value,
} as CardAction)
}) as CardAction,
);
const attachment = CardFactory.heroCard(undefined, text, undefined, buttons);

Expand Down Expand Up @@ -178,7 +178,7 @@ export class ChoiceFactory {
choices: (string | Choice)[],
text?: string,
speak?: string,
options?: ChoiceFactoryOptions
options?: ChoiceFactoryOptions,
): Partial<Activity> {
const opt: ChoiceFactoryOptions = {
inlineSeparator: ', ',
Expand Down Expand Up @@ -229,7 +229,7 @@ export class ChoiceFactory {
choices: (string | Choice)[],
text?: string,
speak?: string,
options?: ChoiceFactoryOptions
options?: ChoiceFactoryOptions,
): Partial<Activity> {
const opt: ChoiceFactoryOptions = {
includeNumbers: true,
Expand Down
4 changes: 2 additions & 2 deletions libraries/botbuilder-dialogs/src/choices/findChoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ export interface FoundChoice {
export function findChoices(
utterance: string,
choices: (string | Choice)[],
options?: FindChoicesOptions
options?: FindChoicesOptions,
): ModelResult<FoundChoice>[] {
const opt: FindChoicesOptions = options || {};

// Normalize choices
const list: Choice[] = (choices || []).map((choice: Choice) =>
typeof choice === 'string' ? { value: choice } : choice
typeof choice === 'string' ? { value: choice } : choice,
);

// Build up full list of synonyms to search over.
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-dialogs/src/choices/findValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface SortedValue {
export function findValues(
utterance: string,
values: SortedValue[],
options?: FindValuesOptions
options?: FindValuesOptions,
): ModelResult<FoundValue>[] {
function indexOfToken(token: Token, startPos: number): number {
for (let i: number = startPos; i < tokens.length; i++) {
Expand Down Expand Up @@ -126,7 +126,7 @@ export function findValues(
index: number,
value: string,
vTokens: Token[],
startPos: number
startPos: number,
): ModelResult<FoundValue> | undefined {
// Match value to utterance and calculate total deviation.
// - The tokens are matched in order so "second last" will match in
Expand Down Expand Up @@ -223,7 +223,7 @@ export function findValues(

// Sort matches by score descending
matches = matches.sort(
(a: ModelResult<FoundValue>, b: ModelResult<FoundValue>) => b.resolution.score - a.resolution.score
(a: ModelResult<FoundValue>, b: ModelResult<FoundValue>) => b.resolution.score - a.resolution.score,
);

// Filter out duplicate matching indexes and overlapping characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { ModelResult } from './modelResult';
export function recognizeChoices(
utterance: string,
choices: (string | Choice)[],
options?: FindChoicesOptions
options?: FindChoicesOptions,
): ModelResult<FoundChoice>[] {
function matchChoiceByIndex(match: ModelResult<any>): void {
try {
Expand Down Expand Up @@ -77,14 +77,14 @@ export function recognizeChoices(
recognizeNumbers: true,
recognizeOrdinals: true,
} as FindChoicesOptions,
options
options,
);

// Normalize choices
const list: Choice[] = (choices || [])
.map((choice: Choice) => (typeof choice === 'string' ? { value: choice } : choice))
.filter(
(choice: Choice) => choice // TODO: does this do anything?
(choice: Choice) => choice, // TODO: does this do anything?
);

// Try finding choices by text search first
Expand Down
15 changes: 7 additions & 8 deletions libraries/botbuilder-dialogs/src/dialogContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export class DialogContext {
if (!dialog) {
throw new DialogContextError(
`DialogContext.beginDialog(): A dialog with an id of '${dialogId}' wasn't found.`,
this
this,
);
}

Expand Down Expand Up @@ -360,7 +360,7 @@ export class DialogContext {
*/
async prompt(
dialogId: string,
promptOrOptions: string | Partial<Activity> | PromptOptions
promptOrOptions: string | Partial<Activity> | PromptOptions,
): Promise<DialogTurnResult>;

/**
Expand All @@ -383,7 +383,7 @@ export class DialogContext {
async prompt(
dialogId: string,
promptOrOptions: string | Partial<Activity> | PromptOptions,
choices: (string | Choice)[]
choices: (string | Choice)[],
): Promise<DialogTurnResult>;

/**
Expand All @@ -405,7 +405,7 @@ export class DialogContext {
async prompt(
dialogId: string,
promptOrOptions: string | Partial<Activity>,
choices?: (string | Choice)[]
choices?: (string | Choice)[],
): Promise<DialogTurnResult> {
let options: PromptOptions;
if (
Expand Down Expand Up @@ -466,7 +466,7 @@ export class DialogContext {
if (!dialog) {
throw new DialogContextError(
`DialogContext.continueDialog(): Can't continue dialog. A dialog with an id of '${instance.id}' wasn't found.`,
this
this,
);
}

Expand Down Expand Up @@ -520,7 +520,7 @@ export class DialogContext {
if (!dialog) {
throw new DialogContextError(
`DialogContext.endDialog(): Can't resume previous dialog. A dialog with an id of '${instance.id}' wasn't found.`,
this
this,
);
}

Expand Down Expand Up @@ -582,7 +582,7 @@ export class DialogContext {
if (!dialog) {
throw new DialogContextError(
`DialogContext.repromptDialog(): Can't find a dialog with an id of '${instance.id}'.`,
this
this,
);
}

Expand Down Expand Up @@ -615,7 +615,6 @@ export class DialogContext {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let dc: DialogContext = this;
if (fromLeaf) {
// eslint-disable-next-line no-constant-condition
while (true) {
const childDc = dc.child;
if (childDc != undefined) {
Expand Down
5 changes: 4 additions & 1 deletion libraries/botbuilder-dialogs/src/dialogContextError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export class DialogContextError extends Error {
* @param {Error | string} error Source error or error message.
* @param {DialogContext} dialogContext Dialog context that is the source of the error.
*/
constructor(public readonly error: Error | string, dialogContext: DialogContext) {
constructor(
readonly error: Error | string,
dialogContext: DialogContext,
) {
super();

if (!(error instanceof Error) && typeof error !== 'string') {
Expand Down
13 changes: 6 additions & 7 deletions libraries/botbuilder-dialogs/src/dialogHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
export async function runDialog(
dialog: Dialog,
context: TurnContext,
accessor: StatePropertyAccessor<DialogState>
accessor: StatePropertyAccessor<DialogState>,
): Promise<void> {
if (!dialog) {
throw new Error('runDialog(): missing dialog');
Expand Down Expand Up @@ -76,7 +76,7 @@ export async function internalRun(
context: TurnContext,
dialogId: string,
dialogContext: DialogContext,
dialogStateManagerConfiguration?: DialogStateManagerConfiguration
dialogStateManagerConfiguration?: DialogStateManagerConfiguration,
): Promise<DialogTurnResult> {
// map TurnState into root dialog context.services
context.turnState.forEach((service, key) => {
Expand Down Expand Up @@ -122,7 +122,7 @@ export async function internalRun(
async function innerRun(
context: TurnContext,
dialogId: string,
dialogContext: DialogContext
dialogContext: DialogContext,
): Promise<DialogTurnResult> {
// Handle EoC and Reprompt event from a parent bot (can be root bot to skill or skill to skill)
if (isFromParentToSkill(context)) {
Expand Down Expand Up @@ -197,9 +197,8 @@ export function shouldSendEndOfConversationToParent(context: TurnContext, turnRe
if (claimIdentity && SkillValidation.isSkillClaim(claimIdentity.claims)) {
// EoC Activities returned by skills are bounced back to the bot by SkillHandler.
// In those cases we will have a SkillConversationReference instance in state.
const skillConversationReference: SkillConversationReference = context.turnState.get(
SkillConversationReferenceKey
);
const skillConversationReference: SkillConversationReference =
context.turnState.get(SkillConversationReferenceKey);
if (skillConversationReference) {
// If the skillConversationReference.OAuthScope is for one of the supported channels, we are at the root and we should not send an EoC.
return (
Expand Down Expand Up @@ -259,7 +258,7 @@ const sendStateSnapshotTrace = async (dialogContext: DialogContext): Promise<voi
'BotState',
'https://www.botframework.com/schemas/botState',
snapshot,
traceLabel
traceLabel,
);
await dialogContext.context.sendActivity(traceActivity);
};
8 changes: 4 additions & 4 deletions libraries/botbuilder-dialogs/src/dialogSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class DialogSet {
// If we are adding a new dialog with a conflicting name, add a suffix to avoid
// dialog name collisions.
let nextSuffix = 2;
// eslint-disable-next-line no-constant-condition

while (true) {
const suffixId = dialog.id + nextSuffix.toString();
if (!Object.prototype.hasOwnProperty.call(this.dialogs, suffixId)) {
Expand All @@ -166,8 +166,8 @@ export class DialogSet {
this.dialogs[dialog.id] = dialog;

// Automatically add any child dependencies the dialog might have
if (typeof ((dialog as any) as DialogDependencies).getDependencies == 'function') {
((dialog as any) as DialogDependencies).getDependencies().forEach((child: Dialog): void => {
if (typeof (dialog as any as DialogDependencies).getDependencies == 'function') {
(dialog as any as DialogDependencies).getDependencies().forEach((child: Dialog): void => {
this.add(child);
});
}
Expand All @@ -184,7 +184,7 @@ export class DialogSet {
async createContext(context: TurnContext): Promise<DialogContext> {
if (!this.dialogState) {
throw new Error(
'DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.'
'DialogSet.createContext(): the dialog set was not bound to a stateProperty when constructed.',
);
}
const state: DialogState = await this.dialogState.get(context, { dialogStack: [] } as DialogState);
Expand Down
6 changes: 3 additions & 3 deletions libraries/botbuilder-dialogs/src/dialogsBotComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class DialogsBotComponent extends BotComponent {
new ClassMemoryScope(),
new ThisMemoryScope(),
new ConversationMemoryScope(),
new UserMemoryScope()
new UserMemoryScope(),
);
});

Expand All @@ -61,8 +61,8 @@ export class DialogsBotComponent extends BotComponent {
new HashPathResolver(),
new AtAtPathResolver(),
new AtPathResolver(),
new PercentPathResolver()
)
new PercentPathResolver(),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { ComponentMemoryScopes, ComponentPathResolvers, MemoryScope, PathResolve
*/
export class DialogsComponentRegistration
extends ComponentRegistration
implements ComponentMemoryScopes, ComponentPathResolvers {
implements ComponentMemoryScopes, ComponentPathResolvers
{
private readonly services = new ServiceCollection({
memoryScopes: [],
pathResolvers: [],
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-dialogs/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under the MIT License.
*/

/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
const Chinese = require('../vendor/cldr-data/main/zh/numbers.json');
const English = require('../vendor/cldr-data/main/en/numbers.json');
const French = require('../vendor/cldr-data/main/fr/numbers.json');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ComponentPathResolvers {

const componentPathResolvers = z.custom<ComponentPathResolvers>(
(val: any) => typeof val.getPathResolvers === 'function',
{ message: 'ComponentPathResolvers' }
{ message: 'ComponentPathResolvers' },
);

/**
Expand Down
Loading
Loading