Skip to content

Commit

Permalink
Merge pull request #25 from shumbo/fix-eslint
Browse files Browse the repository at this point in the history
fix eslint config and existing errors
  • Loading branch information
shumbo authored Jul 24, 2023
2 parents 926ac89 + c6632f5 commit 9c4407b
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env node */
module.exports = {
ignorePatterns: ["src", "packages/*/dist"],
ignorePatterns: ["packages/*/dist", "coverage"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pnpm-lock.yaml

packages/*/dist
packages/*/build
coverage
20 changes: 10 additions & 10 deletions packages/backend-express/src/backend-express.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-constant-condition */

import { Choreography, Located } from "@choreography-ts/core";
import { ExpressBackend } from "./backend-express";

Expand All @@ -14,7 +16,7 @@ describe("HTTP Backend", () => {
test("global arguments", async () => {
const p = "GLOBAL ARGUMENT";
const f = (q: string) => {
const c: Choreography<Locations, [], []> = async ({}) => {
const c: Choreography<Locations, [], []> = async () => {
expect(q).toBe(p);
return [];
};
Expand All @@ -34,8 +36,8 @@ describe("HTTP Backend", () => {
return [];
};
if (false) {
// @ts-expect-error
await backend.epp(c, "alice", null)(1); // wrong type
// @ts-expect-error - alice must provide a string, not a number
await backend.epp(c, "alice", null)(1);
}
await Promise.all([
backend.epp(c, "alice")([p]),
Expand Down Expand Up @@ -89,8 +91,8 @@ describe("HTTP Backend", () => {
});
await locally("carol", (unwrap) => {
if (false) {
// @ts-expect-error
unwrap(msgAtSelectedTwo); // cannot unwrap at carol
// @ts-expect-error - cannot wrap at carol
unwrap(msgAtSelectedTwo);
}
});
return [];
Expand Down Expand Up @@ -136,9 +138,8 @@ describe("HTTP Backend", () => {
await colocally(
["carol"],
async ({ peel }) => {
// carol cannot peel the colocated value `msgAtSelectedTwo`
if (false) {
// @ts-expect-error
// @ts-expect-error - carol cannot peel the colocated value `msgAtSelectedTwo`
peel(msgAtSelectedTwo);
}
return [];
Expand All @@ -148,9 +149,8 @@ describe("HTTP Backend", () => {
await colocally(
["bob", "carol"],
async ({ peel }) => {
// bob can read, but because carol will also attempt to read, this is a type error
if (false) {
// @ts-expect-error
// @ts-expect-error - bob can read, but because carol will also attempt to read, this is a type error
expect(peel(msgAtSelectedTwo));
}
return [];
Expand Down Expand Up @@ -191,7 +191,7 @@ describe("HTTP Backend", () => {
await colocally(
["alice", "bob"],
async () => {
const msgAtEveryone = await broadcast("carol", msgAtCarol);
const _msgAtEveryone = await broadcast("carol", msgAtCarol);
return [];
},
[]
Expand Down
2 changes: 2 additions & 0 deletions packages/backend-express/src/backend-express.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import fetch from "@adobe/node-fetch-retry";
import express from "express";
import { Server } from "http";
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/backend-generic.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import {
Backend,
Broadcast,
Expand Down Expand Up @@ -93,7 +95,7 @@ export abstract class GenericBackend<L extends Location, T>
loc: L2,
callback: (unwrap: Unwrap<L2>) => T | Promise<T>
) => {
// @ts-ignore
// @ts-ignore - no easy way to type this
if (loc !== location) {
return undefined as any;
}
Expand Down Expand Up @@ -195,7 +197,6 @@ export abstract class GenericBackend<L extends Location, T>
value: Located<T, L1>
) => {
t.comm();
const locations: (LL | L1)[] = [sender, ...receivers];
// @ts-ignore
if (location === sender) {
// if sender, send value to all receivers
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/backend-local.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-constant-condition */

import { Choreography, Located } from ".";
import { LocalBackend } from "./backend-local.js";

Expand All @@ -14,7 +16,7 @@ describe("Local Backend", () => {
test("global arguments", async () => {
const p = "GLOBAL ARGUMENT";
const f = (q: string) => {
const c: Choreography<Locations, [], []> = async ({}) => {
const c: Choreography<Locations, [], []> = async () => {
expect(q).toBe(p);
return [];
};
Expand All @@ -34,8 +36,8 @@ describe("Local Backend", () => {
return [];
};
if (false) {
// @ts-expect-error
await backend.epp(c, "alice", null)(1); // wrong type
// @ts-expect-error - alice must provide a string, not a number
await backend.epp(c, "alice", null)(1);
}
await Promise.all([
backend.epp(c, "alice")([p]),
Expand Down Expand Up @@ -90,8 +92,8 @@ describe("Local Backend", () => {
});
await locally("carol", (unwrap) => {
if (false) {
// @ts-expect-error
unwrap(msgAtSelectedTwo); // cannot unwrap at carol
// @ts-expect-error - cannot unwrap at carol
unwrap(msgAtSelectedTwo);
}
});
return [];
Expand Down Expand Up @@ -137,9 +139,8 @@ describe("Local Backend", () => {
await colocally(
["carol"],
async ({ peel }) => {
// carol cannot peel the colocated value `msgAtSelectedTwo`
if (false) {
// @ts-expect-error
// @ts-expect-error - carol cannot peel the colocated value `msgAtSelectedTwo`
peel(msgAtSelectedTwo);
}
return [];
Expand All @@ -149,9 +150,8 @@ describe("Local Backend", () => {
await colocally(
["bob", "carol"],
async ({ peel }) => {
// bob can read, but because carol will also attempt to read, this is a type error
if (false) {
// @ts-expect-error
// @ts-expect-error - bob can read, but because carol will also attempt to read, this is a type error
expect(peel(msgAtSelectedTwo));
}
return [];
Expand Down Expand Up @@ -192,7 +192,7 @@ describe("Local Backend", () => {
await colocally(
["alice", "bob"],
async () => {
const msgAtEveryone = await broadcast("carol", msgAtCarol);
const _msgAtEveryone = await broadcast("carol", msgAtCarol);
return [];
},
[]
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/lib/default-dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class DefaultDict<K, V> extends Map<K, V> {
if (!this.has(key)) {
this.set(key, this.defaultFactory());
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return super.get(key)!;
}
}
2 changes: 2 additions & 0 deletions packages/core/src/lib/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ export class Queue<T = any> {
private waiting: ((v: T) => void)[] = [];
public push(value: T): void {
if (this.waiting.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.waiting.shift()!(value);
} else {
this.queue.push(value);
}
}
public async pop(): Promise<T> {
if (this.queue.length > 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.queue.shift()!;
} else {
return new Promise((resolve) => {
Expand Down
1 change: 1 addition & 0 deletions packages/examples/src/bookseller/bookseller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const bookseller: Choreography<
// if the buyer decides to buy the book, seller looks up the delivery date
const deliveryDateAtSeller = await locally(
"seller",
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(unwrap) => deliveryDateTable.get(unwrap(titleAtSeller))!
);
// send the delivery date back to the buyer
Expand Down
1 change: 1 addition & 0 deletions packages/examples/src/bookseller2/bookseller2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const bookseller: (
if (sharedDecision) {
const deliveryDateAtSeller = await locally(
"seller",
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
(unwrap) => deliveryDateTable.get(unwrap(titleAtSeller))!
);
const deliveryDateAtBuyer = await comm(
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/concurrent-call/concurrent-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const concurrentCall: Choreography<
await locally("bob", (unwrap) => {
console.log(unwrap(msgAtBob));
});
return [oneAtBob];
return [oneAtBob] as [Located<number, "bob">];
}, []);
const p2 = call(async ({ locally, comm }) => {
// [3]
Expand All @@ -36,10 +36,10 @@ export const concurrentCall: Choreography<
await locally("bob", (unwrap) => {
console.log(unwrap(msgAtBob));
});
return [twoAtBob];
return [twoAtBob] as [Located<number, "bob">];
}, []);
const [[oneAtBob], [twoAtBob]] = await Promise.all([p1, p2]);
return [oneAtBob!, twoAtBob!];
return [oneAtBob, twoAtBob];
};

async function main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Diffie Hellman", () => {
bob: ["localhost", 3001],
});
const keyExchange = diffieHellman("alice", "bob");
const [[s1, a], [b, s2]] = await Promise.all([
const [[s1, _a], [_b, s2]] = await Promise.all([
backend.epp(keyExchange, "alice")([false]),
backend.epp(keyExchange, "bob")([undefined]),
]);
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/src/diffie-hellman/diffie-hellman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ExpressBackend } from "@choreography-ts/backend-express";

// Return all divisors of `x`
const divisors = (x: number): number[] => {
let divs: number[] = [1, x];
const divs = [1, x];
for (let y = 2; y <= x / 2; y++) {
if (x % y == 0) divs.push(y);
}
Expand All @@ -19,7 +19,7 @@ const divisors = (x: number): number[] => {

// Checks if input number is prime
const isPrime = (x: number): boolean => {
let divs: number[] = divisors(x);
const divs = divisors(x);
if (divs.length == 2) return true;
return false;
};
Expand Down Expand Up @@ -58,7 +58,7 @@ export const diffieHellman = <A extends Location, B extends Location>(
await locally(a, async (unwrap) => {
console.log("Press enter to begin key exchange...");
// Check for key input on stdin in node: https://stackoverflow.com/a/72906729
let wait = unwrap(arg);
const wait = unwrap(arg);
return new Promise<void>((resolve) => {
if (wait) {
// If waiting is desired
Expand Down
3 changes: 3 additions & 0 deletions packages/examples/src/hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ const helloWorld: Choreography<Locations> = async ({ locally, comm }) => {
};

async function main(location: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!locations.includes(location as any)) {
throw new Error(`Invalid location: ${location}`);
}
const backend = new ExpressBackend<Locations>({
alice: ["localhost", 3000],
bob: ["localhost", 3001],
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await backend.epp(helloWorld, location as any)([]);
}

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
main(process.argv[2]!);
6 changes: 3 additions & 3 deletions packages/examples/src/kvs/kvs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ReplicationStrategy<S extends Located<State, ServerLocations>[]> =
[Located<Response, "primary">]
>;

const nullReplicationStrategy: ReplicationStrategy<
export const nullReplicationStrategy: ReplicationStrategy<
[Located<State, "primary">]
> = async ({ locally }, [requestAtPrimary, primaryState]) => {
const responseAtPrimary = await locally("primary", (unwrap) =>
Expand All @@ -51,7 +51,7 @@ const nullReplicationStrategy: ReplicationStrategy<
return [responseAtPrimary];
};

const primaryBackupReplicationStrategy: ReplicationStrategy<
export const primaryBackupReplicationStrategy: ReplicationStrategy<
[Located<State, "primary">, Located<State, "backup">]
> = async (
{ multicast, locally, colocally },
Expand Down Expand Up @@ -89,7 +89,7 @@ const primaryBackupReplicationStrategy: ReplicationStrategy<
return [responseAtPrimary];
};

function kvs<S extends Located<State, ServerLocations>[]>(
export function kvs<S extends Located<State, ServerLocations>[]>(
replicationStrategy: ReplicationStrategy<S>
) {
const kvs_: Choreography<
Expand Down
1 change: 0 additions & 1 deletion packages/examples/src/majority-vote/majority-vote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Choreography, Located } from "@choreography-ts/core";
import { ExpressBackend } from "@choreography-ts/backend-express";
import process from "process";

export type L = "judge" | "voter1" | "voter2" | "voter3";

Expand Down
2 changes: 2 additions & 0 deletions packages/examples/src/mergesort/mergesort.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */

import { Choreography, Located } from "@choreography-ts/core";
import { ExpressBackend } from "@choreography-ts/backend-express";

Expand Down

0 comments on commit 9c4407b

Please sign in to comment.