From 1fc17b3ae8187e776480371808b4821aeb1d191f Mon Sep 17 00:00:00 2001 From: Nick Stott Date: Wed, 23 Oct 2019 15:56:53 -0400 Subject: [PATCH] resolve eslint warnings --- cli/js/streams/mod.ts | 1 - cli/js/streams/pipe-to.ts | 23 ++-- cli/js/streams/queue-mixin.ts | 11 +- cli/js/streams/queue.ts | 2 +- .../readable-byte-stream-controller.ts | 19 ++-- cli/js/streams/readable-internals.ts | 105 +++++++++--------- cli/js/streams/readable-stream-byob-reader.ts | 4 +- .../streams/readable-stream-byob-request.ts | 4 +- .../readable-stream-default-controller.ts | 19 ++-- .../streams/readable-stream-default-reader.ts | 2 +- cli/js/streams/readable-stream.ts | 19 ++-- cli/js/streams/shared-internals.ts | 29 ++--- cli/js/streams/strategies.ts | 7 +- cli/js/streams/transform-internals.ts | 48 ++++---- cli/js/streams/transform-stream.ts | 9 +- cli/js/streams/writable-internals.ts | 83 ++++++++------ .../writable-stream-default-controller.ts | 13 ++- cli/js/streams/writable-stream.ts | 4 +- core/modules.rs | 2 +- 19 files changed, 226 insertions(+), 178 deletions(-) diff --git a/cli/js/streams/mod.ts b/cli/js/streams/mod.ts index bec6658c53757f..97386b1d2ee3fd 100644 --- a/cli/js/streams/mod.ts +++ b/cli/js/streams/mod.ts @@ -16,4 +16,3 @@ export { ByteLengthQueuingStrategy, CountQueuingStrategy } from "./strategies.ts"; - diff --git a/cli/js/streams/pipe-to.ts b/cli/js/streams/pipe-to.ts index 8a66bc942f8e22..18d2bd4f82f872 100644 --- a/cli/js/streams/pipe-to.ts +++ b/cli/js/streams/pipe-to.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as rs from "./readable-internals.ts"; import * as ws from "./writable-internals.ts"; import * as shared from "./shared-internals.ts"; @@ -26,7 +29,7 @@ export function pipeTo( source: rs.SDReadableStream, dest: ws.WritableStream, options: PipeOptions -) { +): Promise { const preventClose = !!options.preventClose; const preventAbort = !!options.preventAbort; const preventCancel = !!options.preventCancel; @@ -43,7 +46,7 @@ export function pipeTo( let abortAlgorithm: () => any; if (signal !== undefined) { - abortAlgorithm = () => { + abortAlgorithm = (): void => { // TODO this should be a DOMException, // https://github.com/stardazed/sd-streams/blob/master/packages/streams/src/pipe-to.ts#L38 const error = new DenoError(ErrorKind.AbortError, "Aborted"); @@ -83,7 +86,7 @@ export function pipeTo( stream: rs.SDReadableStream | ws.WritableStream, promise: Promise, action: (error: shared.ErrorResult) => void - ) { + ): void { if (stream[shared.state_] === "errored") { action(stream[shared.storedError_]); } else { @@ -95,7 +98,7 @@ export function pipeTo( stream: rs.SDReadableStream | ws.WritableStream, promise: Promise, action: () => void - ) { + ): void { if (stream[shared.state_] === "closed") { action(); } else { @@ -155,7 +158,7 @@ export function pipeTo( ); } - function flushRemainder() { + function flushRemainder(): Promise | undefined { if ( dest[shared.state_] === "writable" && !ws.writableStreamCloseQueuedOrInFlight(dest) @@ -166,17 +169,17 @@ export function pipeTo( } } - function shutDown(action?: () => Promise, error?: ErrorWrapper) { + function shutDown(action?: () => Promise, error?: ErrorWrapper): void { if (shuttingDown) { return; } shuttingDown = true; if (action === undefined) { - action = () => Promise.resolve(); + action = (): Promise => Promise.resolve(); } - function finishShutDown() { + function finishShutDown(): void { action!().then( _ => finalize(error), newError => finalize({ actualError: newError }) @@ -191,7 +194,7 @@ export function pipeTo( } } - function finalize(error?: ErrorWrapper) { + function finalize(error?: ErrorWrapper): void { ws.writableStreamDefaultWriterRelease(writer); rs.readableStreamReaderGenericRelease(reader); if (signal && abortAlgorithm) { @@ -204,7 +207,7 @@ export function pipeTo( } } - function next() { + function next(): Promise | undefined { if (shuttingDown) { return; } diff --git a/cli/js/streams/queue-mixin.ts b/cli/js/streams/queue-mixin.ts index 0fa47893368c50..23c57d75ffde2f 100644 --- a/cli/js/streams/queue-mixin.ts +++ b/cli/js/streams/queue-mixin.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import { Queue, QueueImpl } from "./queue.ts"; import { isFiniteNonNegativeNumber } from "./shared-internals.ts"; @@ -33,7 +36,7 @@ export interface ByteQueueContainer { [queueTotalSize_]: number; } -export function dequeueValue(container: QueueContainer) { +export function dequeueValue(container: QueueContainer): V { // Assert: container has[[queue]] and[[queueTotalSize]] internal slots. // Assert: container.[[queue]] is not empty. const pair = container[queue_].shift()!; @@ -46,7 +49,7 @@ export function enqueueValueWithSize( container: QueueContainer, value: V, size: number -) { +): void { // Assert: container has[[queue]] and[[queueTotalSize]] internal slots. if (!isFiniteNonNegativeNumber(size)) { throw new RangeError("Chunk size must be a non-negative, finite numbers"); @@ -55,7 +58,7 @@ export function enqueueValueWithSize( container[queueTotalSize_] += size; } -export function peekQueueValue(container: QueueContainer) { +export function peekQueueValue(container: QueueContainer): V { // Assert: container has[[queue]] and[[queueTotalSize]] internal slots. // Assert: container.[[queue]] is not empty. return container[queue_].front()!.value; @@ -63,7 +66,7 @@ export function peekQueueValue(container: QueueContainer) { export function resetQueue( container: ByteQueueContainer | QueueContainer -) { +): void { // Chrome (as of v67) has a steep performance cliff with large arrays // and shift(), around about 50k elements. While this is an unusual case // we use a simple wrapper around shift and push that is chunked to diff --git a/cli/js/streams/queue.ts b/cli/js/streams/queue.ts index e243ba169b4e08..264851baf4b092 100644 --- a/cli/js/streams/queue.ts +++ b/cli/js/streams/queue.ts @@ -59,7 +59,7 @@ export class QueueImpl implements Queue { return t; } - get length() { + get length(): number { return this.length_; } } diff --git a/cli/js/streams/readable-byte-stream-controller.ts b/cli/js/streams/readable-byte-stream-controller.ts index 0ac1659feff764..86efd416c2aa92 100644 --- a/cli/js/streams/readable-byte-stream-controller.ts +++ b/cli/js/streams/readable-byte-stream-controller.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as rs from "./readable-internals.ts"; import * as q from "./queue-mixin.ts"; import * as shared from "./shared-internals.ts"; @@ -70,7 +73,7 @@ export class ReadableByteStreamController return rs.readableByteStreamControllerGetDesiredSize(this); } - close() { + close(): void { if (!rs.isReadableByteStreamController(this)) { throw new TypeError(); } @@ -83,7 +86,7 @@ export class ReadableByteStreamController rs.readableByteStreamControllerClose(this); } - enqueue(chunk: ArrayBufferView) { + enqueue(chunk: ArrayBufferView): void { if (!rs.isReadableByteStreamController(this)) { throw new TypeError(); } @@ -100,14 +103,14 @@ export class ReadableByteStreamController return rs.readableByteStreamControllerEnqueue(this, chunk); } - error(error?: shared.ErrorResult) { + error(error?: shared.ErrorResult): void { if (!rs.isReadableByteStreamController(this)) { throw new TypeError(); } rs.readableByteStreamControllerError(this, error); } - [rs.cancelSteps_](reason: shared.ErrorResult) { + [rs.cancelSteps_](reason: shared.ErrorResult): Promise { if (this[rs.pendingPullIntos_].length > 0) { const firstDescriptor = this[rs.pendingPullIntos_][0]; firstDescriptor.bytesFilled = 0; @@ -118,7 +121,9 @@ export class ReadableByteStreamController return result; } - [rs.pullSteps_](forAuthorCode: boolean) { + [rs.pullSteps_]( + forAuthorCode: boolean + ): Promise> { const stream = this[rs.controlledReadableByteStream_]; // Assert: ! ReadableStreamHasDefaultReader(stream) is true. if (this[q.queueTotalSize_] > 0) { @@ -165,13 +170,13 @@ export function setUpReadableByteStreamControllerFromUnderlyingSource( stream: rs.SDReadableStream, underlyingByteSource: UnderlyingByteSource, highWaterMark: number -) { +): void { // Assert: underlyingByteSource is not undefined. const controller = Object.create( ReadableByteStreamController.prototype ) as ReadableByteStreamController; - const startAlgorithm = () => { + const startAlgorithm = (): any => { return shared.invokeOrNoop(underlyingByteSource, "start", [controller]); }; const pullAlgorithm = shared.createAlgorithmFromUnderlyingMethod( diff --git a/cli/js/streams/readable-internals.ts b/cli/js/streams/readable-internals.ts index a0e3eb0fbabeff..6f892a4c8d7e09 100644 --- a/cli/js/streams/readable-internals.ts +++ b/cli/js/streams/readable-internals.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as ws from "./writable-internals.ts"; import * as shared from "./shared-internals.ts"; import * as q from "./queue-mixin.ts"; @@ -233,7 +236,7 @@ export declare class SDReadableStream { export function initializeReadableStream( stream: SDReadableStream -) { +): void { stream[shared.state_] = "readable"; stream[reader_] = undefined; stream[shared.storedError_] = undefined; @@ -251,13 +254,13 @@ export function isReadableStream( export function isReadableStreamLocked( stream: SDReadableStream -) { +): boolean { return stream[reader_] !== undefined; } export function readableStreamGetNumReadIntoRequests( stream: SDReadableStream -) { +): number | undefined { // TODO remove the "as unknown" cast // This is in to workaround a compiler error // error TS2352: Conversion of type 'SDReadableStreamReader' to type 'SDReadableStreamBYOBReader' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. @@ -271,7 +274,7 @@ export function readableStreamGetNumReadIntoRequests( export function readableStreamGetNumReadRequests( stream: SDReadableStream -) { +): number { const reader = stream[reader_] as SDReadableStreamDefaultReader; if (reader === undefined) { return 0; @@ -294,7 +297,7 @@ export function readableStreamCreateReadResult( export function readableStreamAddReadIntoRequest( stream: SDReadableStream, forAuthorCode: boolean -) { +): Promise> { // Assert: ! IsReadableStreamBYOBReader(stream.[[reader]]) is true. // Assert: stream.[[state]] is "readable" or "closed". const reader = stream[reader_] as SDReadableStreamBYOBReader; @@ -309,7 +312,7 @@ export function readableStreamAddReadIntoRequest( export function readableStreamAddReadRequest( stream: SDReadableStream, forAuthorCode: boolean -) { +): Promise> { // Assert: ! IsReadableStreamDefaultReader(stream.[[reader]]) is true. // Assert: stream.[[state]] is "readable". const reader = stream[reader_] as SDReadableStreamDefaultReader; @@ -323,14 +326,14 @@ export function readableStreamAddReadRequest( export function readableStreamHasBYOBReader( stream: SDReadableStream -) { +): boolean { const reader = stream[reader_]; return isReadableStreamBYOBReader(reader); } export function readableStreamHasDefaultReader( stream: SDReadableStream -) { +): boolean { const reader = stream[reader_]; return isReadableStreamDefaultReader(reader); } @@ -338,7 +341,7 @@ export function readableStreamHasDefaultReader( export function readableStreamCancel( stream: SDReadableStream, reason: shared.ErrorResult -) { +): Promise { if (stream[shared.state_] === "closed") { return Promise.resolve(undefined); } @@ -355,7 +358,7 @@ export function readableStreamCancel( export function readableStreamClose( stream: SDReadableStream -) { +): void { // Assert: stream.[[state]] is "readable". stream[shared.state_] = "closed"; const reader = stream[reader_]; @@ -382,7 +385,7 @@ export function readableStreamClose( export function readableStreamError( stream: SDReadableStream, error: shared.ErrorResult -) { +): void { if (stream[shared.state_] !== "readable") { throw new RangeError("Stream is in an invalid state"); } @@ -437,7 +440,7 @@ export function isReadableStreamBYOBReader( export function readableStreamReaderGenericInitialize( reader: SDReadableStreamReader, stream: SDReadableStream -) { +): void { reader[ownerReadableStream_] = stream; stream[reader_] = reader; const streamState = stream[shared.state_]; @@ -455,7 +458,7 @@ export function readableStreamReaderGenericInitialize( export function readableStreamReaderGenericRelease( reader: SDReadableStreamReader -) { +): void { // Assert: reader.[[ownerReadableStream]] is not undefined. // Assert: reader.[[ownerReadableStream]].[[reader]] is reader. const stream = reader[ownerReadableStream_]; @@ -479,7 +482,7 @@ export function readableStreamBYOBReaderRead( reader: SDReadableStreamBYOBReader, view: ArrayBufferView, forAuthorCode = false -) { +): Promise> { const stream = reader[ownerReadableStream_]!; // Assert: stream is not undefined. @@ -516,7 +519,7 @@ export function readableStreamFulfillReadIntoRequest( stream: SDReadableStream, chunk: ArrayBufferView, done: boolean -) { +): void { // TODO remove the "as unknown" cast const reader = (stream[reader_] as unknown) as SDReadableStreamBYOBReader; const readIntoRequest = reader[readIntoRequests_].shift()!; // <-- length check done in caller @@ -529,7 +532,7 @@ export function readableStreamFulfillReadRequest( stream: SDReadableStream, chunk: OutputType, done: boolean -) { +): void { const reader = stream[reader_] as SDReadableStreamDefaultReader; const readRequest = reader[readRequests_].shift()!; // <-- length check done in caller readRequest.resolve( @@ -547,7 +550,7 @@ export function setUpReadableStreamDefaultController( cancelAlgorithm: CancelAlgorithm, highWaterMark: number, sizeAlgorithm: QueuingStrategySizeCallback -) { +): void { // Assert: stream.[[readableStreamController]] is undefined. controller[controlledReadableStream_] = stream; q.resetQueue(controller); @@ -586,20 +589,20 @@ export function isReadableStreamDefaultController( export function readableStreamDefaultControllerHasBackpressure( controller: SDReadableStreamDefaultController -) { +): boolean { return !readableStreamDefaultControllerShouldCallPull(controller); } export function readableStreamDefaultControllerCanCloseOrEnqueue( controller: SDReadableStreamDefaultController -) { +): boolean { const state = controller[controlledReadableStream_][shared.state_]; return controller[closeRequested_] === false && state === "readable"; } export function readableStreamDefaultControllerGetDesiredSize( controller: SDReadableStreamDefaultController -) { +): number | null { const state = controller[controlledReadableStream_][shared.state_]; if (state === "errored") { return null; @@ -612,7 +615,7 @@ export function readableStreamDefaultControllerGetDesiredSize( export function readableStreamDefaultControllerClose( controller: SDReadableStreamDefaultController -) { +): void { // Assert: !ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) is true. controller[closeRequested_] = true; const stream = controller[controlledReadableStream_]; @@ -625,7 +628,7 @@ export function readableStreamDefaultControllerClose( export function readableStreamDefaultControllerEnqueue( controller: SDReadableStreamDefaultController, chunk: OutputType -) { +): void { const stream = controller[controlledReadableStream_]; // Assert: !ReadableStreamDefaultControllerCanCloseOrEnqueue(controller) is true. if ( @@ -657,7 +660,7 @@ export function readableStreamDefaultControllerEnqueue( export function readableStreamDefaultControllerError( controller: SDReadableStreamDefaultController, error: shared.ErrorResult -) { +): void { const stream = controller[controlledReadableStream_]; if (stream[shared.state_] !== "readable") { return; @@ -669,7 +672,7 @@ export function readableStreamDefaultControllerError( export function readableStreamDefaultControllerCallPullIfNeeded( controller: SDReadableStreamDefaultController -) { +): void { if (!readableStreamDefaultControllerShouldCallPull(controller)) { return; } @@ -698,7 +701,7 @@ export function readableStreamDefaultControllerCallPullIfNeeded( export function readableStreamDefaultControllerShouldCallPull( controller: SDReadableStreamDefaultController -) { +): boolean { const stream = controller[controlledReadableStream_]; if (!readableStreamDefaultControllerCanCloseOrEnqueue(controller)) { return false; @@ -721,7 +724,7 @@ export function readableStreamDefaultControllerShouldCallPull( export function readableStreamDefaultControllerClearAlgorithms( controller: SDReadableStreamDefaultController -) { +): void { controller[pullAlgorithm_] = undefined!; controller[cancelAlgorithm_] = undefined!; controller[strategySizeAlgorithm_] = undefined!; @@ -737,7 +740,7 @@ export function setUpReadableByteStreamController( cancelAlgorithm: CancelAlgorithm, highWaterMark: number, autoAllocateChunkSize: number | undefined -) { +): void { // Assert: stream.[[readableStreamController]] is undefined. if (stream[readableStreamController_] !== undefined) { throw new TypeError("Cannot reuse streams"); @@ -805,7 +808,7 @@ export function isReadableByteStreamController( export function readableByteStreamControllerCallPullIfNeeded( controller: SDReadableByteStreamController -) { +): void { if (!readableByteStreamControllerShouldCallPull(controller)) { return; } @@ -831,21 +834,21 @@ export function readableByteStreamControllerCallPullIfNeeded( export function readableByteStreamControllerClearAlgorithms( controller: SDReadableByteStreamController -) { +): void { controller[pullAlgorithm_] = undefined!; controller[cancelAlgorithm_] = undefined!; } export function readableByteStreamControllerClearPendingPullIntos( controller: SDReadableByteStreamController -) { +): void { readableByteStreamControllerInvalidateBYOBRequest(controller); controller[pendingPullIntos_] = []; } export function readableByteStreamControllerClose( controller: SDReadableByteStreamController -) { +): void { const stream = controller[controlledReadableByteStream_]; // Assert: controller.[[closeRequested]] is false. // Assert: stream.[[state]] is "readable". @@ -868,7 +871,7 @@ export function readableByteStreamControllerClose( export function readableByteStreamControllerCommitPullIntoDescriptor( stream: SDReadableStream, pullIntoDescriptor: PullIntoDescriptor -) { +): void { // Assert: stream.[[state]] is not "errored". let done = false; if (stream[shared.state_] === "closed") { @@ -888,7 +891,7 @@ export function readableByteStreamControllerCommitPullIntoDescriptor( export function readableByteStreamControllerConvertPullIntoDescriptor( pullIntoDescriptor: PullIntoDescriptor -) { +): ArrayBufferView { const { bytesFilled, elementSize } = pullIntoDescriptor; // Assert: bytesFilled <= pullIntoDescriptor.byteLength // Assert: bytesFilled mod elementSize is 0 @@ -902,7 +905,7 @@ export function readableByteStreamControllerConvertPullIntoDescriptor( export function readableByteStreamControllerEnqueue( controller: SDReadableByteStreamController, chunk: ArrayBufferView -) { +): void { const stream = controller[controlledReadableByteStream_]; // Assert: controller.[[closeRequested]] is false. // Assert: stream.[[state]] is "readable". @@ -954,7 +957,7 @@ export function readableByteStreamControllerEnqueueChunkToQueue( buffer: ArrayBufferLike, byteOffset: number, byteLength: number -) { +): void { controller[q.queue_].push({ buffer, byteOffset, byteLength }); controller[q.queueTotalSize_] += byteLength; } @@ -962,7 +965,7 @@ export function readableByteStreamControllerEnqueueChunkToQueue( export function readableByteStreamControllerError( controller: SDReadableByteStreamController, error: shared.ErrorResult -) { +): void { const stream = controller[controlledReadableByteStream_]; if (stream[shared.state_] !== "readable") { return; @@ -977,7 +980,7 @@ export function readableByteStreamControllerFillHeadPullIntoDescriptor( controller: SDReadableByteStreamController, size: number, pullIntoDescriptor: PullIntoDescriptor -) { +): void { // Assert: either controller.[[pendingPullIntos]] is empty, or the first element of controller.[[pendingPullIntos]] is pullIntoDescriptor. readableByteStreamControllerInvalidateBYOBRequest(controller); pullIntoDescriptor.bytesFilled += size; @@ -986,7 +989,7 @@ export function readableByteStreamControllerFillHeadPullIntoDescriptor( export function readableByteStreamControllerFillPullIntoDescriptorFromQueue( controller: SDReadableByteStreamController, pullIntoDescriptor: PullIntoDescriptor -) { +): boolean { const elementSize = pullIntoDescriptor.elementSize; const currentAlignedBytes = pullIntoDescriptor.bytesFilled - @@ -1046,7 +1049,7 @@ export function readableByteStreamControllerFillPullIntoDescriptorFromQueue( export function readableByteStreamControllerGetDesiredSize( controller: SDReadableByteStreamController -) { +): number | null { const stream = controller[controlledReadableByteStream_]; const state = stream[shared.state_]; if (state === "errored") { @@ -1060,7 +1063,7 @@ export function readableByteStreamControllerGetDesiredSize( export function readableByteStreamControllerHandleQueueDrain( controller: SDReadableByteStreamController -) { +): void { // Assert: controller.[[controlledReadableByteStream]].[[state]] is "readable". if (controller[q.queueTotalSize_] === 0 && controller[closeRequested_]) { readableByteStreamControllerClearAlgorithms(controller); @@ -1072,7 +1075,7 @@ export function readableByteStreamControllerHandleQueueDrain( export function readableByteStreamControllerInvalidateBYOBRequest( controller: SDReadableByteStreamController -) { +): void { const byobRequest = controller[byobRequest_]; if (byobRequest === undefined) { return; @@ -1084,7 +1087,7 @@ export function readableByteStreamControllerInvalidateBYOBRequest( export function readableByteStreamControllerProcessPullIntoDescriptorsUsingQueue( controller: SDReadableByteStreamController -) { +): void { // Assert: controller.[[closeRequested]] is false. const pendingPullIntos = controller[pendingPullIntos_]; while (pendingPullIntos.length > 0) { @@ -1111,7 +1114,7 @@ export function readableByteStreamControllerPullInto( controller: SDReadableByteStreamController, view: ArrayBufferView, forAuthorCode: boolean -) { +): Promise> { const stream = controller[controlledReadableByteStream_]; const elementSize = (view as Uint8Array).BYTES_PER_ELEMENT || 1; // DataView exposes this in Webkit as 1, is not present in FF or Blink @@ -1176,7 +1179,7 @@ export function readableByteStreamControllerPullInto( export function readableByteStreamControllerRespond( controller: SDReadableByteStreamController, bytesWritten: number -) { +): void { bytesWritten = Number(bytesWritten); if (!shared.isFiniteNonNegativeNumber(bytesWritten)) { throw new RangeError("bytesWritten must be a finite, non-negative number"); @@ -1188,7 +1191,7 @@ export function readableByteStreamControllerRespond( export function readableByteStreamControllerRespondInClosedState( controller: SDReadableByteStreamController, firstDescriptor: PullIntoDescriptor -) { +): void { firstDescriptor.buffer = shared.transferArrayBuffer(firstDescriptor.buffer); // Assert: firstDescriptor.[[bytesFilled]] is 0. const stream = controller[controlledReadableByteStream_]; @@ -1209,7 +1212,7 @@ export function readableByteStreamControllerRespondInReadableState( controller: SDReadableByteStreamController, bytesWritten: number, pullIntoDescriptor: PullIntoDescriptor -) { +): void { if ( pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength @@ -1257,7 +1260,7 @@ export function readableByteStreamControllerRespondInReadableState( export function readableByteStreamControllerRespondInternal( controller: SDReadableByteStreamController, bytesWritten: number -) { +): void { const firstDescriptor = controller[pendingPullIntos_][0]; const stream = controller[controlledReadableByteStream_]; if (stream[shared.state_] === "closed") { @@ -1282,7 +1285,7 @@ export function readableByteStreamControllerRespondInternal( export function readableByteStreamControllerRespondWithNewView( controller: SDReadableByteStreamController, view: ArrayBufferView -) { +): void { // Assert: controller.[[pendingPullIntos]] is not empty. const firstDescriptor = controller[pendingPullIntos_][0]; if ( @@ -1300,7 +1303,7 @@ export function readableByteStreamControllerRespondWithNewView( export function readableByteStreamControllerShiftPendingPullInto( controller: SDReadableByteStreamController -) { +): PullIntoDescriptor | undefined { const descriptor = controller[pendingPullIntos_].shift(); readableByteStreamControllerInvalidateBYOBRequest(controller); return descriptor; @@ -1308,7 +1311,7 @@ export function readableByteStreamControllerShiftPendingPullInto( export function readableByteStreamControllerShouldCallPull( controller: SDReadableByteStreamController -) { +): boolean { // Let stream be controller.[[controlledReadableByteStream]]. const stream = controller[controlledReadableByteStream_]; if (stream[shared.state_] !== "readable") { @@ -1341,7 +1344,7 @@ export function setUpReadableStreamBYOBRequest( request: SDReadableStreamBYOBRequest, controller: SDReadableByteStreamController, view: ArrayBufferView -) { +): void { if (!isReadableByteStreamController(controller)) { throw new TypeError(); } diff --git a/cli/js/streams/readable-stream-byob-reader.ts b/cli/js/streams/readable-stream-byob-reader.ts index 18bbb3802bf2c5..0f9bfb037848d3 100644 --- a/cli/js/streams/readable-stream-byob-reader.ts +++ b/cli/js/streams/readable-stream-byob-reader.ts @@ -15,7 +15,9 @@ export class SDReadableStreamBYOBReader implements rs.SDReadableStreamBYOBReader { [rs.closedPromise_]: shared.ControlledPromise; [rs.ownerReadableStream_]: rs.SDReadableStream | undefined; - [rs.readIntoRequests_]: Array>>; + [rs.readIntoRequests_]: Array< + rs.ReadRequest> + >; constructor(stream: rs.SDReadableStream) { if (!rs.isReadableStream(stream)) { diff --git a/cli/js/streams/readable-stream-byob-request.ts b/cli/js/streams/readable-stream-byob-request.ts index ff96613084fb9c..25b937f1088535 100644 --- a/cli/js/streams/readable-stream-byob-request.ts +++ b/cli/js/streams/readable-stream-byob-request.ts @@ -27,7 +27,7 @@ export class ReadableStreamBYOBRequest { return this[rs.view_]!; } - respond(bytesWritten: number) { + respond(bytesWritten: number): void { if (!rs.isReadableStreamBYOBRequest(this)) { throw new TypeError(); } @@ -41,7 +41,7 @@ export class ReadableStreamBYOBRequest { ); } - respondWithNewView(view: ArrayBufferView) { + respondWithNewView(view: ArrayBufferView): void { if (!rs.isReadableStreamBYOBRequest(this)) { throw new TypeError(); } diff --git a/cli/js/streams/readable-stream-default-controller.ts b/cli/js/streams/readable-stream-default-controller.ts index dd8b98a9d7ff85..e9ddce1bcba7ab 100644 --- a/cli/js/streams/readable-stream-default-controller.ts +++ b/cli/js/streams/readable-stream-default-controller.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as rs from "./readable-internals.ts"; import * as shared from "./shared-internals.ts"; import * as q from "./queue-mixin.ts"; @@ -37,7 +40,7 @@ export class ReadableStreamDefaultController return rs.readableStreamDefaultControllerGetDesiredSize(this); } - close() { + close(): void { if (!rs.isReadableStreamDefaultController(this)) { throw new TypeError(); } @@ -49,7 +52,7 @@ export class ReadableStreamDefaultController rs.readableStreamDefaultControllerClose(this); } - enqueue(chunk?: OutputType) { + enqueue(chunk?: OutputType): void { if (!rs.isReadableStreamDefaultController(this)) { throw new TypeError(); } @@ -61,21 +64,23 @@ export class ReadableStreamDefaultController rs.readableStreamDefaultControllerEnqueue(this, chunk!); } - error(e?: shared.ErrorResult) { + error(e?: shared.ErrorResult): void { if (!rs.isReadableStreamDefaultController(this)) { throw new TypeError(); } rs.readableStreamDefaultControllerError(this, e); } - [rs.cancelSteps_](reason: shared.ErrorResult) { + [rs.cancelSteps_](reason: shared.ErrorResult): Promise { q.resetQueue(this); const result = this[rs.cancelAlgorithm_](reason); rs.readableStreamDefaultControllerClearAlgorithms(this); return result; } - [rs.pullSteps_](forAuthorCode: boolean) { + [rs.pullSteps_]( + forAuthorCode: boolean + ): Promise> { const stream = this[rs.controlledReadableStream_]; if (this[q.queue_].length > 0) { const chunk = q.dequeueValue(this); @@ -106,10 +111,10 @@ export function setUpReadableStreamDefaultControllerFromUnderlyingSource< underlyingSource: UnderlyingSource, highWaterMark: number, sizeAlgorithm: QueuingStrategySizeCallback -) { +): void { // Assert: underlyingSource is not undefined. const controller = Object.create(ReadableStreamDefaultController.prototype); - const startAlgorithm = () => { + const startAlgorithm = (): any => { return shared.invokeOrNoop(underlyingSource, "start", [controller]); }; const pullAlgorithm = shared.createAlgorithmFromUnderlyingMethod( diff --git a/cli/js/streams/readable-stream-default-reader.ts b/cli/js/streams/readable-stream-default-reader.ts index 74453af527273b..eb1910a9d5263a 100644 --- a/cli/js/streams/readable-stream-default-reader.ts +++ b/cli/js/streams/readable-stream-default-reader.ts @@ -60,7 +60,7 @@ export class ReadableStreamDefaultReader return rs.readableStreamDefaultReaderRead(this, true); } - releaseLock() { + releaseLock(): void { if (!rs.isReadableStreamDefaultReader(this)) { throw new TypeError(); } diff --git a/cli/js/streams/readable-stream.ts b/cli/js/streams/readable-stream.ts index 49da4250153204..cadd858ddfa7af 100644 --- a/cli/js/streams/readable-stream.ts +++ b/cli/js/streams/readable-stream.ts @@ -8,10 +8,9 @@ * https://github.com/stardazed/sd-streams */ -/* eslint prefer-const: "warn" */ +/* eslint prefer-const: "off" */ // TODO remove this, surpressed because of // 284:7 error 'branch1' is never reassigned. Use 'const' instead prefer-const -// 285:7 error 'branch2' is never reassigned. Use 'const' instead prefer-const import * as rs from "./readable-internals.ts"; import * as ws from "./writable-internals.ts"; @@ -202,12 +201,12 @@ export function createReadableStream( cancelAlgorithm: rs.CancelAlgorithm, highWaterMark?: number, sizeAlgorithm?: QueuingStrategySizeCallback -) { +): SDReadableStream { if (highWaterMark === undefined) { highWaterMark = 1; } if (sizeAlgorithm === undefined) { - sizeAlgorithm = () => 1; + sizeAlgorithm = (): number => 1; } // Assert: ! IsNonNegativeNumber(highWaterMark) is true. @@ -236,7 +235,7 @@ export function createReadableByteStream( cancelAlgorithm: rs.CancelAlgorithm, highWaterMark?: number, autoAllocateChunkSize?: number -) { +): SDReadableStream { if (highWaterMark === undefined) { highWaterMark = 0; } @@ -274,7 +273,7 @@ export function createReadableByteStream( export function readableStreamTee( stream: SDReadableStream, cloneForBranch2: boolean -) { +): [SDReadableStream, SDReadableStream] { if (!rs.isReadableStream(stream)) { throw new TypeError(); } @@ -291,7 +290,7 @@ export function readableStreamTee( let cancelResolve: (reason: shared.ErrorResult) => void; const cancelPromise = new Promise(resolve => (cancelResolve = resolve)); - const pullAlgorithm = () => { + const pullAlgorithm = (): Promise => { return rs .readableStreamDefaultReaderRead(reader) .then(({ value, done }) => { @@ -335,7 +334,7 @@ export function readableStreamTee( }); }; - const cancel1Algorithm = (reason: shared.ErrorResult) => { + const cancel1Algorithm = (reason: shared.ErrorResult): Promise => { canceled1 = true; reason1 = reason; if (canceled2) { @@ -345,7 +344,7 @@ export function readableStreamTee( return cancelPromise; }; - const cancel2Algorithm = (reason: shared.ErrorResult) => { + const cancel2Algorithm = (reason: shared.ErrorResult): Promise => { canceled2 = true; reason2 = reason; if (canceled1) { @@ -355,7 +354,7 @@ export function readableStreamTee( return cancelPromise; }; - const startAlgorithm = () => undefined; + const startAlgorithm = (): undefined => undefined; branch1 = createReadableStream( startAlgorithm, pullAlgorithm, diff --git a/cli/js/streams/shared-internals.ts b/cli/js/streams/shared-internals.ts index 3442e5323dfe80..90e66e59173148 100644 --- a/cli/js/streams/shared-internals.ts +++ b/cli/js/streams/shared-internals.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO don't disable this warning + import { AbortSignal, QueuingStrategySizeCallback } from "../dom_types.ts"; import { DenoError, ErrorKind } from "../errors.ts"; @@ -23,7 +26,7 @@ export type ErrorResult = any; // --------- -export function isInteger(value: number) { +export function isInteger(value: number): boolean { if (!isFinite(value)) { // covers NaN, +Infinity and -Infinity return false; @@ -32,7 +35,7 @@ export function isInteger(value: number) { return Math.floor(absValue) === absValue; } -export function isFiniteNonNegativeNumber(value: unknown) { +export function isFiniteNonNegativeNumber(value: unknown): boolean { if (!(typeof value === "number" && isFinite(value))) { // covers NaN, +Infinity and -Infinity return false; @@ -59,7 +62,7 @@ export function invokeOrNoop( o: O, p: P, args: any[] -) { +): any { // Assert: O is not undefined. // Assert: IsPropertyKey(P) is true. // Assert: args is a List. @@ -83,7 +86,7 @@ export function cloneArrayBuffer( ) as InstanceType; } -export function transferArrayBuffer(buffer: ArrayBufferLike) { +export function transferArrayBuffer(buffer: ArrayBufferLike): ArrayBuffer { // This would in a JS engine context detach the buffer's backing store and return // a new ArrayBuffer with the same backing store, invalidating `buffer`, // i.e. a move operation in C++ parlance. @@ -97,7 +100,7 @@ export function copyDataBlockBytes( fromBlock: ArrayBufferLike, fromIndex: number, count: number -) { +): void { new Uint8Array(toBlock, toIndex, count).set( new Uint8Array(fromBlock, fromIndex, count) ); @@ -216,7 +219,7 @@ export function promiseCall( f: F, v: object | undefined, args: any[] -) { +): Promise { // tslint:disable-line:ban-types try { const result = Function.prototype.apply.call(f, v, args); @@ -229,15 +232,15 @@ export function promiseCall( export function createAlgorithmFromUnderlyingMethod< O extends object, K extends keyof O ->(obj: O, methodName: K, extraArgs: any[]) { +>(obj: O, methodName: K, extraArgs: any[]): any { const method = obj[methodName]; if (method === undefined) { - return () => Promise.resolve(undefined); + return (): any => Promise.resolve(undefined); } if (typeof method !== "function") { throw new TypeError(`Field "${methodName}" is not a function.`); } - return function(...fnArgs: any[]) { + return function(...fnArgs: any[]): any { return promiseCall(method, obj, fnArgs.concat(extraArgs)); }; } @@ -250,7 +253,7 @@ function createIterResultObject(value: T, done: boolean): IteratorResult { } */ -export function validateAndNormalizeHighWaterMark(hwm: unknown) { +export function validateAndNormalizeHighWaterMark(hwm: unknown): number { const highWaterMark = Number(hwm); if (isNaN(highWaterMark) || highWaterMark < 0) { throw new RangeError( @@ -266,7 +269,7 @@ export function makeSizeAlgorithmFromSizeFunction( if (typeof sizeFn !== "function" && typeof sizeFn !== "undefined") { throw new TypeError("size function must be undefined or a function"); } - return function(chunk: T) { + return function(chunk: T): number { if (typeof sizeFn === "function") { return sizeFn(chunk); } @@ -294,11 +297,11 @@ export function createControlledPromise(): ControlledPromise { state: ControlledPromiseState.Pending } as ControlledPromise; conProm.promise = new Promise(function(resolve, reject) { - conProm.resolve = function(v?: V) { + conProm.resolve = function(v?: V): void { conProm.state = ControlledPromiseState.Resolved; resolve(v); }; - conProm.reject = function(e?: ErrorResult) { + conProm.reject = function(e?: ErrorResult): void { conProm.state = ControlledPromiseState.Rejected; reject(e); }; diff --git a/cli/js/streams/strategies.ts b/cli/js/streams/strategies.ts index 84c09d84583a1e..5f7ffc6324f512 100644 --- a/cli/js/streams/strategies.ts +++ b/cli/js/streams/strategies.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import { QueuingStrategy } from "../dom_types.ts"; export class ByteLengthQueuingStrategy @@ -18,7 +21,7 @@ export class ByteLengthQueuingStrategy this.highWaterMark = options.highWaterMark; } - size(chunk: ArrayBufferView) { + size(chunk: ArrayBufferView): number { return chunk.byteLength; } } @@ -30,7 +33,7 @@ export class CountQueuingStrategy implements QueuingStrategy { this.highWaterMark = options.highWaterMark; } - size() { + size(): number { return 1; } } diff --git a/cli/js/streams/transform-internals.ts b/cli/js/streams/transform-internals.ts index dd481dc8bd65e6..e659a4965bbb7f 100644 --- a/cli/js/streams/transform-internals.ts +++ b/cli/js/streams/transform-internals.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as rs from "./readable-internals.ts"; import * as ws from "./writable-internals.ts"; import * as shared from "./shared-internals.ts"; @@ -102,17 +105,17 @@ export function initializeTransformStream( writableSizeAlgorithm: QueuingStrategySizeCallback, readableHighWaterMark: number, readableSizeAlgorithm: QueuingStrategySizeCallback -) { - const startAlgorithm = function() { +): void { + const startAlgorithm = function(): Promise { return startPromise; }; - const writeAlgorithm = function(chunk: InputType) { + const writeAlgorithm = function(chunk: InputType): Promise { return transformStreamDefaultSinkWriteAlgorithm(stream, chunk); }; - const abortAlgorithm = function(reason: shared.ErrorResult) { + const abortAlgorithm = function(reason: shared.ErrorResult): Promise { return transformStreamDefaultSinkAbortAlgorithm(stream, reason); }; - const closeAlgorithm = function() { + const closeAlgorithm = function(): Promise { return transformStreamDefaultSinkCloseAlgorithm(stream); }; stream[writable_] = createWritableStream( @@ -124,10 +127,12 @@ export function initializeTransformStream( writableSizeAlgorithm ); - const pullAlgorithm = function() { + const pullAlgorithm = function(): Promise { return transformStreamDefaultSourcePullAlgorithm(stream); }; - const cancelAlgorithm = function(reason: shared.ErrorResult) { + const cancelAlgorithm = function( + reason: shared.ErrorResult + ): Promise { transformStreamErrorWritableAndUnblockWrite(stream, reason); return Promise.resolve(undefined); }; @@ -148,7 +153,7 @@ export function initializeTransformStream( export function transformStreamError( stream: TransformStream, error: shared.ErrorResult -) { +): void { rs.readableStreamDefaultControllerError( stream[readable_][ rs.readableStreamController_ @@ -161,7 +166,10 @@ export function transformStreamError( export function transformStreamErrorWritableAndUnblockWrite< InputType, OutputType ->(stream: TransformStream, error: shared.ErrorResult) { +>( + stream: TransformStream, + error: shared.ErrorResult +): void { transformStreamDefaultControllerClearAlgorithms( stream[transformStreamController_] ); @@ -177,7 +185,7 @@ export function transformStreamErrorWritableAndUnblockWrite< export function transformStreamSetBackpressure( stream: TransformStream, backpressure: boolean -) { +): void { // Assert: stream.[[backpressure]] is not backpressure. if (stream[backpressure_] !== undefined) { stream[backpressureChangePromise_]!.resolve(undefined); @@ -202,7 +210,7 @@ export function setUpTransformStreamDefaultController( controller: TransformStreamDefaultController, transformAlgorithm: TransformAlgorithm, flushAlgorithm: FlushAlgorithm -) { +): void { // Assert: ! IsTransformStream(stream) is true. // Assert: stream.[[transformStreamController]] is undefined. controller[controlledTransformStream_] = stream; @@ -214,7 +222,7 @@ export function setUpTransformStreamDefaultController( export function transformStreamDefaultControllerClearAlgorithms< InputType, OutputType ->(controller: TransformStreamDefaultController) { +>(controller: TransformStreamDefaultController): void { // Use ! assertions to override type check here, this way we don't // have to perform type checks/assertions everywhere else. controller[transformAlgorithm_] = undefined!; @@ -224,7 +232,7 @@ export function transformStreamDefaultControllerClearAlgorithms< export function transformStreamDefaultControllerEnqueue( controller: TransformStreamDefaultController, chunk: OutputType -) { +): void { const stream = controller[controlledTransformStream_]; const readableController = stream[readable_][ rs.readableStreamController_ @@ -252,7 +260,7 @@ export function transformStreamDefaultControllerEnqueue( export function transformStreamDefaultControllerError( controller: TransformStreamDefaultController, error: shared.ErrorResult -) { +): void { transformStreamError(controller[controlledTransformStream_], error); } @@ -262,7 +270,7 @@ export function transformStreamDefaultControllerPerformTransform< >( controller: TransformStreamDefaultController, chunk: InputType -) { +): Promise { const transformPromise = controller[transformAlgorithm_](chunk); return transformPromise.catch(error => { transformStreamError(controller[controlledTransformStream_], error); @@ -273,7 +281,7 @@ export function transformStreamDefaultControllerPerformTransform< export function transformStreamDefaultControllerTerminate< InputType, OutputType ->(controller: TransformStreamDefaultController) { +>(controller: TransformStreamDefaultController): void { const stream = controller[controlledTransformStream_]; const readableController = stream[readable_][ rs.readableStreamController_ @@ -290,7 +298,7 @@ export function transformStreamDefaultControllerTerminate< export function transformStreamDefaultSinkWriteAlgorithm( stream: TransformStream, chunk: InputType -) { +): Promise { // Assert: stream.[[writable]].[[state]] is "writable". const controller = stream[transformStreamController_]; if (stream[backpressure_]) { @@ -315,14 +323,14 @@ export function transformStreamDefaultSinkWriteAlgorithm( export function transformStreamDefaultSinkAbortAlgorithm( stream: TransformStream, reason: shared.ErrorResult -) { +): Promise { transformStreamError(stream, reason); return Promise.resolve(undefined); } export function transformStreamDefaultSinkCloseAlgorithm( stream: TransformStream -) { +): Promise { const readable = stream[readable_]; const controller = stream[transformStreamController_]; const flushPromise = controller[flushAlgorithm_](); @@ -354,7 +362,7 @@ export function transformStreamDefaultSinkCloseAlgorithm( export function transformStreamDefaultSourcePullAlgorithm< InputType, OutputType ->(stream: TransformStream) { +>(stream: TransformStream): Promise { // Assert: stream.[[backpressure]] is true. // Assert: stream.[[backpressureChangePromise]] is not undefined. transformStreamSetBackpressure(stream, false); diff --git a/cli/js/streams/transform-stream.ts b/cli/js/streams/transform-stream.ts index 73ebaf50dddf46..dfd241e143abed 100644 --- a/cli/js/streams/transform-stream.ts +++ b/cli/js/streams/transform-stream.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as rs from "./readable-internals.ts"; import * as ws from "./writable-internals.ts"; import * as ts from "./transform-internals.ts"; @@ -99,7 +102,7 @@ function setUpTransformStreamDefaultControllerFromTransformer< >( stream: TransformStream, transformer: ts.Transformer -) { +): void { const controller = Object.create( TransformStreamDefaultController.prototype ) as TransformStreamDefaultController; @@ -112,11 +115,11 @@ function setUpTransformStreamDefaultControllerFromTransformer< "`transform` field of the transformer must be a function" ); } - transformAlgorithm = (chunk: InputType) => + transformAlgorithm = (chunk: InputType): Promise => shared.promiseCall(transformMethod, transformer, [chunk, controller]); } else { // use identity transform - transformAlgorithm = function(chunk: InputType) { + transformAlgorithm = function(chunk: InputType): Promise { try { // OutputType and InputType are the same here ts.transformStreamDefaultControllerEnqueue( diff --git a/cli/js/streams/writable-internals.ts b/cli/js/streams/writable-internals.ts index e796a9d16be928..df0f7a0b8e3b33 100644 --- a/cli/js/streams/writable-internals.ts +++ b/cli/js/streams/writable-internals.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as shared from "./shared-internals.ts"; import * as q from "./queue-mixin.ts"; @@ -147,7 +150,7 @@ export declare class WritableStream { export function initializeWritableStream( stream: WritableStream -) { +): void { stream[shared.state_] = "writable"; stream[shared.storedError_] = undefined; stream[writer_] = undefined; @@ -169,14 +172,14 @@ export function isWritableStream(value: unknown): value is WritableStream { export function isWritableStreamLocked( stream: WritableStream -) { +): boolean { return stream[writer_] !== undefined; } export function writableStreamAbort( stream: WritableStream, reason: shared.ErrorResult -) { +): Promise { const state = stream[shared.state_]; if (state === "closed" || state === "errored") { return Promise.resolve(undefined); @@ -210,7 +213,7 @@ export function writableStreamAbort( export function writableStreamAddWriteRequest( stream: WritableStream -) { +): Promise { // Assert: !IsWritableStreamLocked(stream) is true. // Assert: stream.[[state]] is "writable". const writePromise = shared.createControlledPromise(); @@ -221,7 +224,7 @@ export function writableStreamAddWriteRequest( export function writableStreamDealWithRejection( stream: WritableStream, error: shared.ErrorResult -) { +): void { const state = stream[shared.state_]; if (state === "writable") { writableStreamStartErroring(stream, error); @@ -234,7 +237,7 @@ export function writableStreamDealWithRejection( export function writableStreamStartErroring( stream: WritableStream, reason: shared.ErrorResult -) { +): void { // Assert: stream.[[storedError]] is undefined. // Assert: stream.[[state]] is "writable". const controller = stream[writableStreamController_]!; @@ -255,7 +258,7 @@ export function writableStreamStartErroring( export function writableStreamFinishErroring( stream: WritableStream -) { +): void { // Assert: stream.[[state]] is "erroring". // Assert: writableStreamHasOperationMarkedInFlight(stream) is false. stream[shared.state_] = "errored"; @@ -293,7 +296,7 @@ export function writableStreamFinishErroring( export function writableStreamFinishInFlightWrite( stream: WritableStream -) { +): void { // Assert: stream.[[inFlightWriteRequest]] is not undefined. stream[inFlightWriteRequest_]!.resolve(undefined); stream[inFlightWriteRequest_] = undefined; @@ -302,7 +305,7 @@ export function writableStreamFinishInFlightWrite( export function writableStreamFinishInFlightWriteWithError( stream: WritableStream, error: shared.ErrorResult -) { +): void { // Assert: stream.[[inFlightWriteRequest]] is not undefined. stream[inFlightWriteRequest_]!.reject(error); stream[inFlightWriteRequest_] = undefined; @@ -312,7 +315,7 @@ export function writableStreamFinishInFlightWriteWithError( export function writableStreamFinishInFlightClose( stream: WritableStream -) { +): void { // Assert: stream.[[inFlightCloseRequest]] is not undefined. stream[inFlightCloseRequest_]!.resolve(undefined); stream[inFlightCloseRequest_] = undefined; @@ -337,7 +340,7 @@ export function writableStreamFinishInFlightClose( export function writableStreamFinishInFlightCloseWithError( stream: WritableStream, error: shared.ErrorResult -) { +): void { // Assert: stream.[[inFlightCloseRequest]] is not undefined. stream[inFlightCloseRequest_]!.reject(error); stream[inFlightCloseRequest_] = undefined; @@ -351,7 +354,7 @@ export function writableStreamFinishInFlightCloseWithError( export function writableStreamCloseQueuedOrInFlight( stream: WritableStream -) { +): boolean { return ( stream[closeRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined @@ -360,7 +363,7 @@ export function writableStreamCloseQueuedOrInFlight( export function writableStreamHasOperationMarkedInFlight( stream: WritableStream -) { +): boolean { return ( stream[inFlightWriteRequest_] !== undefined || stream[inFlightCloseRequest_] !== undefined @@ -369,7 +372,7 @@ export function writableStreamHasOperationMarkedInFlight( export function writableStreamMarkCloseRequestInFlight( stream: WritableStream -) { +): void { // Assert: stream.[[inFlightCloseRequest]] is undefined. // Assert: stream.[[closeRequest]] is not undefined. stream[inFlightCloseRequest_] = stream[closeRequest_]; @@ -378,7 +381,7 @@ export function writableStreamMarkCloseRequestInFlight( export function writableStreamMarkFirstWriteRequestInFlight( stream: WritableStream -) { +): void { // Assert: stream.[[inFlightWriteRequest]] is undefined. // Assert: stream.[[writeRequests]] is not empty. const writeRequest = stream[writeRequests_].shift()!; @@ -387,7 +390,7 @@ export function writableStreamMarkFirstWriteRequestInFlight( export function writableStreamRejectCloseAndClosedPromiseIfNeeded( stream: WritableStream -) { +): void { // Assert: stream.[[state]] is "errored". const closeRequest = stream[closeRequest_]; if (closeRequest !== undefined) { @@ -405,7 +408,7 @@ export function writableStreamRejectCloseAndClosedPromiseIfNeeded( export function writableStreamUpdateBackpressure( stream: WritableStream, backpressure: boolean -) { +): void { // Assert: stream.[[state]] is "writable". // Assert: !WritableStreamCloseQueuedOrInFlight(stream) is false. const writer = stream[writer_]; @@ -433,7 +436,7 @@ export function isWritableStreamDefaultWriter( export function writableStreamDefaultWriterAbort( writer: WritableStreamDefaultWriter, reason: shared.ErrorResult -) { +): Promise { const stream = writer[ownerWritableStream_]!; // Assert: stream is not undefined. return writableStreamAbort(stream, reason); @@ -441,7 +444,7 @@ export function writableStreamDefaultWriterAbort( export function writableStreamDefaultWriterClose( writer: WritableStreamDefaultWriter -) { +): Promise { const stream = writer[ownerWritableStream_]!; // Assert: stream is not undefined. const state = stream[shared.state_]; @@ -463,7 +466,7 @@ export function writableStreamDefaultWriterClose( export function writableStreamDefaultWriterCloseWithErrorPropagation( writer: WritableStreamDefaultWriter -) { +): Promise { const stream = writer[ownerWritableStream_]!; // Assert: stream is not undefined. const state = stream[shared.state_]; @@ -479,7 +482,10 @@ export function writableStreamDefaultWriterCloseWithErrorPropagation( export function writableStreamDefaultWriterEnsureClosedPromiseRejected< InputType ->(writer: WritableStreamDefaultWriter, error: shared.ErrorResult) { +>( + writer: WritableStreamDefaultWriter, + error: shared.ErrorResult +): void { const closedPromise = writer[closedPromise_]; if (closedPromise.state === shared.ControlledPromiseState.Pending) { closedPromise.reject(error); @@ -492,7 +498,10 @@ export function writableStreamDefaultWriterEnsureClosedPromiseRejected< export function writableStreamDefaultWriterEnsureReadyPromiseRejected< InputType ->(writer: WritableStreamDefaultWriter, error: shared.ErrorResult) { +>( + writer: WritableStreamDefaultWriter, + error: shared.ErrorResult +): void { const readyPromise = writer[readyPromise_]; if (readyPromise.state === shared.ControlledPromiseState.Pending) { readyPromise.reject(error); @@ -505,7 +514,7 @@ export function writableStreamDefaultWriterEnsureReadyPromiseRejected< export function writableStreamDefaultWriterGetDesiredSize( writer: WritableStreamDefaultWriter -) { +): number | null { const stream = writer[ownerWritableStream_]!; const state = stream[shared.state_]; if (state === "errored" || state === "erroring") { @@ -521,7 +530,7 @@ export function writableStreamDefaultWriterGetDesiredSize( export function writableStreamDefaultWriterRelease( writer: WritableStreamDefaultWriter -) { +): void { const stream = writer[ownerWritableStream_]!; // Assert: stream is not undefined. // Assert: stream.[[writer]] is writer. @@ -535,7 +544,7 @@ export function writableStreamDefaultWriterRelease( export function writableStreamDefaultWriterWrite( writer: WritableStreamDefaultWriter, chunk: InputType -) { +): Promise { const stream = writer[ownerWritableStream_]!; // Assert: stream is not undefined. const controller = stream[writableStreamController_]!; @@ -575,7 +584,7 @@ export function setUpWritableStreamDefaultController( abortAlgorithm: AbortAlgorithm, highWaterMark: number, sizeAlgorithm: QueuingStrategySizeCallback -) { +): void { if (!isWritableStream(stream)) { throw new TypeError(); } @@ -623,7 +632,7 @@ export function isWritableStreamDefaultController( export function writableStreamDefaultControllerClearAlgorithms( controller: WritableStreamDefaultController -) { +): void { // Use ! assertions to override type check here, this way we don't // have to perform type checks/assertions everywhere else. controller[writeAlgorithm_] = undefined!; @@ -634,7 +643,7 @@ export function writableStreamDefaultControllerClearAlgorithms( export function writableStreamDefaultControllerClose( controller: WritableStreamDefaultController -) { +): void { q.enqueueValueWithSize(controller, "close", 0); writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); } @@ -642,7 +651,7 @@ export function writableStreamDefaultControllerClose( export function writableStreamDefaultControllerGetChunkSize( controller: WritableStreamDefaultController, chunk: InputType -) { +): number { let chunkSize: number; try { chunkSize = controller[strategySizeAlgorithm_](chunk); @@ -655,7 +664,7 @@ export function writableStreamDefaultControllerGetChunkSize( export function writableStreamDefaultControllerGetDesiredSize( controller: WritableStreamDefaultController -) { +): number { return controller[strategyHWM_] - controller[q.queueTotalSize_]; } @@ -663,7 +672,7 @@ export function writableStreamDefaultControllerWrite( controller: WritableStreamDefaultController, chunk: InputType, chunkSize: number -) { +): void { try { q.enqueueValueWithSize(controller, { chunk }, chunkSize); } catch (error) { @@ -685,7 +694,7 @@ export function writableStreamDefaultControllerWrite( export function writableStreamDefaultControllerAdvanceQueueIfNeeded( controller: WritableStreamDefaultController -) { +): void { if (!controller[started_]) { return; } @@ -715,7 +724,7 @@ export function writableStreamDefaultControllerAdvanceQueueIfNeeded( export function writableStreamDefaultControllerErrorIfNeeded( controller: WritableStreamDefaultController, error: shared.ErrorResult -) { +): void { if (controller[controlledWritableStream_][shared.state_] === "writable") { writableStreamDefaultControllerError(controller, error); } @@ -723,7 +732,7 @@ export function writableStreamDefaultControllerErrorIfNeeded( export function writableStreamDefaultControllerProcessClose( controller: WritableStreamDefaultController -) { +): void { const stream = controller[controlledWritableStream_]; writableStreamMarkCloseRequestInFlight(stream); q.dequeueValue(controller); @@ -743,7 +752,7 @@ export function writableStreamDefaultControllerProcessClose( export function writableStreamDefaultControllerProcessWrite( controller: WritableStreamDefaultController, chunk: InputType -) { +): void { const stream = controller[controlledWritableStream_]; writableStreamMarkFirstWriteRequestInFlight(stream); controller[writeAlgorithm_](chunk).then( @@ -774,7 +783,7 @@ export function writableStreamDefaultControllerProcessWrite( export function writableStreamDefaultControllerGetBackpressure( controller: WritableStreamDefaultController -) { +): boolean { const desiredSize = writableStreamDefaultControllerGetDesiredSize(controller); return desiredSize <= 0; } @@ -782,7 +791,7 @@ export function writableStreamDefaultControllerGetBackpressure( export function writableStreamDefaultControllerError( controller: WritableStreamDefaultController, error: shared.ErrorResult -) { +): void { const stream = controller[controlledWritableStream_]; // Assert: stream.[[state]] is "writable". writableStreamDefaultControllerClearAlgorithms(controller); diff --git a/cli/js/streams/writable-stream-default-controller.ts b/cli/js/streams/writable-stream-default-controller.ts index c2f065bc0b1232..9a3886d21c9e7b 100644 --- a/cli/js/streams/writable-stream-default-controller.ts +++ b/cli/js/streams/writable-stream-default-controller.ts @@ -8,6 +8,9 @@ * https://github.com/stardazed/sd-streams */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +// TODO reenable this lint here + import * as ws from "./writable-internals.ts"; import * as shared from "./shared-internals.ts"; import * as q from "./queue-mixin.ts"; @@ -31,7 +34,7 @@ export class WritableStreamDefaultController throw new TypeError(); } - error(e?: shared.ErrorResult) { + error(e?: shared.ErrorResult): void { if (!ws.isWritableStreamDefaultController(this)) { throw new TypeError(); } @@ -42,13 +45,13 @@ export class WritableStreamDefaultController ws.writableStreamDefaultControllerError(this, e); } - [ws.abortSteps_](reason: shared.ErrorResult) { + [ws.abortSteps_](reason: shared.ErrorResult): Promise { const result = this[ws.abortAlgorithm_](reason); ws.writableStreamDefaultControllerClearAlgorithms(this); return result; } - [ws.errorSteps_]() { + [ws.errorSteps_](): void { q.resetQueue(this); } } @@ -60,13 +63,13 @@ export function setUpWritableStreamDefaultControllerFromUnderlyingSink< underlyingSink: ws.WritableStreamSink, highWaterMark: number, sizeAlgorithm: QueuingStrategySizeCallback -) { +): void { // Assert: underlyingSink is not undefined. const controller = Object.create( WritableStreamDefaultController.prototype ) as WritableStreamDefaultController; - const startAlgorithm = function() { + const startAlgorithm = function(): any { return shared.invokeOrNoop(underlyingSink, "start", [controller]); }; const writeAlgorithm = shared.createAlgorithmFromUnderlyingMethod( diff --git a/cli/js/streams/writable-stream.ts b/cli/js/streams/writable-stream.ts index 42de9b9681311f..b6e4dd4ad1c34e 100644 --- a/cli/js/streams/writable-stream.ts +++ b/cli/js/streams/writable-stream.ts @@ -87,12 +87,12 @@ export function createWritableStream( abortAlgorithm: ws.AbortAlgorithm, highWaterMark?: number, sizeAlgorithm?: QueuingStrategySizeCallback -) { +): WritableStream { if (highWaterMark === undefined) { highWaterMark = 1; } if (sizeAlgorithm === undefined) { - sizeAlgorithm = () => 1; + sizeAlgorithm = (): number => 1; } // Assert: ! IsNonNegativeNumber(highWaterMark) is true. diff --git a/core/modules.rs b/core/modules.rs index 6f71537a681462..85de79cca59de3 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1021,7 +1021,7 @@ mod tests { let result = recursive_load.poll(); assert!(result.is_ok()); assert!(result.ok().unwrap().is_not_ready()); - let l = loads.lock().unwrap();; + let l = loads.lock().unwrap(); assert_eq!( l.to_vec(), vec![