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: [#2745] Fix current eslint warnings - adaptive-expressions library (1/2) #4034

Merged
merged 5 commits into from
Jan 31, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions libraries/adaptive-expressions/src/builtinFunctions/addDays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
18 changes: 7 additions & 11 deletions libraries/adaptive-expressions/src/builtinFunctions/dateFunc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { ExpressionType } from '../expressionType';
import { FunctionUtils } from '../functionUtils';
import { InternalFunctionUtils } from '../functionUtils.internal';
import { ComparisonEvaluator } from './comparisonEvaluator';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class GetTimeOfDay extends ExpressionEvaluator {
} else {
return { value, error };
}

}
} else {
// utc iso format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable security/detect-object-injection */
/**
* @module adaptive-expressions
*/
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Loading