Lint the expressions package
This commit is contained in:
@@ -9,7 +9,7 @@ export function isDescriptionDictionary(x: ExpressionData): x is DescriptionDict
|
||||
|
||||
export class DescriptionDictionary extends Dictionary {
|
||||
private readonly descriptions = new Map<string, string>();
|
||||
public complete: boolean = true;
|
||||
public complete = true;
|
||||
|
||||
constructor(...pairs: DescriptionPair[]) {
|
||||
super();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import {ExpressionData, ExpressionDataInterface, Kind} from "./expressiondata";
|
||||
import {ExpressionDataInterface, Kind} from "./expressiondata";
|
||||
|
||||
export class Null implements ExpressionDataInterface {
|
||||
constructor() {}
|
||||
|
||||
public readonly kind = Kind.Null;
|
||||
|
||||
public primitive = true;
|
||||
|
||||
@@ -8,7 +8,7 @@ export class NumberData implements ExpressionDataInterface {
|
||||
public primitive = true;
|
||||
|
||||
coerceString(): string {
|
||||
if (this.value === -0) {
|
||||
if (Object.is(this.value, -0)) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {StringData} from "./string";
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#replacer
|
||||
*/
|
||||
export function replacer(key: string, value: any): any {
|
||||
export function replacer(_key: string, value: unknown): unknown {
|
||||
if (value instanceof Null) {
|
||||
return null;
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export function replacer(key: string, value: any): any {
|
||||
if (value instanceof Dictionary) {
|
||||
const pairs = value.pairs();
|
||||
|
||||
const r: any = {};
|
||||
const r: Record<string, unknown> = {};
|
||||
for (const p of pairs) {
|
||||
r[p.key] = p.value;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {Array as dArray} from "./array";
|
||||
import {BooleanData} from "./boolean";
|
||||
import {Dictionary} from "./dictionary";
|
||||
import {ExpressionData, Pair} from "./expressiondata";
|
||||
import {ExpressionData} from "./expressiondata";
|
||||
import {Null} from "./null";
|
||||
import {NumberData} from "./number";
|
||||
import {StringData} from "./string";
|
||||
@@ -11,7 +11,7 @@ import {StringData} from "./string";
|
||||
*
|
||||
* See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#reviver
|
||||
*/
|
||||
export function reviver(key: string, val: any): ExpressionData {
|
||||
export function reviver(_key: string, val: unknown): ExpressionData {
|
||||
if (val === null) {
|
||||
return new Null();
|
||||
}
|
||||
@@ -25,25 +25,22 @@ export function reviver(key: string, val: any): ExpressionData {
|
||||
}
|
||||
|
||||
if (typeof val === "boolean") {
|
||||
return new BooleanData(val as boolean);
|
||||
return new BooleanData(val);
|
||||
}
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
return new dArray(...val);
|
||||
return new dArray(...(val as ExpressionData[]));
|
||||
}
|
||||
|
||||
if (typeof val === "object") {
|
||||
return new Dictionary(
|
||||
...Object.keys(val).map(
|
||||
k =>
|
||||
({
|
||||
key: k,
|
||||
value: val[k]
|
||||
} as Pair)
|
||||
)
|
||||
...Object.keys(val).map(k => ({
|
||||
key: k,
|
||||
value: val[k as keyof typeof val]
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
// Pass through value
|
||||
return val;
|
||||
return val as ExpressionData;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Array, BooleanData, ExpressionData, Kind} from "../data";
|
||||
import {BooleanData, ExpressionData, Kind} from "../data";
|
||||
import {equals} from "../result";
|
||||
import {FunctionDefinition} from "./info";
|
||||
|
||||
@@ -19,7 +19,7 @@ export const contains: FunctionDefinition = {
|
||||
return new BooleanData(ls.toLowerCase().includes(rs.toLowerCase()));
|
||||
}
|
||||
} else if (left.kind === Kind.Array) {
|
||||
const la = left as Array;
|
||||
const la = left;
|
||||
if (la.values().length === 0) {
|
||||
return new BooleanData(false);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export const format: FunctionDefinition = {
|
||||
|
||||
while (index < fs.length) {
|
||||
const lbrace = fs.indexOf("{", index);
|
||||
let rbrace = fs.indexOf("}", index);
|
||||
const rbrace = fs.indexOf("}", index);
|
||||
|
||||
// Left brace
|
||||
if (lbrace >= 0 && (rbrace < 0 || rbrace > lbrace)) {
|
||||
@@ -81,7 +81,7 @@ function safeCharAt(string: string, index: number): string {
|
||||
function readArgIndex(string: string, startIndex: number): ArgIndex {
|
||||
// Count the number of digits
|
||||
let length = 0;
|
||||
while (true) {
|
||||
for (;;) {
|
||||
const nextChar = safeCharAt(string, startIndex + length);
|
||||
if (nextChar >= "0" && nextChar <= "9") {
|
||||
length++;
|
||||
@@ -112,9 +112,3 @@ interface ArgIndex {
|
||||
result: number;
|
||||
endIndex: number;
|
||||
}
|
||||
|
||||
interface FormatSpecifiers {
|
||||
success: boolean;
|
||||
result: string;
|
||||
rbrace: number;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export const fromjson: FunctionDefinition = {
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(is, reviver);
|
||||
return JSON.parse(is, reviver) as ExpressionData;
|
||||
} catch (e) {
|
||||
throw new ExpressionEvaluationError("Error parsing JSON when evaluating fromJson", {cause: e});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Array, ExpressionData, Kind, StringData} from "../data";
|
||||
import {ExpressionData, Kind, StringData} from "../data";
|
||||
import {FunctionDefinition} from "./info";
|
||||
|
||||
export const join: FunctionDefinition = {
|
||||
@@ -23,7 +23,7 @@ export const join: FunctionDefinition = {
|
||||
|
||||
// Convert items to strings
|
||||
return new StringData(
|
||||
(args[0] as Array)
|
||||
args[0]
|
||||
.values()
|
||||
.map(item => item.coerceString())
|
||||
.join(separator)
|
||||
|
||||
Reference in New Issue
Block a user