Skip to content

Commit

Permalink
resolve eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nstott committed Oct 23, 2019
1 parent d195cd4 commit 1cc6eb3
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 177 deletions.
1 change: 0 additions & 1 deletion cli/js/streams/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export {
ByteLengthQueuingStrategy,
CountQueuingStrategy
} from "./strategies.ts";

23 changes: 13 additions & 10 deletions cli/js/streams/pipe-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,7 +29,7 @@ export function pipeTo<ChunkType>(
source: rs.SDReadableStream<ChunkType>,
dest: ws.WritableStream<ChunkType>,
options: PipeOptions
) {
): Promise<void> {
const preventClose = !!options.preventClose;
const preventAbort = !!options.preventAbort;
const preventCancel = !!options.preventCancel;
Expand All @@ -43,7 +46,7 @@ export function pipeTo<ChunkType>(

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");
Expand Down Expand Up @@ -83,7 +86,7 @@ export function pipeTo<ChunkType>(
stream: rs.SDReadableStream<ChunkType> | ws.WritableStream<ChunkType>,
promise: Promise<void>,
action: (error: shared.ErrorResult) => void
) {
): void {
if (stream[shared.state_] === "errored") {
action(stream[shared.storedError_]);
} else {
Expand All @@ -95,7 +98,7 @@ export function pipeTo<ChunkType>(
stream: rs.SDReadableStream<ChunkType> | ws.WritableStream<ChunkType>,
promise: Promise<void>,
action: () => void
) {
): void {
if (stream[shared.state_] === "closed") {
action();
} else {
Expand Down Expand Up @@ -155,7 +158,7 @@ export function pipeTo<ChunkType>(
);
}

function flushRemainder() {
function flushRemainder(): Promise<void> | undefined {
if (
dest[shared.state_] === "writable" &&
!ws.writableStreamCloseQueuedOrInFlight(dest)
Expand All @@ -166,17 +169,17 @@ export function pipeTo<ChunkType>(
}
}

function shutDown(action?: () => Promise<void>, error?: ErrorWrapper) {
function shutDown(action?: () => Promise<void>, error?: ErrorWrapper): void {
if (shuttingDown) {
return;
}
shuttingDown = true;

if (action === undefined) {
action = () => Promise.resolve();
action = (): Promise<void> => Promise.resolve();
}

function finishShutDown() {
function finishShutDown(): void {
action!().then(
_ => finalize(error),
newError => finalize({ actualError: newError })
Expand All @@ -191,7 +194,7 @@ export function pipeTo<ChunkType>(
}
}

function finalize(error?: ErrorWrapper) {
function finalize(error?: ErrorWrapper): void {
ws.writableStreamDefaultWriterRelease(writer);
rs.readableStreamReaderGenericRelease(reader);
if (signal && abortAlgorithm) {
Expand All @@ -204,7 +207,7 @@ export function pipeTo<ChunkType>(
}
}

function next() {
function next(): Promise<void> | undefined {
if (shuttingDown) {
return;
}
Expand Down
11 changes: 7 additions & 4 deletions cli/js/streams/queue-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -33,7 +36,7 @@ export interface ByteQueueContainer {
[queueTotalSize_]: number;
}

export function dequeueValue<V>(container: QueueContainer<V>) {
export function dequeueValue<V>(container: QueueContainer<V>): V {
// Assert: container has[[queue]] and[[queueTotalSize]] internal slots.
// Assert: container.[[queue]] is not empty.
const pair = container[queue_].shift()!;
Expand All @@ -46,7 +49,7 @@ export function enqueueValueWithSize<V>(
container: QueueContainer<V>,
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");
Expand All @@ -55,15 +58,15 @@ export function enqueueValueWithSize<V>(
container[queueTotalSize_] += size;
}

export function peekQueueValue<V>(container: QueueContainer<V>) {
export function peekQueueValue<V>(container: QueueContainer<V>): V {
// Assert: container has[[queue]] and[[queueTotalSize]] internal slots.
// Assert: container.[[queue]] is not empty.
return container[queue_].front()!.value;
}

export function resetQueue<V>(
container: ByteQueueContainer | QueueContainer<V>
) {
): 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
Expand Down
2 changes: 1 addition & 1 deletion cli/js/streams/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class QueueImpl<T> implements Queue<T> {
return t;
}

get length() {
get length(): number {
return this.length_;
}
}
19 changes: 12 additions & 7 deletions cli/js/streams/readable-byte-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -70,7 +73,7 @@ export class ReadableByteStreamController
return rs.readableByteStreamControllerGetDesiredSize(this);
}

close() {
close(): void {
if (!rs.isReadableByteStreamController(this)) {
throw new TypeError();
}
Expand All @@ -83,7 +86,7 @@ export class ReadableByteStreamController
rs.readableByteStreamControllerClose(this);
}

enqueue(chunk: ArrayBufferView) {
enqueue(chunk: ArrayBufferView): void {
if (!rs.isReadableByteStreamController(this)) {
throw new TypeError();
}
Expand All @@ -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<void> {
if (this[rs.pendingPullIntos_].length > 0) {
const firstDescriptor = this[rs.pendingPullIntos_][0];
firstDescriptor.bytesFilled = 0;
Expand All @@ -118,7 +121,9 @@ export class ReadableByteStreamController
return result;
}

[rs.pullSteps_](forAuthorCode: boolean) {
[rs.pullSteps_](
forAuthorCode: boolean
): Promise<IteratorResult<ArrayBufferView, any>> {
const stream = this[rs.controlledReadableByteStream_];
// Assert: ! ReadableStreamHasDefaultReader(stream) is true.
if (this[q.queueTotalSize_] > 0) {
Expand Down Expand Up @@ -165,13 +170,13 @@ export function setUpReadableByteStreamControllerFromUnderlyingSource(
stream: rs.SDReadableStream<ArrayBufferView>,
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(
Expand Down
Loading

0 comments on commit 1cc6eb3

Please sign in to comment.