Lint the expressions package

This commit is contained in:
Josh Gross
2023-03-15 15:22:30 -04:00
parent 28a4438faf
commit 9c8c407478
9 changed files with 21 additions and 32 deletions
@@ -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 -3
View File
@@ -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;
+1 -1
View File
@@ -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";
}
+2 -2
View File
@@ -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;
}
+9 -12
View File
@@ -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;
}
+2 -2
View File
@@ -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);
}
+2 -8
View File
@@ -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;
}
+1 -1
View File
@@ -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});
}
+2 -2
View File
@@ -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)