diff --git a/libraries/adaptive-expressions/etc/adaptive-expressions.api.md b/libraries/adaptive-expressions/etc/adaptive-expressions.api.md index 76eda96dea..e5cdff4fa0 100644 --- a/libraries/adaptive-expressions/etc/adaptive-expressions.api.md +++ b/libraries/adaptive-expressions/etc/adaptive-expressions.api.md @@ -3017,6 +3017,7 @@ export class Quantifier { constructor(variable: string, type: QuantifierType, bindings: string[]); // (undocumented) readonly bindings: string[]; + // (undocumented) toString(): string; // (undocumented) readonly type: QuantifierType; @@ -3339,6 +3340,7 @@ export class TriggerTree { readonly optimizers: Optimizer[]; removeTrigger(trigger: Trigger): boolean; root: Node_2; + // (undocumented) toString(): string; totalTriggers: number; treeToString(indent?: number): string; diff --git a/libraries/adaptive-expressions/src/builtinFunctions/addDays.ts b/libraries/adaptive-expressions/src/builtinFunctions/addDays.ts index 4c447bd288..ad2b214431 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/addDays.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/addDays.ts @@ -17,10 +17,13 @@ export class AddDays extends TimeTransformEvaluator { * Initializes a new instance of the [AddDays](xref:adaptive-expressions.AddDays) class. */ public constructor() { - super(ExpressionType.AddDays, (ts: Date, num: number): Date => { - const newDate = new Date(ts); - newDate.setDate(ts.getDate() + num); - return newDate; - }); + super( + ExpressionType.AddDays, + (ts: Date, num: number): Date => { + const newDate = new Date(ts); + newDate.setDate(ts.getDate() + num); + return newDate; + } + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/addHours.ts b/libraries/adaptive-expressions/src/builtinFunctions/addHours.ts index 8a6ca3b066..615b1affcf 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/addHours.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/addHours.ts @@ -17,10 +17,13 @@ export class AddHours extends TimeTransformEvaluator { * Initializes a new instance of the [AddHours](xref:adaptive-expressions.AddHours) class. */ public constructor() { - super(ExpressionType.AddHours, (ts: Date, num: number): Date => { - const newDate = new Date(ts); - newDate.setHours(ts.getHours() + num); - return newDate; - }); + super( + ExpressionType.AddHours, + (ts: Date, num: number): Date => { + const newDate = new Date(ts); + newDate.setHours(ts.getHours() + num); + return newDate; + } + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/addMinutes.ts b/libraries/adaptive-expressions/src/builtinFunctions/addMinutes.ts index becf0a3708..eae8db5d73 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/addMinutes.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/addMinutes.ts @@ -17,10 +17,13 @@ export class AddMinutes extends TimeTransformEvaluator { * Initializes a new instance of the [AddMinutes](xref:adaptive-expressions.AddMinutes) class. */ public constructor() { - super(ExpressionType.AddMinutes, (ts: Date, num: number): Date => { - const newDate = new Date(ts); - newDate.setMinutes(ts.getMinutes() + num); - return newDate; - }); + super( + ExpressionType.AddMinutes, + (ts: Date, num: number): Date => { + const newDate = new Date(ts); + newDate.setMinutes(ts.getMinutes() + num); + return newDate; + } + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/addSeconds.ts b/libraries/adaptive-expressions/src/builtinFunctions/addSeconds.ts index 717519781f..dd01b87650 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/addSeconds.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/addSeconds.ts @@ -17,10 +17,13 @@ export class AddSeconds extends TimeTransformEvaluator { * Initializes a new instance of the [AddSeconds](xref:adaptive-expressions.AddSeconds) class. */ public constructor() { - super(ExpressionType.AddSeconds, (ts: Date, num: number): Date => { - const newDate = new Date(ts); - newDate.setSeconds(ts.getSeconds() + num); - return newDate; - }); + super( + ExpressionType.AddSeconds, + (ts: Date, num: number): Date => { + const newDate = new Date(ts); + newDate.setSeconds(ts.getSeconds() + num); + return newDate; + } + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/addToTime.ts b/libraries/adaptive-expressions/src/builtinFunctions/addToTime.ts index aa60e1e63c..0f1fe6b692 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/addToTime.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/addToTime.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ -import dayjs, { OpUnitType } from 'dayjs'; +import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); import { Expression } from '../expression'; diff --git a/libraries/adaptive-expressions/src/builtinFunctions/comparisonEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/comparisonEvaluator.ts index f1025fe168..4ed05c4626 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/comparisonEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/comparisonEvaluator.ts @@ -24,6 +24,7 @@ import { ReturnType } from '../returnType'; export class ComparisonEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [ComparisonEvaluator](xref:adaptive-expressions.ComparisonEvaluator) class. + * * @param type Name of the built-in function. * @param func The comparison function, it takes a list of objects and returns a boolean. * @param validator [ValidateExpressionDelegate](xref:adaptive-expressions.ValidateExpressionDelegate) for input arguments. diff --git a/libraries/adaptive-expressions/src/builtinFunctions/convertFromUTC.ts b/libraries/adaptive-expressions/src/builtinFunctions/convertFromUTC.ts index 5217b26203..67545f2214 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/convertFromUTC.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/convertFromUTC.ts @@ -56,7 +56,12 @@ export class ConvertFromUTC extends ExpressionEvaluator { /** * @private */ - private static evalConvertFromUTC(timeStamp: string, destinationTimeZone: string, format?: string, locale?: string): ValueWithError { + private static evalConvertFromUTC( + timeStamp: string, + destinationTimeZone: string, + format?: string, + locale?: string + ): ValueWithError { let result: string; let error: string; error = InternalFunctionUtils.verifyISOTimestamp(timeStamp); @@ -68,7 +73,7 @@ export class ConvertFromUTC extends ExpressionEvaluator { if (!error) { try { result = dayjs(timeStamp).locale(locale).tz(timeZone).format(format); - } catch (e) { + } catch { error = `${format} is not a valid timestamp format`; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/convertToUTC.ts b/libraries/adaptive-expressions/src/builtinFunctions/convertToUTC.ts index 9ef2ccc22d..e5addcb540 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/convertToUTC.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/convertToUTC.ts @@ -65,7 +65,12 @@ export class ConvertToUTC extends ExpressionEvaluator { /** * @private */ - private static evalConvertToUTC(timeStamp: string, sourceTimezone: string, format?: string, locale?: string): ValueWithError { + private static evalConvertToUTC( + timeStamp: string, + sourceTimezone: string, + format?: string, + locale?: string + ): ValueWithError { let result: string; let error: string; let formattedSourceTime: string; @@ -80,14 +85,14 @@ export class ConvertToUTC extends ExpressionEvaluator { try { const sourceTime = dayjs.tz(timeStamp, timeZone); formattedSourceTime = sourceTime.format(); - } catch (e) { + } catch { error = `${timeStamp} with ${timeZone} is not a valid timestamp with specified timeZone:`; } if (!error) { try { result = dayjs(formattedSourceTime).locale(locale).tz('Etc/UTC').format(format); - } catch (e) { + } catch { error = `${format} is not a valid timestamp format`; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dataUri.ts b/libraries/adaptive-expressions/src/builtinFunctions/dataUri.ts index d2baa7c6a3..3c2de6ffcd 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dataUri.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dataUri.ts @@ -28,8 +28,7 @@ export class DataUri extends ExpressionEvaluator { */ private static evaluator(): EvaluateExpressionDelegate { return FunctionUtils.apply( - (args: any[]): string => - 'data:text/plain;charset=utf-8;base64,'.concat(btoa(args[0])), + (args: any[]): string => 'data:text/plain;charset=utf-8;base64,'.concat(btoa(args[0])), FunctionUtils.verifyString ); } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dateFunc.ts b/libraries/adaptive-expressions/src/builtinFunctions/dateFunc.ts index b22d2c44e7..7c325caeb5 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dateFunc.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dateFunc.ts @@ -30,17 +30,13 @@ export class DateFunc extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: dayjs(args[0]).utc().format('M/DD/YYYY'), error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: dayjs(args[0]).utc().format('M/DD/YYYY'), error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dateTimeDiff.ts b/libraries/adaptive-expressions/src/builtinFunctions/dateTimeDiff.ts index 8776d75eb8..74e9816245 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dateTimeDiff.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dateTimeDiff.ts @@ -6,7 +6,6 @@ * Licensed under the MIT License. */ -import bigInt from 'big-integer'; import { Expression } from '../expression'; import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator'; import { ExpressionType } from '../expressionType'; diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dayOfMonth.ts b/libraries/adaptive-expressions/src/builtinFunctions/dayOfMonth.ts index 06db59ef3b..4ebded0361 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dayOfMonth.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dayOfMonth.ts @@ -27,17 +27,13 @@ export class DayOfMonth extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: new Date(args[0]).getUTCDate(), error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: new Date(args[0]).getUTCDate(), error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dayOfWeek.ts b/libraries/adaptive-expressions/src/builtinFunctions/dayOfWeek.ts index 8555485ca2..de96a44840 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dayOfWeek.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dayOfWeek.ts @@ -27,17 +27,13 @@ export class DayOfWeek extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: new Date(args[0]).getUTCDay(), error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: new Date(args[0]).getUTCDay(), error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/dayOfYear.ts b/libraries/adaptive-expressions/src/builtinFunctions/dayOfYear.ts index 5c0ef32306..c58a447e9a 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/dayOfYear.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/dayOfYear.ts @@ -32,17 +32,13 @@ export class DayOfYear extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: dayjs(args[0]).utc().dayOfYear(), error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: dayjs(args[0]).utc().dayOfYear(), error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/equal.ts b/libraries/adaptive-expressions/src/builtinFunctions/equal.ts index 5a880f669f..86ba9dbdcb 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/equal.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/equal.ts @@ -8,7 +8,6 @@ import { ExpressionType } from '../expressionType'; import { FunctionUtils } from '../functionUtils'; -import { InternalFunctionUtils } from '../functionUtils.internal'; import { ComparisonEvaluator } from './comparisonEvaluator'; /** diff --git a/libraries/adaptive-expressions/src/builtinFunctions/formatDateTime.ts b/libraries/adaptive-expressions/src/builtinFunctions/formatDateTime.ts index 58b1a6bd2a..357623f6f5 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/formatDateTime.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/formatDateTime.ts @@ -52,7 +52,7 @@ export class FormatDateTime extends ExpressionEvaluator { } else { try { dateString = new Date(`${arg}Z`).toISOString(); - } catch (err) { + } catch { dateString = new Date(arg).toISOString(); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/getFutureTime.ts b/libraries/adaptive-expressions/src/builtinFunctions/getFutureTime.ts index c32d6d2c40..623aa50654 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/getFutureTime.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/getFutureTime.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ -import dayjs, { OpUnitType } from 'dayjs'; +import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); import { Expression } from '../expression'; @@ -59,6 +59,11 @@ export class GetFutureTime extends ExpressionEvaluator { * @private */ private static validator(expression: Expression): void { - FunctionUtils.validateOrder(expression, [ReturnType.String, ReturnType.String], ReturnType.Number, ReturnType.String); + FunctionUtils.validateOrder( + expression, + [ReturnType.String, ReturnType.String], + ReturnType.Number, + ReturnType.String + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/getPastTime.ts b/libraries/adaptive-expressions/src/builtinFunctions/getPastTime.ts index 267592289b..915849f9a2 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/getPastTime.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/getPastTime.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ -import dayjs, { OpUnitType } from 'dayjs'; +import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); import { Expression } from '../expression'; @@ -59,6 +59,11 @@ export class GetPastTime extends ExpressionEvaluator { * @private */ private static validator(expression: Expression): void { - FunctionUtils.validateOrder(expression, [ReturnType.String, ReturnType.String], ReturnType.Number, ReturnType.String); + FunctionUtils.validateOrder( + expression, + [ReturnType.String, ReturnType.String], + ReturnType.Number, + ReturnType.String + ); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/getTimeOfDay.ts b/libraries/adaptive-expressions/src/builtinFunctions/getTimeOfDay.ts index 7b05e9d087..8466c28867 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/getTimeOfDay.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/getTimeOfDay.ts @@ -49,7 +49,6 @@ export class GetTimeOfDay extends ExpressionEvaluator { } else { return { value, error }; } - } } else { // utc iso format diff --git a/libraries/adaptive-expressions/src/builtinFunctions/indicesAndValues.ts b/libraries/adaptive-expressions/src/builtinFunctions/indicesAndValues.ts index ab0540c1c5..401b7dc003 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/indicesAndValues.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/indicesAndValues.ts @@ -1,4 +1,3 @@ -/* eslint-disable security/detect-object-injection */ /** * @module adaptive-expressions */ @@ -36,6 +35,7 @@ export class IndicesAndValues extends ExpressionEvaluator { * @private */ private static evaluator(expression: Expression, state: any, options: Options): ValueWithError { + // eslint-disable-next-line @typescript-eslint/ban-types let result: object = undefined; let error: string = undefined; let value: any = undefined; diff --git a/libraries/adaptive-expressions/src/builtinFunctions/jPath.ts b/libraries/adaptive-expressions/src/builtinFunctions/jPath.ts index 96054d9c2f..1dd040daa7 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/jPath.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/jPath.ts @@ -35,14 +35,16 @@ export class JPath extends ExpressionEvaluator { /** * @private */ + // eslint-disable-next-line @typescript-eslint/ban-types private static evalJPath(jsonEntity: object | string, path: string): ValueWithError { let error: string; let evaled: any; + // eslint-disable-next-line @typescript-eslint/ban-types let json: object; if (typeof jsonEntity === 'string') { try { json = JSON.parse(jsonEntity); - } catch (e) { + } catch { error = `${jsonEntity} is not a valid json string`; } } else if (typeof jsonEntity === 'object') { diff --git a/libraries/adaptive-expressions/src/builtinFunctions/mod.ts b/libraries/adaptive-expressions/src/builtinFunctions/mod.ts index 4042cb5ec5..f6d2ba0a1d 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/mod.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/mod.ts @@ -30,7 +30,7 @@ export class Mod extends ExpressionEvaluator { let error: string; let value: any; if (Number(args[1]) === 0) { - error = `Cannot mod by 0.`; + error = 'Cannot mod by 0.'; } else { value = args[0] % args[1]; } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/month.ts b/libraries/adaptive-expressions/src/builtinFunctions/month.ts index d2b76a7cdf..86e875d474 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/month.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/month.ts @@ -27,17 +27,13 @@ export class Month extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: new Date(args[0]).getUTCMonth() + 1, error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: new Date(args[0]).getUTCMonth() + 1, error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/multivariateNumericEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/multivariateNumericEvaluator.ts index 414fcb96dc..7350a130e4 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/multivariateNumericEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/multivariateNumericEvaluator.ts @@ -16,6 +16,7 @@ import { ReturnType } from '../returnType'; export class MultivariateNumericEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [MultivariateNumericEvaluator](xref:adaptive-expressions.MultivariateNumericEvaluator) class. + * * @param type Name of the built-in function. * @param func The evaluation function, it takes a list of objects and returns a number. * @param verify Optional. [VerifyExpression](xref:adaptive-expressions.VerifyExpression) function to verify each child's result. diff --git a/libraries/adaptive-expressions/src/builtinFunctions/notEqual.ts b/libraries/adaptive-expressions/src/builtinFunctions/notEqual.ts index b904d3171d..b6ea353e38 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/notEqual.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/notEqual.ts @@ -8,7 +8,6 @@ import { ExpressionType } from '../expressionType'; import { FunctionUtils } from '../functionUtils'; -import { InternalFunctionUtils } from '../functionUtils.internal'; import { ComparisonEvaluator } from './comparisonEvaluator'; /** diff --git a/libraries/adaptive-expressions/src/builtinFunctions/numberTransformEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/numberTransformEvaluator.ts index 6489e23007..210609bdaf 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/numberTransformEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/numberTransformEvaluator.ts @@ -16,6 +16,7 @@ import { ReturnType } from '../returnType'; export class NumberTransformEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [NumberTransformEvaluator](xref:adaptive-expressions.NumberTransformEvaluator) class. + * * @param type Name of the built-in function. * @param func The evaluation function, it takes a list of objects and returns a number. */ diff --git a/libraries/adaptive-expressions/src/builtinFunctions/numericEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/numericEvaluator.ts index b94f5608fc..47593df8e8 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/numericEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/numericEvaluator.ts @@ -16,6 +16,7 @@ import { ReturnType } from '../returnType'; export class NumericEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [NumericEvaluator](xref:adaptive-expressions.NumericEvaluator) class. + * * @param type Name of the built-in function. * @param func The evaluation function, it takes a list of objects and returns a number. */ diff --git a/libraries/adaptive-expressions/src/builtinFunctions/rand.ts b/libraries/adaptive-expressions/src/builtinFunctions/rand.ts index efb358c9b3..b21ee06e1b 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/rand.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/rand.ts @@ -34,6 +34,7 @@ export class Rand extends ExpressionEvaluator { const [maybeMinValue, maybeMaxValue] = expression.children; + // eslint-disable-next-line prefer-const ({ value: minValue, error } = maybeMinValue.tryEvaluate(state, options)); if (error) { return { value: undefined, error }; @@ -42,6 +43,7 @@ export class Rand extends ExpressionEvaluator { return { value: undefined, error: `${minValue} is not an integer.` }; } + // eslint-disable-next-line prefer-const ({ value: maxValue, error } = maybeMaxValue.tryEvaluate(state, options)); if (error) { return { value: undefined, error }; diff --git a/libraries/adaptive-expressions/src/builtinFunctions/replaceIgnoreCase.ts b/libraries/adaptive-expressions/src/builtinFunctions/replaceIgnoreCase.ts index dfb11860ea..248d673cc6 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/replaceIgnoreCase.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/replaceIgnoreCase.ts @@ -43,6 +43,7 @@ export class ReplaceIgnoreCase extends ExpressionEvaluator { if (!error) { result = InternalFunctionUtils.parseStringOrUndefined(args[0]).replace( + // eslint-disable-next-line security/detect-non-literal-regexp new RegExp(InternalFunctionUtils.parseStringOrUndefined(args[1]), 'gi'), InternalFunctionUtils.parseStringOrUndefined(args[2]) ); diff --git a/libraries/adaptive-expressions/src/builtinFunctions/sqrt.ts b/libraries/adaptive-expressions/src/builtinFunctions/sqrt.ts index 74d8e5b20b..14b09cd479 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/sqrt.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/sqrt.ts @@ -26,21 +26,17 @@ export class Sqrt extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - let error: string; - let value: any; - const originalNumber = Number(args[0]); - if (originalNumber < 0) { - error = 'Do not support square root extraction of negative numbers.'; - } else { - value = Math.sqrt(originalNumber); - } + return FunctionUtils.applyWithError((args: any[]): any => { + let error: string; + let value: any; + const originalNumber = Number(args[0]); + if (originalNumber < 0) { + error = 'Do not support square root extraction of negative numbers.'; + } else { + value = Math.sqrt(originalNumber); + } - return {value, error} - }, - FunctionUtils.verifyNumber - ); + return { value, error }; + }, FunctionUtils.verifyNumber); } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/stringOrValue.ts b/libraries/adaptive-expressions/src/builtinFunctions/stringOrValue.ts index 8a1b2a60a8..0804f533a9 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/stringOrValue.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/stringOrValue.ts @@ -24,7 +24,12 @@ export class StringOrValue extends ExpressionEvaluator { * Initializes a new instance of the [StringOrValue](xref:adaptive-expressions.StringOrValue) class. */ public constructor() { - super(ExpressionType.StringOrValue, StringOrValue.evaluator, ReturnType.Object, FunctionUtils.validateUnaryString); + super( + ExpressionType.StringOrValue, + StringOrValue.evaluator, + ReturnType.Object, + FunctionUtils.validateUnaryString + ); } /** @@ -47,11 +52,13 @@ export class StringOrValue extends ExpressionEvaluator { // If the Expression follows this format: // concat('', childExpression) // return the childExpression result directly. - if (firstChild instanceof Constant - && firstChild.value.toString() === '' - && !(secondChild instanceof Constant)) { - return secondChild.tryEvaluate(state, options); - } + if ( + firstChild instanceof Constant && + firstChild.value.toString() === '' && + !(secondChild instanceof Constant) + ) { + return secondChild.tryEvaluate(state, options); + } } return expr.tryEvaluate(state, options); diff --git a/libraries/adaptive-expressions/src/builtinFunctions/stringTransformEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/stringTransformEvaluator.ts index 884f40d34e..e644b523fe 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/stringTransformEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/stringTransformEvaluator.ts @@ -7,7 +7,7 @@ */ import { Expression } from '..'; -import { ExpressionEvaluator, ValueWithError } from '../expressionEvaluator'; +import { ExpressionEvaluator } from '../expressionEvaluator'; import { FunctionUtils } from '../functionUtils'; import { Options } from '../options'; import { ReturnType } from '../returnType'; @@ -18,8 +18,10 @@ import { ReturnType } from '../returnType'; export class StringTransformEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [StringTransformEvaluator](xref:adaptive-expressions.StringTransformEvaluator) class. + * * @param type Name of the built-in function. * @param func The string transformation function, it takes a list of objects and returns an string. + * @param validator The validation function. */ public constructor( type: string, diff --git a/libraries/adaptive-expressions/src/builtinFunctions/subtractFromTime.ts b/libraries/adaptive-expressions/src/builtinFunctions/subtractFromTime.ts index a2897ce743..f3e11b665b 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/subtractFromTime.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/subtractFromTime.ts @@ -6,7 +6,7 @@ * Licensed under the MIT License. */ -import dayjs, { OpUnitType } from 'dayjs'; +import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); import { Expression } from '../expression'; @@ -54,7 +54,6 @@ export class SubtractFromTime extends ExpressionEvaluator { error = InternalFunctionUtils.verifyISOTimestamp(args[0]); if (!error) { value = dayjs(args[0]).locale(locale).utc().subtract(dur, tsStr).format(format); - } } } else { diff --git a/libraries/adaptive-expressions/src/builtinFunctions/timeTransformEvaluator.ts b/libraries/adaptive-expressions/src/builtinFunctions/timeTransformEvaluator.ts index 1cc1a6aa52..89a6e2fa8a 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/timeTransformEvaluator.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/timeTransformEvaluator.ts @@ -23,6 +23,7 @@ import { ReturnType } from '../returnType'; export class TimeTransformEvaluator extends ExpressionEvaluator { /** * Initializes a new instance of the [TimeTransformEvaluator](xref:adaptive-expressions.TimeTransformEvaluator) class. + * * @param type Name of the built-in function. * @param func The evaluation function, it takes a timestamp and the number of transformation, and returns a `Date`. */ diff --git a/libraries/adaptive-expressions/src/builtinFunctions/toUpper.ts b/libraries/adaptive-expressions/src/builtinFunctions/toUpper.ts index be2ee7ffcc..828fe725c9 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/toUpper.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/toUpper.ts @@ -6,12 +6,10 @@ * Licensed under the MIT License. */ -import { Expression } from '../expression'; import { ExpressionType } from '../expressionType'; import { FunctionUtils } from '../functionUtils'; import { InternalFunctionUtils } from '../functionUtils.internal'; import { Options } from '../options'; -import { ReturnType } from '../returnType'; import { StringTransformEvaluator } from './stringTransformEvaluator'; /** diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriHost.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriHost.ts index 067e77269f..47f2a14d0e 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriHost.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriHost.ts @@ -54,7 +54,7 @@ export class UriHost extends ExpressionEvaluator { if (!error) { try { result = parsed.hostname; - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriPath.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriPath.ts index 576e7de186..8ced7ea0dc 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriPath.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriPath.ts @@ -54,7 +54,7 @@ export class UriPath extends ExpressionEvaluator { try { const uriObj: URL = new URL(uri); result = uriObj.pathname; - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriPathAndQuery.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriPathAndQuery.ts index 6949acee9f..492c103151 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriPathAndQuery.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriPathAndQuery.ts @@ -59,7 +59,7 @@ export class UriPathAndQuery extends ExpressionEvaluator { if (!error) { try { result = parsed.pathname + parsed.search; - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriPort.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriPort.ts index c32d29916a..2c40885aba 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriPort.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriPort.ts @@ -54,7 +54,7 @@ export class UriPort extends ExpressionEvaluator { if (!error) { try { result = parseInt(parsed.port); - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriQuery.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriQuery.ts index 2ad462f604..745d86b2c2 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriQuery.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriQuery.ts @@ -54,7 +54,7 @@ export class UriQuery extends ExpressionEvaluator { if (!error) { try { result = parsed.search; - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/uriScheme.ts b/libraries/adaptive-expressions/src/builtinFunctions/uriScheme.ts index 52bfc64fa3..8ec737602b 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/uriScheme.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/uriScheme.ts @@ -54,7 +54,7 @@ export class UriScheme extends ExpressionEvaluator { if (!error) { try { result = parsed.protocol.replace(':', ''); - } catch (e) { + } catch { error = 'invalid operation, input uri should be an absolute URI'; } } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/xml.ts b/libraries/adaptive-expressions/src/builtinFunctions/xml.ts index ba3089a3b5..f3ea464edc 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/xml.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/xml.ts @@ -6,7 +6,6 @@ * Licensed under the MIT License. */ -import { Expression } from '../expression'; import { EvaluateExpressionDelegate, ExpressionEvaluator } from '../expressionEvaluator'; import { ExpressionType } from '../expressionType'; import { FunctionUtils } from '../functionUtils'; @@ -24,7 +23,9 @@ export class XML extends ExpressionEvaluator { } private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError((args: unknown[]): { value: unknown; error: string } => XML.platformSpecificXML(args)); + return FunctionUtils.applyWithError((args: unknown[]): { value: unknown; error: string } => + XML.platformSpecificXML(args) + ); } private static platformSpecificXML(args: unknown[]): { value: unknown; error: string } { @@ -42,7 +43,7 @@ export class XML extends ExpressionEvaluator { format: true, }); result = `\n${parser.parse(obj)}`.trim(); - } catch (err) { + } catch { error = `${args[0]} is not a valid json`; } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/xpath.ts b/libraries/adaptive-expressions/src/builtinFunctions/xpath.ts index 391660fde8..17b238b0c5 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/xpath.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/xpath.ts @@ -38,7 +38,7 @@ export class XPath extends ExpressionEvaluator { try { const parser = new DOMParser(); xmlDoc = parser.parseFromString(args[0] as string, 'text/xml'); - } catch (err) { + } catch { error = error = `${args[0]} is not valid xml input`; } @@ -71,7 +71,7 @@ export class XPath extends ExpressionEvaluator { let doc: XMLDocument; try { doc = new DOMParser().parseFromString(args[0], 'text/xml'); - } catch (err) { + } catch { error = `${args[0]} is not valid xml input`; } diff --git a/libraries/adaptive-expressions/src/builtinFunctions/year.ts b/libraries/adaptive-expressions/src/builtinFunctions/year.ts index b83a7dad5b..1ecfae8eed 100644 --- a/libraries/adaptive-expressions/src/builtinFunctions/year.ts +++ b/libraries/adaptive-expressions/src/builtinFunctions/year.ts @@ -27,17 +27,13 @@ export class Year extends ExpressionEvaluator { * @private */ private static evaluator(): EvaluateExpressionDelegate { - return FunctionUtils.applyWithError( - (args: any[]): any => - { - const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); - if (!error) { - return {value: new Date(args[0]).getUTCFullYear(), error} - } + return FunctionUtils.applyWithError((args: any[]): any => { + const error = InternalFunctionUtils.verifyISOTimestamp(args[0]); + if (!error) { + return { value: new Date(args[0]).getUTCFullYear(), error }; + } - return {value: undefined, error} - }, - FunctionUtils.verifyString - ); + return { value: undefined, error }; + }, FunctionUtils.verifyString); } } diff --git a/libraries/adaptive-expressions/src/triggerTrees/clause.ts b/libraries/adaptive-expressions/src/triggerTrees/clause.ts index c5d35af7fd..9f0c35468d 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/clause.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/clause.ts @@ -20,6 +20,7 @@ export class Clause extends Expression { /** * Initializes a new instance of the `Clause` class. + * * @param clauseOrExpression A clause, expression or an array of expressions to initialize a `Clause`. */ public constructor(clauseOrExpression?: Clause | Expression | Expression[]) { @@ -53,8 +54,10 @@ export class Clause extends Expression { /** * Gets a string that represents the current clause. + * * @param builder An array of string to build the string of clause. * @param indent An integer represents the number of spaces at the start of a line. + * @returns A string that represents the current clause. */ public toString(builder: string[] = [], indent = 0): string { builder.push(' '.repeat(indent)); @@ -88,6 +91,7 @@ export class Clause extends Expression { /** * Compares the current `Clause` with another `Clause`. + * * @param other The other `Clause` to compare. * @param comparers A comparer, which is a dictionary of `PredicateComparer` with string keys. * @returns A `RelationshipType` value between two `Clause` instances. @@ -172,6 +176,7 @@ export class Clause extends Expression { /** * Determines whether the current `Clause` matches with another `Clause`. + * * @param clause The other `Clause` instance to compare with. * @param memory The scope for looking up variables. * @returns A boolean value indicating whether the two clauses are matches. diff --git a/libraries/adaptive-expressions/src/triggerTrees/node.ts b/libraries/adaptive-expressions/src/triggerTrees/node.ts index b3467cc2ec..4efc052d85 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/node.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/node.ts @@ -30,6 +30,7 @@ export class Node { /** * Intializes a new instance of the `Node` class. + * * @param clause The logical conjunction this node represents. * @param tree The trigger tree this node is found in. * @param trigger The trigger to initialize this node. @@ -45,6 +46,8 @@ export class Node { /** * Gets all of the most specific triggers that contains the `Clause` in this node. + * + * @returns All of the most specific triggers that contains the `Clause` in this node. */ public get triggers(): Trigger[] { return this._triggers; @@ -52,6 +55,8 @@ export class Node { /** * Gets all triggers that contain the `Clause` in this node. + * + * @returns All triggers that contain the `Clause` in this node. */ public get allTriggers(): Trigger[] { return this._allTriggers; @@ -59,6 +64,8 @@ export class Node { /** * Gets specialized children of this node. + * + * @returns Specialized children of this node. */ public get specializations(): Node[] { return this._specializations; @@ -76,8 +83,10 @@ export class Node { /** * Gets a string that represents the current node. + * * @param builder An array of string to build the string of node. * @param indent An integer representing the number of spaces at the start of a line. + * @returns A string that represents the current node. */ public toString(builder: string[] = [], indent = 0): string { return this.clause.toString(builder, indent); @@ -85,6 +94,7 @@ export class Node { /** * Identify the relationship between two nodes. + * * @param other Node to compare against. * @returns Relationship between this node an the other. */ @@ -94,6 +104,7 @@ export class Node { /** * Gets the most specific matches below this node. + * * @param state Frame to evaluate against. * @returns List of the most specific matches found. */ @@ -105,6 +116,7 @@ export class Node { /** * Adds a child node. + * * @param triggerNode The node to be added. * @returns Whether adding node operation is successful. */ @@ -114,6 +126,7 @@ export class Node { /** * Removes a trigger from node. + * * @param trigger The trigger to be removed. * @returns Whether removing trigger operation is successful. */ @@ -130,7 +143,7 @@ export class Node { const trigger = triggerNode.triggers[0]; const relationship = this.relationship(triggerNode); switch (relationship) { - case RelationshipType.equal: + case RelationshipType.equal: { // Ensure action is not already there const found = this._allTriggers.find( @@ -160,6 +173,7 @@ export class Node { op = Operation.added; } break; + } case RelationshipType.incomparable: for (const child of this._specializations) { child._addNode(triggerNode, ops); @@ -169,7 +183,7 @@ export class Node { triggerNode._addSpecialization(this); op = Operation.inserted; break; - case RelationshipType.generalizes: + case RelationshipType.generalizes: { let foundOne = false; let removals: Node[]; for (let i = 0; i < this._specializations.length; i++) { @@ -204,6 +218,7 @@ export class Node { op = Operation.added; } break; + } } // Prevent visiting this node again diff --git a/libraries/adaptive-expressions/src/triggerTrees/optimizer.ts b/libraries/adaptive-expressions/src/triggerTrees/optimizer.ts index 87e9147b69..810db4f186 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/optimizer.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/optimizer.ts @@ -16,6 +16,7 @@ import { RelationshipType } from './relationshipType'; export interface Optimizer { /** * Optionally rewrite a clause. + * * @param clause Original clause. * @returns Optimized clause. */ @@ -33,6 +34,7 @@ export interface PredicateComparer { /** * Identify the relationship between two predicates. + * * @param predicate First predicate. * @param other Second predicate. * @returns Relationship between predicates. diff --git a/libraries/adaptive-expressions/src/triggerTrees/quantifier.ts b/libraries/adaptive-expressions/src/triggerTrees/quantifier.ts index 754966fe17..57356848f1 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/quantifier.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/quantifier.ts @@ -27,6 +27,7 @@ export enum QuantifierType { export class Quantifier { /** * Initializes a new instance of the `Quantifier` class. + * * @param variable Name of variable to replace. * @param type Type of quantifier. * @param bindings Possible bindings for variable. @@ -34,7 +35,7 @@ export class Quantifier { public constructor(readonly variable: string, readonly type: QuantifierType, readonly bindings: string[]) {} /** - * Returns a string that represents the quantifier. + * @returns A string that represents the quantifier. */ public toString(): string { return `${this.type} ${this.variable} ${this.bindings.length}`; diff --git a/libraries/adaptive-expressions/src/triggerTrees/trigger.ts b/libraries/adaptive-expressions/src/triggerTrees/trigger.ts index 7ecd50f95a..b165a56323 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/trigger.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/trigger.ts @@ -18,13 +18,17 @@ import { TriggerTree } from './triggerTree'; /** * Rewrite the expression by pushing not down to the leaves. + * + * @param expression Expression to rewrite. + * @param inNot . + * @returns The rewritten expression. */ const pushDownNot = (expression: Expression, inNot = false): Expression => { let newExpr = expression; const negation = expression.evaluator.negation; switch (expression.type) { case ExpressionType.And: - case ExpressionType.Or: + case ExpressionType.Or: { const children = expression.children.map((child) => pushDownNot(child, inNot)); if (children.length === 1) { newExpr = children[0]; @@ -42,6 +46,7 @@ const pushDownNot = (expression: Expression, inNot = false): Expression => { ); } break; + } case ExpressionType.Not: newExpr = pushDownNot(expression.children[0], !inNot); break; @@ -80,6 +85,7 @@ export class Trigger { /** * Intializes a new instance of the `Trigger` class. + * * @param tree Trigger tree that contains this trigger. * @param expression Expression for when the trigger action is possible. * @param action Action to take when a trigger matches. @@ -117,6 +123,8 @@ export class Trigger { /** * Gets list of expressions converted into Disjunctive Normal Form where ! is pushed to the leaves and * there is an implicit || between clauses and && within a clause. + * + * @returns The list of clauses. */ public get clauses(): Clause[] { return this._clauses; @@ -124,6 +132,7 @@ export class Trigger { /** * Determines the relationship between current instance and another `Trigger` instance. + * * @param other The other Trigger instance. * @param comparers The comparer dictionary. * @returns A `RelationshipType` value. @@ -155,6 +164,7 @@ export class Trigger { /** * Determines whether there is a member in the current `Clause` that matches the nodeClause parameter. + * * @param nodeClause The other Clause instance to match. * @param state The scope for looking up variables. * @returns A boolean value inidicating whether there is a member matches. @@ -165,8 +175,10 @@ export class Trigger { /** * Gets a string that represents the current trigger. + * * @param builder An array of string to build the string of trigger. * @param indent An integer represents the number of spaces at the start of a line. + * @returns A string that represents the current trigger. */ public toString(builder: string[] = [], indent = 0): string { builder.push(' '.repeat(indent)); @@ -229,7 +241,7 @@ export class Trigger { private _generateClauses(expression: Expression): Clause[] { switch (expression.type) { - case ExpressionType.And: + case ExpressionType.And: { // Need to combine every combination of clauses let soFar: Clause[] = []; let first = true; @@ -259,13 +271,15 @@ export class Trigger { } } return soFar; - case ExpressionType.Or: + } + case ExpressionType.Or: { const clauses: Clause[] = []; for (let i = 0; i < expression.children.length; i++) { const child = expression.children[i]; clauses.push(...this._generateClauses(child)); } return clauses; + } case ExpressionType.Optional: return [new Clause(), ...this._generateClauses(expression.children[0])]; default: diff --git a/libraries/adaptive-expressions/src/triggerTrees/triggerTree.ts b/libraries/adaptive-expressions/src/triggerTrees/triggerTree.ts index 6491cc611e..b15bd7d87e 100644 --- a/libraries/adaptive-expressions/src/triggerTrees/triggerTree.ts +++ b/libraries/adaptive-expressions/src/triggerTrees/triggerTree.ts @@ -47,7 +47,7 @@ export class TriggerTree { public totalTriggers = 0; /** - * Returns a string the represents the current object. + * @returns A string the represents the current object. */ public toString(): string { return `TriggerTree with ${this.totalTriggers} triggers`; @@ -55,6 +55,7 @@ export class TriggerTree { /** * Add a trigger expression to the tree. + * * @param stringOrExpression Trigger to add. * @param action Action when triggered. * @param quantifiers Quantifiers to use when expanding expressions. @@ -83,6 +84,7 @@ export class TriggerTree { /** * Remove trigger from tree. + * * @param trigger Trigger to remove. * @returns True if removed trigger. */ @@ -96,6 +98,7 @@ export class TriggerTree { /** * Generates a string describing the tree. + * * @param indent Current indent level. * @returns String describing the tree. */ @@ -107,6 +110,7 @@ export class TriggerTree { /** * Return the possible matches given the current state. + * * @param state State to evaluate against. * @returns List of possible matches. */ @@ -116,6 +120,7 @@ export class TriggerTree { /** * Verify the tree meets specialization/generalization invariants. + * * @returns Bad node if found. */ public verifyTree(): Node {