Skip to content

More eslint issues addressed #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/Adder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MyAdder extends Adder {
}
}

public getProxy(port: IOPort<unknown>) {
public getProxy<T>(port: IOPort<T>) {
return this.writable(port);
}
}
Expand Down
4 changes: 2 additions & 2 deletions __tests__/HierarchicalSingleEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {Logger} from "../src/share/Logger";

class SEContainer extends Reactor {
// Made these public to accommodate the test below.
public o: OutPort<any> = new OutPort<any>(this);
public o: OutPort<string> = new OutPort(this);

public child = new SingleEvent<string>(this, new Parameter("Foo"));

Expand All @@ -24,7 +24,7 @@ class SEContainer extends Reactor {

class LogContainer extends Reactor {
// Made these public to accommodate the test below.
public i: InPort<any> = new InPort<any>(this);
public i: InPort<string> = new InPort(this);

public child: Logger = new Logger(this, "Foo");

Expand Down
2 changes: 1 addition & 1 deletion __tests__/SingleEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {SingleEvent} from "../src/share/SingleEvent";
import {Logger} from "../src/share/Logger";

class SETest extends App {
singleEvent: SingleEvent<any>;
singleEvent: SingleEvent<string>;

logger: Logger;

Expand Down
11 changes: 5 additions & 6 deletions __tests__/dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Priority, Sortable, ReactionGraph} from "../src/core/internal";
import {Priority, Sortable, ReactionGraph, dontIndent} from "../src/core/internal";
import {
Reactor,
App,
InPort,
SortablePrecedenceGraph,
PrioritySet,
Log,
StringUtil
} from "../src/core/internal";

// Log.setGlobalLevel(Log.levels.DEBUG);
Expand Down Expand Up @@ -94,7 +93,7 @@ describe("Manually constructed precedence graphs", () => {
expect(graph.size()[0]).toEqual(6); // V
expect(graph.size()[1]).toEqual(7); // E
expect(graph.toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["app.R[R3]"]
1["app.R[R5]"]
2["app.R[R4]"]
Expand Down Expand Up @@ -126,7 +125,7 @@ describe("Manually constructed precedence graphs", () => {
expect(graph.size()[0]).toEqual(6); // V
expect(graph.size()[1]).toEqual(6); // E
expect(graph.toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["app.R[R3]"]
1["app.R[R5]"]
2["app.R[R4]"]
Expand All @@ -148,7 +147,7 @@ describe("Manually constructed precedence graphs", () => {
expect(graph.size()[1]).toEqual(3); // E
Log.global.debug(graph.toString());
expect(graph.toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["app.R[R3]"]
1["app.R[R5]"]
2["app.R[R4]"]
Expand All @@ -168,7 +167,7 @@ describe("Manually constructed precedence graphs", () => {
expect(graph.size()[1]).toEqual(4); // E
Log.global.debug(graph.toString());
expect(graph.toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["app.R[R3]"]
1["app.R[R5]"]
2["app.R[R4]"]
Expand Down
2 changes: 1 addition & 1 deletion __tests__/graph.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PrioritySet, PrioritySetElement} from "../src/core/queue";
import type {Sortable} from "../src/core/types";
import {PrecedenceGraph, SortablePrecedenceGraph} from "../src/core/graph";
import {StringUtil} from "../src/core/strings";

/**
* The tests below test the functionality of the hasCycle() utility function on various
* dependency graphs, in combination with various graph manipulation utilities
Expand Down
10 changes: 5 additions & 5 deletions __tests__/simple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Reactor, App, InPort, OutPort, StringUtil} from "../src/core/internal";
import {Reactor, App, InPort, OutPort, dontIndent} from "../src/core/internal";

class MyActor extends Reactor {
a = new InPort<{t: number}>(this);
Expand All @@ -18,7 +18,7 @@ class MyActor2 extends Reactor {

describe("Test names for contained reactors", () => {
class myApp extends App {
port: InPort<any> = new InPort<any>(this);
port: InPort<unknown> = new InPort(this);

x = new MyActor(this);

Expand Down Expand Up @@ -68,7 +68,7 @@ describe("Test names for contained reactors", () => {

it("graph before connect", () => {
expect(this._getPrecedenceGraph().toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["myApp.x[M0]"]
1["myApp[M0]"]
2["myApp.y[M0]"]
Expand All @@ -91,7 +91,7 @@ describe("Test names for contained reactors", () => {

it("graph after connect and before disconnect", () => {
expect(this._getPrecedenceGraph().toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["myApp.x.a"]
1["myApp.y.b"]
2["myApp.x[M0]"]
Expand All @@ -106,7 +106,7 @@ describe("Test names for contained reactors", () => {
it("graph after disconnect", () => {
this._disconnect(this.y.b, this.x.a);
expect(this._getPrecedenceGraph().toString()).toBe(
StringUtil.dontIndent`graph
dontIndent`graph
0["myApp.x.a"]
1["myApp.y.b"]
2["myApp.x[M0]"]
Expand Down
3 changes: 2 additions & 1 deletion lingua-franca-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
master
ts-never

15 changes: 5 additions & 10 deletions src/core/bank.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
IOPort,
MultiPort,
ParmList,
Port,
Reactor,
WritableMultiPort,
Expand All @@ -12,15 +13,9 @@ import type {
* are of type `ReactorArgs`.
*/
export type ReactorClass<T extends Reactor, S> = new (
...args: ReactorArgs<S>
...parameters: ParmList<S>
) => T;

/**
* Type that describes a tuple of arguments passed into the constructor
* of a reactor class.
*/
export type ReactorArgs<T> = T extends any[] ? T : never;

/**
* A bank of reactor instances.
*/
Expand All @@ -40,18 +35,18 @@ export class Bank<T extends Reactor, S> {
* Construct a new bank of given width on the basis of a given reactor class and a list of arguments.
* @param width the width of the bank
* @param cls the class to construct reactor instances of that will populate the bank
* @param args the arguments to pass into the constructor of the given reactor class
* @param parameters the arguments to pass into the constructor of the given reactor class
*/
constructor(
container: Reactor,
width: number,
cls: ReactorClass<T, S>,
...args: ReactorArgs<S>
...parameters: ParmList<S>
) {
for (let i = 0; i < width; i++) {
Bank.initializationMap.set(container, i);
console.log(`Setting initializing to ${i}`);
this.members.push(Reflect.construct(cls, args, cls));
this.members.push(Reflect.construct(cls, parameters, cls));
}
Bank.initializationMap.delete(container);
}
Expand Down
4 changes: 1 addition & 3 deletions src/core/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export abstract class Component {
* A symbol that identifies this component, and it also used to selectively
* grant access to its privileged functions.
*/
// TODO (axmmisaka): Is instantiating in abstract class a good idea...?
// eslint-disable-next-line symbol-description
protected _key = Symbol();
protected _key = Symbol("Unique component identifier");

/**
* The container of this component. Each component is contained by a
Expand Down
19 changes: 10 additions & 9 deletions src/core/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,8 @@ class RTIClient extends EventEmitter {
* meaning that the type checker cannot check whether uses of the action are type safe.
* In an alternative design, type information might be preserved. TODO(marten): Look into this.
*/
private readonly federatePortActionByID: Map<number, Action<any>> = new Map<
number,
Action<any>
>();
private readonly federatePortActionByID: Map<number, Action<unknown>> =
new Map<number, Action<unknown>>();

/**
* Establish the mapping between a federate port's action and its ID.
Expand All @@ -323,7 +321,10 @@ class RTIClient extends EventEmitter {
federatePortID: number,
federatePortAction: Action<T>
): void {
this.federatePortActionByID.set(federatePortID, federatePortAction);
this.federatePortActionByID.set(
federatePortID,
federatePortAction as Action<unknown>
);
}

/**
Expand Down Expand Up @@ -1123,7 +1124,7 @@ export class FederatedApp extends App {
*/
private stopRequestInfo: StopRequestInfo = new StopRequestInfo(
StopRequestState.NOT_SENT,
new Tag(TimeValue.FOREVER(), 0)
new Tag(TimeValue.forever(), 0)
);

/**
Expand All @@ -1132,7 +1133,7 @@ export class FederatedApp extends App {
* An RTI synchronized Federate cannot advance its logical time
* beyond this value.
*/
private greatestTimeAdvanceGrant: Tag = new Tag(TimeValue.NEVER(), 0);
private greatestTimeAdvanceGrant: Tag = new Tag(TimeValue.never(), 0);

private readonly upstreamFedIDs: number[] = [];

Expand Down Expand Up @@ -1220,7 +1221,7 @@ export class FederatedApp extends App {
* @param nextEvent
*/
protected _canProceed(nextEvent: TaggedEvent<unknown>): boolean {
let tagBarrier = new Tag(TimeValue.NEVER());
let tagBarrier = new Tag(TimeValue.never());
// Set tag barrier using the tag when stop is requested but not granted yet.
// Otherwise, set the tagBarrier using the greated TAG.
if (this.stopRequestInfo.state === StopRequestState.SENT) {
Expand Down Expand Up @@ -1361,7 +1362,7 @@ export class FederatedApp extends App {
);
}
for (let index = 0; index < config.dependsOn.length; index++) {
let minOutputConnectionDelay = TimeValue.FOREVER();
let minOutputConnectionDelay = TimeValue.forever();
for (const candidate of config.upstreamConnectionDelays[index]) {
if (minOutputConnectionDelay.isLaterThan(candidate)) {
minOutputConnectionDelay = candidate;
Expand Down
5 changes: 1 addition & 4 deletions src/core/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ export abstract class WritableMultiPort<T> implements MultiReadWrite<T> {
* Interface for a writable multi port, intended as a wrapper for a multi port.
*/
interface IOPortManager<T> extends TriggerManager {
// TODO (axmmisaka): Function property is better in terms of type checking
// as tsc will check additional info; yet that additional check will cause massive issues
// and therefore this linter rule is disabled and method signature is used.
// However, this indicates that there are typing issues and needs to be addressed.
// See https://github.com/lf-lang/reactor-ts/issues/184
// eslint-disable-next-line @typescript-eslint/method-signature-style
addReceiver(port: WritablePort<T>): void;
// eslint-disable-next-line @typescript-eslint/method-signature-style
Expand Down
28 changes: 13 additions & 15 deletions src/core/reactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export abstract class Reactor extends Component {
}
}

public disconnect(src: IOPort<unknown>, dst?: IOPort<unknown>): void {
public disconnect<R, S extends R>(src: IOPort<S>, dst?: IOPort<R>): void {
if (
src instanceof IOPort &&
(dst === undefined || dst instanceof IOPort)
Expand Down Expand Up @@ -578,7 +578,6 @@ export abstract class Reactor extends Component {
return action.asSchedulable(this._getKey(action));
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private _recordDeps<T extends Variable[]>(reaction: Reaction<T>): void {
// Add a dependency on the previous reaction or mutation, if it exists.
const prev = this._getLastReactionOrMutation();
Expand Down Expand Up @@ -1223,7 +1222,9 @@ export abstract class Reactor extends Component {
this._dependencyGraph.addEdge(src, dst);
// Register receiver for value propagation.
const writer = dst.asWritable(this._getKey(dst));
src.getManager(this._getKey(src)).addReceiver(writer as WritablePort<S>);
src
.getManager(this._getKey(src))
.addReceiver(writer as unknown as WritablePort<S>);
const val = src.get();
if (this._runtime.isRunning() && val !== undefined) {
writer.set(val);
Expand Down Expand Up @@ -1468,23 +1469,21 @@ export abstract class Reactor extends Component {
}
}

private _uncheckedDisconnect<R, S extends R>(
src: IOPort<S>,
dst?: IOPort<R>
private _uncheckedDisconnect(
src: IOPort<unknown>,
dst?: IOPort<unknown>
): void {
Log.debug(this, () => `disconnecting ${src} and ${dst}`);
if (dst instanceof IOPort) {
const writer = dst.asWritable(this._getKey(dst));
src.getManager(this._getKey(src)).delReceiver(writer as WritablePort<S>);
src.getManager(this._getKey(src)).delReceiver(writer);
this._dependencyGraph.removeEdge(src, dst);
} else {
const nodes = this._dependencyGraph.getDownstreamNeighbors(src);
for (const node of nodes) {
if (node instanceof IOPort) {
const writer = node.asWritable(this._getKey(node));
src
.getManager(this._getKey(src))
.delReceiver(writer as WritablePort<S>);
src.getManager(this._getKey(src)).delReceiver(writer);
this._dependencyGraph.removeEdge(src, node);
}
}
Expand Down Expand Up @@ -1619,8 +1618,7 @@ export class CallerPort<A, R> extends Port<R> implements Write<A>, Read<R> {
}
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface CalleeManager<T> extends TriggerManager {
interface CalleeManager extends TriggerManager {
setLastCaller: (reaction: Reaction<Variable[]> | undefined) => void;
getLastCaller: () => Reaction<Variable[]> | undefined;
addReaction: (procedure: Procedure<Variable[]>) => void;
Expand Down Expand Up @@ -1664,14 +1662,14 @@ export class CalleePort<A, R> extends Port<A> implements Read<A>, Write<R> {
*
* @param key
*/
public getManager(key: symbol | undefined): CalleeManager<A> {
public getManager(key: symbol | undefined): CalleeManager {
if (this._key === key) {
return this.manager;
}
throw Error("Unable to grant access to manager.");
}

protected manager: CalleeManager<A> = new (class implements CalleeManager<A> {
protected manager: CalleeManager = new (class implements CalleeManager {
constructor(private readonly port: CalleePort<A, unknown>) {}

getContainer(): Reactor {
Expand Down Expand Up @@ -1783,7 +1781,7 @@ export interface MutationSandbox extends ReactionSandbox {
dst: CalleePort<T, S> | IOPort<R>
) => void;

disconnect: (src: IOPort<unknown>, dst?: IOPort<unknown>) => void;
disconnect: <R, S extends R>(src: IOPort<S>, dst?: IOPort<R>) => void;

delete: (reactor: Reactor) => void;

Expand Down
Loading