From 47787c0b0b846d5f4a057661efdd05d8786032f1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 6 Apr 2020 23:32:01 +0530 Subject: make linter less grumpy --- src/util/amounts.ts | 12 +++++------- src/util/asyncMemo.ts | 8 ++++---- src/util/codec.ts | 6 +----- src/util/http.ts | 8 ++++---- src/util/logging.ts | 10 +++++----- src/util/query.ts | 10 +++++----- src/util/time.ts | 6 +++--- 7 files changed, 27 insertions(+), 33 deletions(-) (limited to 'src/util') diff --git a/src/util/amounts.ts b/src/util/amounts.ts index f0a4f1d72..da1c19233 100644 --- a/src/util/amounts.ts +++ b/src/util/amounts.ts @@ -22,10 +22,10 @@ * Imports. */ import { - typecheckedCodec, makeCodecForObject, codecForString, codecForNumber, + Codec, } from "./codec"; /** @@ -66,14 +66,12 @@ export interface AmountJson { readonly currency: string; } -export const codecForAmountJson = () => - typecheckedCodec( +export const codecForAmountJson = (): Codec => makeCodecForObject() .property("currency", codecForString) .property("value", codecForNumber) .property("fraction", codecForNumber) - .build("AmountJson"), - ); + .build("AmountJson"); /** * Result of a possibly overflowing operation. @@ -100,7 +98,7 @@ export function getZero(currency: string): AmountJson { }; } -export function sum(amounts: AmountJson[]) { +export function sum(amounts: AmountJson[]): Result { if (amounts.length <= 0) { throw Error("can't sum zero amounts"); } @@ -287,7 +285,7 @@ export function parseOrThrow(s: string): AmountJson { * Convert a float to a Taler amount. * Loss of precision possible. */ -export function fromFloat(floatVal: number, currency: string) { +export function fromFloat(floatVal: number, currency: string): AmountJson { return { currency, fraction: Math.floor((floatVal - Math.floor(floatVal)) * fractionalBase), diff --git a/src/util/asyncMemo.ts b/src/util/asyncMemo.ts index 84fe6b802..6e88081b6 100644 --- a/src/util/asyncMemo.ts +++ b/src/util/asyncMemo.ts @@ -24,7 +24,7 @@ export class AsyncOpMemoMap { private n = 0; private memoMap: { [k: string]: MemoEntry } = {}; - private cleanUp(key: string, n: number) { + private cleanUp(key: string, n: number): void { const r = this.memoMap[key]; if (r && r.n === n) { delete this.memoMap[key]; @@ -48,7 +48,7 @@ export class AsyncOpMemoMap { this.cleanUp(key, n); }); } - clear() { + clear(): void { this.memoMap = {}; } } @@ -57,7 +57,7 @@ export class AsyncOpMemoSingle { private n = 0; private memoEntry: MemoEntry | undefined; - private cleanUp(n: number) { + private cleanUp(n: number): void { if (this.memoEntry && this.memoEntry.n === n) { this.memoEntry = undefined; } @@ -81,7 +81,7 @@ export class AsyncOpMemoSingle { }; return p; } - clear() { + clear(): void { this.memoEntry = undefined; } } diff --git a/src/util/codec.ts b/src/util/codec.ts index a8f495238..480e1eec7 100644 --- a/src/util/codec.ts +++ b/src/util/codec.ts @@ -346,8 +346,4 @@ export function makeCodecOptional( return innerCodec.decode(x, c); }, }; -} - -export function typecheckedCodec(c: Codec): Codec { - return c; -} +} \ No newline at end of file diff --git a/src/util/http.ts b/src/util/http.ts index 1a5cb85fa..3842347dc 100644 --- a/src/util/http.ts +++ b/src/util/http.ts @@ -116,7 +116,7 @@ export class BrowserHttpLib implements HttpRequestLibrary { ); return; } - const makeJson = async () => { + const makeJson = async (): Promise => { let responseJson; try { responseJson = JSON.parse(myRequest.responseText); @@ -152,15 +152,15 @@ export class BrowserHttpLib implements HttpRequestLibrary { }); } - get(url: string, opt?: HttpRequestOptions) { + get(url: string, opt?: HttpRequestOptions): Promise { return this.req("get", url, undefined, opt); } - postJson(url: string, body: any, opt?: HttpRequestOptions) { + postJson(url: string, body: any, opt?: HttpRequestOptions): Promise { return this.req("post", url, JSON.stringify(body), opt); } - stop() { + stop(): void { // Nothing to do } } diff --git a/src/util/logging.ts b/src/util/logging.ts index 80ba344d5..83e8d2192 100644 --- a/src/util/logging.ts +++ b/src/util/logging.ts @@ -24,7 +24,7 @@ function writeNodeLog( tag: string, level: string, args: any[], -) { +): void { process.stderr.write(`${new Date().toISOString()} ${tag} ${level} `); process.stderr.write(message); if (args.length != 0) { @@ -41,7 +41,7 @@ function writeNodeLog( export class Logger { constructor(private tag: string) {} - info(message: string, ...args: any[]) { + info(message: string, ...args: any[]): void { if (isNode()) { writeNodeLog(message, this.tag, "INFO", args); } else { @@ -52,7 +52,7 @@ export class Logger { } } - warn(message: string, ...args: any[]) { + warn(message: string, ...args: any[]): void { if (isNode()) { writeNodeLog(message, this.tag, "WARN", args); } else { @@ -63,7 +63,7 @@ export class Logger { } } - error(message: string, ...args: any[]) { + error(message: string, ...args: any[]): void { if (isNode()) { writeNodeLog(message, this.tag, "ERROR", args); } else { @@ -74,7 +74,7 @@ export class Logger { } } - trace(message: any, ...args: any[]) { + trace(message: any, ...args: any[]): void { if (isNode()) { writeNodeLog(message, this.tag, "TRACE", args); } else { diff --git a/src/util/query.ts b/src/util/query.ts index 44f668658..d11b79a96 100644 --- a/src/util/query.ts +++ b/src/util/query.ts @@ -25,6 +25,11 @@ */ import { openPromise } from "./promiseUtils"; +/** + * Exception that should be thrown by client code to abort a transaction. + */ +export const TransactionAbort = Symbol("transaction_abort"); + /** * Definition of an object store. */ @@ -430,11 +435,6 @@ export function openDatabase( }); } -/** - * Exception that should be thrown by client code to abort a transaction. - */ -export const TransactionAbort = Symbol("transaction_abort"); - export class Database { constructor(private db: IDBDatabase) {} diff --git a/src/util/time.ts b/src/util/time.ts index 05188b6d2..ea4f8ca8d 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -36,7 +36,7 @@ export interface Duration { let timeshift = 0; -export function setDangerousTimetravel(dt: number) { +export function setDangerousTimetravel(dt: number): void { timeshift = dt; } @@ -121,7 +121,7 @@ export function timestampSubtractDuraction( return { t_ms: Math.max(0, t1.t_ms - d.d_ms) }; } -export function stringifyTimestamp(t: Timestamp) { +export function stringifyTimestamp(t: Timestamp): string { if (t.t_ms === "never") { return "never"; } @@ -142,7 +142,7 @@ export function timestampIsBetween( t: Timestamp, start: Timestamp, end: Timestamp, -) { +): boolean { if (timestampCmp(t, start) < 0) { return false; } -- cgit v1.2.3