aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-04-06 23:32:01 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-04-06 23:32:01 +0530
commit47787c0b0b846d5f4a057661efdd05d8786032f1 (patch)
tree3a3d58a5ebad8af584de6a6cd882c2019f71dffa /src/util
parentf36bb7a04eabe0330cb166bf9ce5021c92f38dc8 (diff)
downloadwallet-core-47787c0b0b846d5f4a057661efdd05d8786032f1.tar.xz
make linter less grumpy
Diffstat (limited to 'src/util')
-rw-r--r--src/util/amounts.ts12
-rw-r--r--src/util/asyncMemo.ts8
-rw-r--r--src/util/codec.ts6
-rw-r--r--src/util/http.ts8
-rw-r--r--src/util/logging.ts10
-rw-r--r--src/util/query.ts10
-rw-r--r--src/util/time.ts6
7 files changed, 27 insertions, 33 deletions
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<AmountJson>(
+export const codecForAmountJson = (): Codec<AmountJson> =>
makeCodecForObject<AmountJson>()
.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<T> {
private n = 0;
private memoMap: { [k: string]: MemoEntry<T> } = {};
- 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<T> {
this.cleanUp(key, n);
});
}
- clear() {
+ clear(): void {
this.memoMap = {};
}
}
@@ -57,7 +57,7 @@ export class AsyncOpMemoSingle<T> {
private n = 0;
private memoEntry: MemoEntry<T> | 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<T> {
};
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<V>(
return innerCodec.decode(x, c);
},
};
-}
-
-export function typecheckedCodec<T = undefined>(c: Codec<T>): Codec<T> {
- 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<any> => {
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<HttpResponse> {
return this.req("get", url, undefined, opt);
}
- postJson(url: string, body: any, opt?: HttpRequestOptions) {
+ postJson(url: string, body: any, opt?: HttpRequestOptions): Promise<HttpResponse> {
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
@@ -26,6 +26,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.
*/
export class Store<T> {
@@ -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;
}