diff --git a/libraries/botbuilder-dialogs-adaptive-runtime-core/eslint.config.cjs b/libraries/botbuilder-dialogs-adaptive-runtime-core/eslint.config.cjs deleted file mode 100644 index 63647b52cc..0000000000 --- a/libraries/botbuilder-dialogs-adaptive-runtime-core/eslint.config.cjs +++ /dev/null @@ -1,10 +0,0 @@ -const onlyWarn = require("eslint-plugin-only-warn"); -const sharedConfig = require("../../eslint.config.cjs") - -module.exports = [ - ...sharedConfig, - { - plugins: { - "only-warn": onlyWarn, - }, - }]; diff --git a/libraries/botbuilder-dialogs-adaptive-runtime-core/package.json b/libraries/botbuilder-dialogs-adaptive-runtime-core/package.json index 9c52c31d7b..12d35c465d 100644 --- a/libraries/botbuilder-dialogs-adaptive-runtime-core/package.json +++ b/libraries/botbuilder-dialogs-adaptive-runtime-core/package.json @@ -28,8 +28,7 @@ } }, "dependencies": { - "dependency-graph": "^1.0.0", - "eslint-plugin-only-warn": "^1.1.0" + "dependency-graph": "^1.0.0" }, "devDependencies": { "mocha": "^10.7.3", @@ -39,7 +38,7 @@ "build": "tsc -b", "clean": "rimraf _ts3.4 lib tsconfig.tsbuildinfo", "depcheck": "depcheck --config ../../.depcheckrc --ignores dependency-graph", - "lint": "eslint .", + "lint": "eslint . --config ../../eslint.config.cjs", "postbuild": "downlevel-dts lib _ts3.4/lib --checksum", "test": "nyc mocha", "test:min": "nyc --silent mocha --reporter dot" diff --git a/libraries/botbuilder-dialogs-adaptive-runtime-core/src/serviceCollection.ts b/libraries/botbuilder-dialogs-adaptive-runtime-core/src/serviceCollection.ts index a6a2679e37..cf7e3aac7b 100644 --- a/libraries/botbuilder-dialogs-adaptive-runtime-core/src/serviceCollection.ts +++ b/libraries/botbuilder-dialogs-adaptive-runtime-core/src/serviceCollection.ts @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import assert from 'assert'; +import assert, { ok } from 'assert'; import { DepGraph } from 'dependency-graph'; -import { ok } from 'assert'; import { stringify } from './util'; /** @@ -13,7 +12,7 @@ import { stringify } from './util'; * @template Initial true if the `initialValue` passed to the factory must be defined */ export type Factory = ( - initialValue: Initial extends true ? Type : Type | undefined + initialValue: Initial extends true ? Type : Type | undefined, ) => Type; /** @@ -26,7 +25,7 @@ export type Factory = ( */ export type DependencyFactory = ( dependencies: Dependencies, - initialValue: Initial extends true ? Type : Type | undefined + initialValue: Initial extends true ? Type : Type | undefined, ) => Type; /** @@ -97,7 +96,7 @@ export class ServiceCollection { addFactory( key: string, dependencies: string[], - factory: DependencyFactory + factory: DependencyFactory, ): this; /** @@ -106,7 +105,7 @@ export class ServiceCollection { addFactory( key: string, depsOrFactory: string[] | Factory, - maybeFactory?: DependencyFactory + maybeFactory?: DependencyFactory, ): this { const dependencies = Array.isArray(depsOrFactory) ? depsOrFactory : undefined; @@ -129,8 +128,6 @@ export class ServiceCollection { this.graph.removeNode(key); } - // Note: we have done the type checking above, so disabling no-explicit-any is okay. - // eslint-disable-next-line @typescript-eslint/no-explicit-any this.graph.addNode(key, factories.concat(factory) as any); return this; @@ -157,7 +154,7 @@ export class ServiceCollection { composeFactory( key: string, dependencies: string[], - factory: DependencyFactory + factory: DependencyFactory, ): this; /** @@ -166,7 +163,7 @@ export class ServiceCollection { composeFactory( key: string, depsOrFactory: string[] | Factory, - maybeFactory?: DependencyFactory + maybeFactory?: DependencyFactory, ): this { if (maybeFactory) { return this.addFactory( @@ -176,7 +173,7 @@ export class ServiceCollection { ok(value, `unable to create ${key}, initial value undefined`); return maybeFactory(dependencies, value); - } + }, ); } else { ok(typeof depsOrFactory === 'function', 'illegal invocation with undefined factory'); @@ -193,43 +190,49 @@ export class ServiceCollection { // depend on results of dependency registration private buildNodes>( generateNodes: () => string[], - reuseServices: Record = {} + reuseServices: Record = {}, ): ReturnType { // Consume all dependencies and then reset so updating registrations without re-registering // dependencies works this.dependencies.forEach((dependencies, node) => - dependencies.forEach((dependency) => this.graph.addDependency(node, stringify(dependency))) + dependencies.forEach((dependency) => this.graph.addDependency(node, stringify(dependency))), ); // Generate nodes after registering dependencies so ordering is correct const nodes = generateNodes(); - const services = nodes.reduce((services, service) => { - // Extra precaution - if (!this.graph.hasNode(service)) { - return services; - } + const services = nodes.reduce( + (services, service) => { + // Extra precaution + if (!this.graph.hasNode(service)) { + return services; + } - // Helper to generate return value - const assignValue = (value: unknown) => ({ - ...services, - [service]: value, - }); + // Helper to generate return value + const assignValue = (value: unknown) => ({ + ...services, + [service]: value, + }); - // Optionally reuse existing service - const reusedService = reuseServices[service]; - if (reusedService !== undefined) { - return assignValue(reusedService); - } + // Optionally reuse existing service + const reusedService = reuseServices[service]; + if (reusedService !== undefined) { + return assignValue(reusedService); + } - // Each node stores a list of factory methods. - const factories = this.graph.getNodeData(service); + // Each node stores a list of factory methods. + const factories = this.graph.getNodeData(service); - // Produce the instance by reducing those factories, passing the instance along for composition. - const instance = factories.reduce((value, factory) => factory(services, value), services[service]); + // Produce the instance by reducing those factories, passing the instance along for composition. + const instance = factories.reduce( + (value, factory) => factory(services, value), + services[service], + ); - return assignValue(instance); - }, >{}); + return assignValue(instance); + }, + >{}, + ); // Cache results for subsequent invocations that may desire pre-constructed instances Object.assign(this.cache, services); @@ -254,7 +257,7 @@ export class ServiceCollection { const services = this.buildNodes>( () => this.graph.dependenciesOf(key).concat(key), - initialServices + initialServices, ); return services[key]; diff --git a/libraries/botbuilder-dialogs-adaptive-runtime-core/test/serviceCollection.test.ts b/libraries/botbuilder-dialogs-adaptive-runtime-core/test/serviceCollection.test.ts index 2d9fe5d302..3d1badb1f4 100644 --- a/libraries/botbuilder-dialogs-adaptive-runtime-core/test/serviceCollection.test.ts +++ b/libraries/botbuilder-dialogs-adaptive-runtime-core/test/serviceCollection.test.ts @@ -11,7 +11,10 @@ class Bar { } class Baz { - constructor(public foo: Foo, public bar: Bar) {} + constructor( + public foo: Foo, + public bar: Bar, + ) {} } interface TestServices { @@ -129,7 +132,7 @@ describe('ServiceCollection', function () { services.composeFactory, Record>>( 'b', ['a'], - ({ a }, b) => ({ ...a, ...b }) + ({ a }, b) => ({ ...a, ...b }), ); const a = services.mustMakeInstance('a'); @@ -144,7 +147,7 @@ describe('ServiceCollection', function () { services.composeFactory, Record>>( 'b', ['a'], - ({ a }, b) => ({ ...a, ...b }) + ({ a }, b) => ({ ...a, ...b }), ); assert.throws(() => services.makeInstance('b')); });