Skip to content

Commit

Permalink
Fix issues in botbuilder-dialogs-declarative (#4813)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaavila authored Jan 6, 2025
1 parent 18f95ed commit 551267e
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 31 deletions.
10 changes: 0 additions & 10 deletions libraries/botbuilder-dialogs-declarative/eslint.config.cjs

This file was deleted.

3 changes: 1 addition & 2 deletions libraries/botbuilder-dialogs-declarative/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"botbuilder-dialogs": "4.1.6",
"botbuilder-stdlib": "4.1.6",
"chokidar": "^3.6.0",
"eslint-plugin-only-warn": "^1.1.0",
"zod": "^3.23.8"
},
"devDependencies": {
Expand All @@ -45,7 +44,7 @@
"build-docs": "typedoc --theme markdown --entryPoint botbuilder-dialogs-adaptive --excludePrivate --includeDeclarations --ignoreCompilerErrors --module amd --out ..\\..\\doc\\botbuilder-dialogs .\\lib\\index.d.ts --hideGenerator --name \"Bot Builder SDK - Dialogs\" --readme none",
"clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo",
"depcheck": "depcheck --config ../../.depcheckrc --ignores botbuilder-ai,botbuilder-dialogs-adaptive",
"lint": "eslint .",
"lint": "eslint . --config ../../eslint.config.cjs",
"postbuild": "downlevel-dts lib _ts3.4/lib --checksum",
"test": "yarn build && nyc mocha tests/**/*.test.js --exit",
"test:compat": "api-extractor run --verbose"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ComponentDeclarativeTypes {

const componentDeclarativeTypes = z.custom<ComponentDeclarativeTypes>(
(val: any) => typeof val.getDeclarativeTypes === 'function',
{ message: 'ComponentDeclarativeTypes' }
{ message: 'ComponentDeclarativeTypes' },
);

/**
Expand Down
3 changes: 3 additions & 0 deletions libraries/botbuilder-dialogs-declarative/src/pathUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class PathUtil {
* @returns True if the path is a directory; false otherwise.
*/
static isDirectory(path: string): boolean {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return lstatSync(path).isDirectory();
}

Expand All @@ -30,6 +31,7 @@ export class PathUtil {
* @returns Sub folders in the directory.
*/
static getDirectories(path: string): string[] {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return readdirSync(path)
.map((name: string): string => join(path, name))
.filter(PathUtil.isDirectory);
Expand All @@ -43,6 +45,7 @@ export class PathUtil {
* @returns The files in the directory.
*/
static getFiles(path: string, includeSubFolders = true): string[] {
// eslint-disable-next-line security/detect-non-literal-fs-filename
return readdirSync(path)
.map((name: string): string => join(path, name))
.reduce((files: string[], file: string): string[] => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable security/detect-non-literal-fs-filename */
/**
* @module botbuilder-dialogs-declarative
*/
Expand All @@ -7,7 +6,7 @@
* Licensed under the MIT License.
*/

import fs = require('fs');
import { readFileSync } from 'fs';
import { Resource } from './resource';

/**
Expand All @@ -33,7 +32,8 @@ export class FileResource extends Resource {
*/
readText(): string {
const filePath = this._fullname;
const text = fs.readFileSync(filePath, 'utf-8');
// eslint-disable-next-line security/detect-non-literal-fs-filename
const text = readFileSync(filePath, 'utf-8');
return text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class FolderResourceProvider extends ResourceProvider {
this._resources.clear();
const files: string[] = PathUtil.getFiles(this.directory, this.includeSubFolders);
const filteredFiles: string[] = files.filter((filename): boolean =>
this.resourceExplorer.resourceTypes.has(extname(filename).toLowerCase().replace(/^\./, ''))
this.resourceExplorer.resourceTypes.has(extname(filename).toLowerCase().replace(/^\./, '')),
);
for (let i = 0; i < filteredFiles.length; i++) {
const filename = filteredFiles[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class ResourceExplorer {
registerType<T>(
kind: string,
type: Newable<T>,
loader?: CustomDeserializer<T, Record<string, unknown>>
loader?: CustomDeserializer<T, Record<string, unknown>>,
): ResourceExplorer {
this.registerComponentTypes();
this.registerTypeInternal(kind, type, loader);
Expand Down Expand Up @@ -286,7 +286,7 @@ export class ResourceExplorer {
return value;
}
return this.load(value as { $kind: string } & Record<string, unknown>);
})
}),
);

if (result instanceof Dialog && !config['id']) {
Expand Down
11 changes: 6 additions & 5 deletions libraries/botbuilder-dialogs-declarative/tests/jsonLoad.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const buildQnAMakerTestFlowPreciseAnswer = (
resourceExplorer,
testName,
enablePreciseAnswer,
displayPreciseAnswerOnly
displayPreciseAnswerOnly,
) => {
const adapter = initializeAdapter(testName);
const dialog = resourceExplorer.loadType('QnAMakerBot.main.dialog');
Expand All @@ -213,6 +213,7 @@ const buildQnAMakerTestFlowPreciseAnswer = (

describe('Json load tests', function () {
let resourceExplorer;

beforeEach(function () {
const services = new ServiceCollection({
declarativeTypes: [],
Expand All @@ -226,7 +227,7 @@ describe('Json load tests', function () {
resourceExplorer = new ResourceExplorer({ declarativeTypes }).addFolder(
path.join(__dirname, 'resources/JsonDialog'),
true,
false
false,
);
});

Expand Down Expand Up @@ -510,7 +511,7 @@ describe('Json load tests', function () {
const suggestionActivity = QnACardBuilder.getSuggestionsCard(
suggestionList,
'Did you mean:',
'None of the above.'
'None of the above.',
);
await buildQnAMakerTestFlow(resourceExplorer, this.fullTitle())
.send('Q11')
Expand All @@ -528,7 +529,7 @@ describe('Json load tests', function () {
const suggestionActivity = QnACardBuilder.getSuggestionsCard(
suggestionList,
'Did you mean:',
'None of the above.'
'None of the above.',
);
const noAnswerActivity = 'No QnAMaker answers found.';
await buildQnAMakerTestFlow(resourceExplorer, this.fullTitle())
Expand All @@ -547,7 +548,7 @@ describe('Json load tests', function () {
const suggestionActivity = QnACardBuilder.getSuggestionsCard(
suggestionList,
'Did you mean:',
'None of the above.'
'None of the above.',
);
await buildQnAMakerTestFlow(resourceExplorer, this.fullTitle())
.send('Q11')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function assertResourceFound(explorer, id) {
const dialogs = explorer.getResources('dialog');
assert(
dialogs.some((dialog) => dialog.id == id),
"getResources('dialog') should return resources"
"getResources('dialog') should return resources",
);
}

Expand All @@ -29,7 +29,7 @@ function assertResourceNotFound(explorer, id) {
const dialogs = explorer.getResources('dialog');
assert(
dialogs.every((dialog) => dialog.id != id),
"getResouces('dialog') should not return resources"
"getResouces('dialog') should not return resources",
);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ describe('ResourceExplorer', function () {
assert.strictEqual(
dialog.id,
'test.dialog',
'resource id should be used as default dialog id if none assigned.'
'resource id should be used as default dialog id if none assigned.',
);
assert.strictEqual(dialog.triggers[0].actions[0].id, '1234567890');
assert.strictEqual(dialog.triggers[0].actions[1].id, 'test3.dialog');
Expand Down Expand Up @@ -275,7 +275,7 @@ describe('ResourceExplorer', function () {
const resourceExplorer = new ResourceExplorer({ declarativeTypes }).addFolder(
join(__dirname, './resources/CycleDetection'),
false,
false
false,
);

const root = resourceExplorer.loadType('root.dialog');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const assert = require('assert');
const fs = require('fs');
const Validator = require('jsonschema').Validator;
const util = require('util');
// eslint-disable-next-line security/detect-child-process
const exec = util.promisify(require('child_process').exec);

// Note: This file is intentionally not named *.test.js to ensure it isn't run
Expand All @@ -30,7 +29,7 @@ describe('Schema Merge Tests', function () {
resourceExplorer,
path.join(__dirname, '..', '..'),
true,
false
false,
);
const dialogResources = resourceProvider.getResources('dialog');
const dialogs = dialogResources
Expand Down Expand Up @@ -92,7 +91,7 @@ describe('Schema Merge Tests', function () {
[
'Generated schema differs from committed schema.',
'Run this test locally and commit the tests.*schema files to upload the correct and updated schema.',
].join('\n')
].join('\n'),
);
}

Expand Down

0 comments on commit 551267e

Please sign in to comment.