Skip to content

Commit

Permalink
Require triple equals via eslint (#447)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkleeman authored Oct 14, 2024
1 parent 0cac0a2 commit 5451ca5
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"plugins": ["@typescript-eslint", "require-extensions"],
"rules": {
"no-console": "error",
"eqeqeq": "error",
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/restrict-template-expressions": [
Expand Down
2 changes: 1 addition & 1 deletion packages/restate-e2e-services/src/non_determinism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const invocationCounts = new Map<string, number>();
function doLeftAction(ctx: restate.ObjectContext): boolean {
const newValue = (invocationCounts.get(ctx.key) ?? 0) + 1;
invocationCounts.set(ctx.key, newValue);
return newValue % 2 == 1;
return newValue % 2 === 1;
}

function incrementCounter(ctx: restate.ObjectContext) {
Expand Down
2 changes: 1 addition & 1 deletion packages/restate-e2e-services/src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const wf = restate.workflow({

const output = await ctx.promise("p");

if (ctx.promise("p").peek() == undefined) {
if (ctx.promise("p").peek() === undefined) {
throw new restate.TerminalError("Durable promise should be completed");
}

Expand Down
8 changes: 4 additions & 4 deletions packages/restate-sdk-clients/src/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class HttpIngress implements Ingress {
result,
};
} catch (e) {
if (!(e instanceof HttpCallError) || e.status != 470) {
if (!(e instanceof HttpCallError) || e.status !== 470) {
throw e;
}
return {
Expand All @@ -335,11 +335,11 @@ class HttpIngress implements Ingress {
{
get: (_target, prop) => {
const handler = prop as string;
if (handler == "workflowSubmit") {
if (handler === "workflowSubmit") {
return workflowSubmit;
} else if (handler == "workflowAttach") {
} else if (handler === "workflowAttach") {
return workflowAttach;
} else if (handler == "workflowOutput") {
} else if (handler === "workflowOutput") {
return workflowOutput;
}
// shared handlers pass trough via the ingress's normal invocation form
Expand Down
4 changes: 2 additions & 2 deletions packages/restate-sdk-core/src/serde_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class JsonSerde<T> implements Serde<T | undefined> {
}

deserialize(data: Uint8Array): T | undefined {
if (data.length == 0) {
if (data.length === 0) {
return undefined;
}
return JSON.parse(new TextDecoder().decode(data)) as T;
Expand Down Expand Up @@ -62,7 +62,7 @@ class VoidSerde implements Serde<void> {
}

deserialize(data: Uint8Array): void {
if (data.length != 0) {
if (data.length !== 0) {
throw new Error("Expected empty data");
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/restate-sdk/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export const CombineablePromise = {
all<T extends readonly CombineablePromise<unknown>[] | []>(
values: T
): Promise<{ -readonly [P in keyof T]: Awaited<T[P]> }> {
if (values.length == 0) {
if (values.length === 0) {
return Promise.all(values);
}
return ContextImpl.createCombinator("All", values) as Promise<{
Expand All @@ -626,7 +626,7 @@ export const CombineablePromise = {
race<T extends readonly CombineablePromise<unknown>[] | []>(
values: T
): Promise<Awaited<T[number]>> {
if (values.length == 0) {
if (values.length === 0) {
return Promise.race(values);
}
return ContextImpl.createCombinator("Race", values) as Promise<
Expand All @@ -647,7 +647,7 @@ export const CombineablePromise = {
any<T extends readonly CombineablePromise<unknown>[] | []>(
values: T
): Promise<Awaited<T[number]>> {
if (values.length == 0) {
if (values.length === 0) {
return Promise.any(values);
}
return ContextImpl.createCombinator("Any", values) as Promise<
Expand All @@ -669,7 +669,7 @@ export const CombineablePromise = {
): Promise<{
-readonly [P in keyof T]: PromiseSettledResult<Awaited<T[P]>>;
}> {
if (values.length == 0) {
if (values.length === 0) {
return Promise.allSettled(values);
}
return ContextImpl.createCombinator("AllSettled", values) as Promise<{
Expand Down
26 changes: 13 additions & 13 deletions packages/restate-sdk/src/context_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
}, new Map()),
attemptHeaders: Object.entries(attemptHeaders).reduce(
(headers, [key, value]) => {
if (value != undefined) {
if (value !== undefined) {
headers.set(key, value instanceof Array ? value[0] : value);
}
return headers;
Expand Down Expand Up @@ -139,7 +139,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
return this.processCompletableEntry(
(vm) => vm.sys_get_state(name),
(asyncResultValue) => {
if (asyncResultValue == "Empty") {
if (asyncResultValue === "Empty") {
// Empty
return null;
} else if ("Success" in asyncResultValue) {
Expand Down Expand Up @@ -244,7 +244,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
const parameter = requestSerde.serialize(send.parameter);

let delay;
if (send.delay != undefined) {
if (send.delay !== undefined) {
delay = BigInt(send.delay);
}

Expand Down Expand Up @@ -358,7 +358,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
// Record the result/failure, get back the handle for the ack.
let handle;
try {
if (err != undefined) {
if (err !== undefined) {
if (err instanceof TerminalError) {
// Record failure, go ahead
handle = this.coreVm.sys_run_exit_failure({
Expand Down Expand Up @@ -409,7 +409,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
return this.processCompletableEntry(
(vm) => vm.sys_sleep(BigInt(millis)),
(asyncResultValue) => {
if (asyncResultValue == "Empty") {
if (asyncResultValue === "Empty") {
// Empty
return undefined as void;
} else if ("Failure" in asyncResultValue) {
Expand Down Expand Up @@ -453,7 +453,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
if (!serde) {
return defaultSerde<T>().deserialize(asyncResultValue.Success);
}
if (asyncResultValue.Success.length == 0) {
if (asyncResultValue.Success.length === 0) {
return undefined as T;
}
return serde.deserialize(asyncResultValue.Success);
Expand Down Expand Up @@ -482,10 +482,10 @@ export class ContextImpl implements ObjectContext, WorkflowContext {

if (serde) {
value =
payload == undefined ? new Uint8Array() : serde.serialize(payload);
payload === undefined ? new Uint8Array() : serde.serialize(payload);
} else {
value =
payload != undefined
payload !== undefined
? defaultSerde().serialize(payload)
: defaultSerde().serialize(null);
}
Expand Down Expand Up @@ -634,7 +634,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
return promisesMap.get(handlesResult[0]);
case "OrTimeout":
// The sleep promise is always the second one in the list.
if (handlesResult[0] == castedPromises[1].asyncResultHandle) {
if (handlesResult[0] === castedPromises[1].asyncResultHandle) {
return Promise.reject(new TimeoutError());
} else {
return promisesMap.get(handlesResult[0]);
Expand Down Expand Up @@ -751,7 +751,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {

// Now loop waiting for the async result
let asyncResult = this.coreVm.take_async_result(handle);
while (asyncResult == "NotReady") {
while (asyncResult === "NotReady") {
await this.awaitNextRead();
// Using notify_await_point immediately before take_async_result
// makes sure the state machine will try to suspend only now,
Expand All @@ -776,7 +776,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
// and will notify the caller that a read was executed
// and the result was piped in the state machine.
private awaitNextRead(): Promise<void> {
if (this.currentRead == undefined) {
if (this.currentRead === undefined) {
// Register a new read
this.currentRead = this.readNext().finally(() => {
this.currentRead = undefined;
Expand Down Expand Up @@ -808,7 +808,7 @@ export class ContextImpl implements ObjectContext, WorkflowContext {
const error = ensureError(e);
if (
!(error instanceof RestateError) ||
error.code != SUSPENDED_ERROR_CODE
error.code !== SUSPENDED_ERROR_CODE
) {
this.console.warn("Function completed with an error.\n", error);
}
Expand All @@ -823,7 +823,7 @@ function unpack<T>(
a: string | RunAction<T>,
b?: RunAction<T>
): { name?: string; action: RunAction<T> } {
if (typeof a == "string") {
if (typeof a === "string") {
if (typeof b !== "function") {
throw new TypeError("");
}
Expand Down
9 changes: 6 additions & 3 deletions packages/restate-sdk/src/endpoint/handlers/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export class GenericHandler implements RestateHandler {
private readonly protocolMode: ProtocolMode
) {
// Setup identity verifier
if (this.endpoint.keySet == undefined || this.endpoint.keySet.length == 0) {
if (
this.endpoint.keySet === undefined ||
this.endpoint.keySet.length === 0
) {
this.endpoint.rlog.warn(
`Accepting requests without validating request signatures; handler access must be restricted`
);
Expand Down Expand Up @@ -257,7 +260,7 @@ export class GenericHandler implements RestateHandler {
// Now buffer input entries
while (!coreVm.is_ready_to_execute()) {
const nextValue = await inputReader.read();
if (nextValue.value != undefined) {
if (nextValue.value !== undefined) {
coreVm.notify_input(nextValue.value);
}
if (nextValue.done) {
Expand Down Expand Up @@ -318,7 +321,7 @@ export class GenericHandler implements RestateHandler {
const error = ensureError(e);
if (
!(error instanceof RestateError) ||
error.code != SUSPENDED_ERROR_CODE
error.code !== SUSPENDED_ERROR_CODE
) {
console.warn("Function completed with an error.\n", error);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/restate-sdk/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const defaultLogger: Logger = (
function readRestateLogLevel(): RestateLogLevel {
const env = globalThis.process?.env?.RESTATE_LOGGING;
const level = logLevelFromName(env);
if (level != null) {
if (level !== null) {
return level;
}
return RestateLogLevel.INFO;
Expand Down
4 changes: 2 additions & 2 deletions packages/restate-sdk/src/types/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class VirtualObjectComponent implements Component {
contentType: opts.contentType ?? "application/json",
},
ty:
opts.kind == HandlerKind.EXCLUSIVE
opts.kind === HandlerKind.EXCLUSIVE
? d.ServiceHandlerType.EXCLUSIVE
: d.ServiceHandlerType.SHARED,
};
Expand Down Expand Up @@ -220,7 +220,7 @@ export class WorkflowComponent implements Component {
contentType: handler.contentType ?? "application/json",
},
ty:
handler.kind == HandlerKind.WORKFLOW
handler.kind === HandlerKind.WORKFLOW
? d.ServiceHandlerType.WORKFLOW
: d.ServiceHandlerType.SHARED,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/restate-sdk/src/types/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function ensureError(e: unknown): Error {
if (e instanceof Error) {
return e;
}
if (typeof e == "object" && e != null && "code" in e && "message" in e) {
if (typeof e === "object" && e !== null && "code" in e && "message" in e) {
// This is an error from the VM
return new RestateError(e.message as string, {
errorCode: e.code as number,
Expand Down
18 changes: 9 additions & 9 deletions packages/restate-sdk/src/types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class HandlerWrapper {
} else if (opts?.accept) {
// accept but no serializer, use pass trough
inputSerde = new DeserializerWrapper(opts.accept, (input) => input);
} else if (opts?.contentType == JSON_CONTENT_TYPE) {
} else if (opts?.contentType === JSON_CONTENT_TYPE) {
// contentType is JSON, use the default serde
inputSerde = defaultSerde();
} else if (opts?.input) {
Expand All @@ -426,7 +426,7 @@ export class HandlerWrapper {
opts.contentType ?? JSON_CONTENT_TYPE,
opts.outputSerializer
);
} else if (opts?.contentType == JSON_CONTENT_TYPE) {
} else if (opts?.contentType === JSON_CONTENT_TYPE) {
// contentType is JSON, use the default serde
outputSerde = defaultSerde();
} else if (opts?.contentType) {
Expand Down Expand Up @@ -541,7 +541,7 @@ export namespace handlers {
optsOrFn: WorkflowHandlerOpts | WorkflowHandler<F, WorkflowContext<any>>,
fn?: WorkflowHandler<F, WorkflowContext<any>>
): F {
if (typeof optsOrFn == "function") {
if (typeof optsOrFn === "function") {
return HandlerWrapper.from(HandlerKind.WORKFLOW, optsOrFn).transpose();
}
const opts = optsOrFn satisfies WorkflowHandlerOpts;
Expand Down Expand Up @@ -593,7 +593,7 @@ export namespace handlers {
| WorkflowSharedHandler<F, WorkflowSharedContext<any>>,
fn?: WorkflowSharedHandler<F, WorkflowSharedContext<any>>
): F {
if (typeof optsOrFn == "function") {
if (typeof optsOrFn === "function") {
return HandlerWrapper.from(HandlerKind.SHARED, optsOrFn).transpose();
}
const opts = optsOrFn satisfies ObjectHandlerOpts;
Expand Down Expand Up @@ -649,7 +649,7 @@ export namespace handlers {
optsOrFn: ObjectHandlerOpts | ObjectHandler<F, ObjectContext<any>>,
fn?: ObjectHandler<F, ObjectContext<any>>
): F {
if (typeof optsOrFn == "function") {
if (typeof optsOrFn === "function") {
return HandlerWrapper.from(HandlerKind.EXCLUSIVE, optsOrFn).transpose();
}
const opts = optsOrFn satisfies ObjectHandlerOpts;
Expand Down Expand Up @@ -707,7 +707,7 @@ export namespace handlers {
| ObjectSharedHandler<F, ObjectSharedContext<any>>,
fn?: ObjectSharedHandler<F, ObjectSharedContext<any>>
): F {
if (typeof optsOrFn == "function") {
if (typeof optsOrFn === "function") {
return HandlerWrapper.from(HandlerKind.SHARED, optsOrFn).transpose();
}
const opts = optsOrFn satisfies ObjectHandlerOpts;
Expand Down Expand Up @@ -973,7 +973,7 @@ export const workflow = <P extends string, M>(workflow: {
} else {
throw new TypeError(`Missing main workflow handler, named 'run'`);
}
if (runWrapper.kind != HandlerKind.WORKFLOW) {
if (runWrapper.kind !== HandlerKind.WORKFLOW) {
throw new TypeError(
`Workflow's main handler handler run, must be of type workflow'`
);
Expand All @@ -986,7 +986,7 @@ export const workflow = <P extends string, M>(workflow: {
//

for (const [name, handler] of Object.entries(workflow.handlers)) {
if (name == "run") {
if (name === "run") {
continue;
}
let wrapper: HandlerWrapper;
Expand All @@ -1000,7 +1000,7 @@ export const workflow = <P extends string, M>(workflow: {
} else {
throw new TypeError(`Unexpected handler type ${name}`);
}
if (wrapper.kind == HandlerKind.WORKFLOW) {
if (wrapper.kind === HandlerKind.WORKFLOW) {
throw new TypeError(
`A workflow must contain exactly one handler annotated as workflow, named 'run'. Please use a shared handler for any additional handlers`
);
Expand Down
2 changes: 1 addition & 1 deletion packages/restate-sdk/src/utils/rand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class RandImpl implements Rand {
id: string | [bigint, bigint, bigint, bigint],
private readonly checkState: (state: string) => void = () => undefined
) {
if (typeof id == "string") {
if (typeof id === "string") {
// hash the invocation ID, which is known to contain 74 bits of entropy
const hash = createHash("sha256").update(id).digest();

Expand Down

0 comments on commit 5451ca5

Please sign in to comment.