Skip to content

Commit

Permalink
Migrate from tslint to eslint for linting (denoland#1905)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk authored and ry committed Mar 9, 2019
1 parent 8c7a12d commit 034e2cc
Show file tree
Hide file tree
Showing 90 changed files with 1,037 additions and 1,100 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/js/deps/
/js/gen/
/tests/error_syntax.js
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
"rules": {
"@typescript-eslint/array-type": ["error", "array-simple"],
"@typescript-eslint/explicit-member-accessibility": ["off"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"@typescript-eslint/no-parameter-properties": ["off"],
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
]
}
}
34 changes: 17 additions & 17 deletions core/http_bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ function createResolvable() {
return Object.assign(promise, methods);
}

function setRecord(i, off, value) {
if (i >= NUM_RECORDS) {
throw Error("out of range");
}
shared32[INDEX_RECORDS + RECORD_SIZE * i + off] = value;
}

function getRecord(i, off) {
if (i >= NUM_RECORDS) {
throw Error("out of range");
}
return shared32[INDEX_RECORDS + RECORD_SIZE * i + off];
}

/** Returns Promise<number> */
function sendAsync(op, arg, zeroCopyData) {
const id = nextPromiseId++;
Expand All @@ -64,20 +78,6 @@ function sendSync(op, arg) {
return getRecord(0, RECORD_OFFSET_RESULT);
}

function setRecord(i, off, value) {
if (i >= NUM_RECORDS) {
throw Error("out of range");
}
shared32[INDEX_RECORDS + RECORD_SIZE * i + off] = value;
}

function getRecord(i, off) {
if (i >= NUM_RECORDS) {
throw Error("out of range");
}
return shared32[INDEX_RECORDS + RECORD_SIZE * i + off];
}

function handleAsyncMsgFromRust() {
for (let i = 0; i < shared32[INDEX_NUM_RECORDS]; i++) {
let id = getRecord(i, RECORD_OFFSET_PROMISE_ID);
Expand Down Expand Up @@ -134,10 +134,10 @@ async function main() {

libdeno.print("http_bench.js start");

const listener_rid = listen();
libdeno.print(`listening http:https://127.0.0.1:4544/ rid = ${listener_rid}`);
const listenerRid = listen();
libdeno.print(`listening http:https://127.0.0.1:4544/ rid = ${listenerRid}`);
while (true) {
const rid = await accept(listener_rid);
const rid = await accept(listenerRid);
// libdeno.print(`accepted ${rid}`);
if (rid < 0) {
libdeno.print(`accept error ${rid}`);
Expand Down
4 changes: 1 addition & 3 deletions js/assets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

// tslint:disable-next-line:no-reference
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
/// <reference path="./plugins.d.ts" />

// There is a rollup plugin that will inline any module ending with `!string`
// tslint:disable:max-line-length

// Generated default library
import libDts from "gen/lib/lib.deno_runtime.d.ts!string";
Expand Down Expand Up @@ -39,7 +38,6 @@ import libEsnextBigintDts from "/third_party/node_modules/typescript/lib/lib.esn
import libEsnextDts from "/third_party/node_modules/typescript/lib/lib.esnext.d.ts!string";
import libEsnextIntlDts from "/third_party/node_modules/typescript/lib/lib.esnext.intl.d.ts!string";
import libEsnextSymbolDts from "/third_party/node_modules/typescript/lib/lib.esnext.symbol.d.ts!string";
// tslint:enable:max-line-length

// @internal
export const assetSourceCode: { [key: string]: string } = {
Expand Down
137 changes: 69 additions & 68 deletions js/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,75 @@ import { TextEncoder } from "./text_encoding";

export const bytesSymbol = Symbol("bytes");

function convertLineEndingsToNative(s: string): string {
// TODO(qti3e) Implement convertLineEndingsToNative.
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native
return s;
}

function toUint8Arrays(
blobParts: domTypes.BlobPart[],
doNormalizeLineEndingsToNative: boolean
): Uint8Array[] {
const ret: Uint8Array[] = [];
const enc = new TextEncoder();
for (const element of blobParts) {
if (typeof element === "string") {
let str = element;
if (doNormalizeLineEndingsToNative) {
str = convertLineEndingsToNative(element);
}
ret.push(enc.encode(str));
// eslint-disable-next-line @typescript-eslint/no-use-before-define
} else if (element instanceof DenoBlob) {
ret.push(element[bytesSymbol]);
} else if (element instanceof Uint8Array) {
ret.push(element);
} else if (element instanceof Uint16Array) {
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (element instanceof Uint32Array) {
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (ArrayBuffer.isView(element)) {
// Convert view to Uint8Array.
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (element instanceof ArrayBuffer) {
// Create a new Uint8Array view for the given ArrayBuffer.
const uint8 = new Uint8Array(element);
ret.push(uint8);
} else {
ret.push(enc.encode(String(element)));
}
}
return ret;
}

function processBlobParts(
blobParts: domTypes.BlobPart[],
options: domTypes.BlobPropertyBag
): Uint8Array {
const normalizeLineEndingsToNative = options.ending === "native";
// ArrayBuffer.transfer is not yet implemented in V8, so we just have to
// pre compute size of the array buffer and do some sort of static allocation
// instead of dynamic allocation.
const uint8Arrays = toUint8Arrays(blobParts, normalizeLineEndingsToNative);
const byteLength = uint8Arrays
.map(u8 => u8.byteLength)
.reduce((a, b) => a + b, 0);
const ab = new ArrayBuffer(byteLength);
const bytes = new Uint8Array(ab);

let courser = 0;
for (const u8 of uint8Arrays) {
bytes.set(u8, courser);
courser += u8.byteLength;
}

return bytes;
}

export class DenoBlob implements domTypes.Blob {
private readonly [bytesSymbol]: Uint8Array;
readonly size: number = 0;
Expand Down Expand Up @@ -56,71 +125,3 @@ export class DenoBlob implements domTypes.Blob {
});
}
}

function processBlobParts(
blobParts: domTypes.BlobPart[],
options: domTypes.BlobPropertyBag
): Uint8Array {
const normalizeLineEndingsToNative = options.ending === "native";
// ArrayBuffer.transfer is not yet implemented in V8, so we just have to
// pre compute size of the array buffer and do some sort of static allocation
// instead of dynamic allocation.
const uint8Arrays = toUint8Arrays(blobParts, normalizeLineEndingsToNative);
const byteLength = uint8Arrays
.map(u8 => u8.byteLength)
.reduce((a, b) => a + b, 0);
const ab = new ArrayBuffer(byteLength);
const bytes = new Uint8Array(ab);

let courser = 0;
for (const u8 of uint8Arrays) {
bytes.set(u8, courser);
courser += u8.byteLength;
}

return bytes;
}

function toUint8Arrays(
blobParts: domTypes.BlobPart[],
doNormalizeLineEndingsToNative: boolean
): Uint8Array[] {
const ret: Uint8Array[] = [];
const enc = new TextEncoder();
for (const element of blobParts) {
if (typeof element === "string") {
let str = element;
if (doNormalizeLineEndingsToNative) {
str = convertLineEndingsToNative(element);
}
ret.push(enc.encode(str));
} else if (element instanceof DenoBlob) {
ret.push(element[bytesSymbol]);
} else if (element instanceof Uint8Array) {
ret.push(element);
} else if (element instanceof Uint16Array) {
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (element instanceof Uint32Array) {
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (ArrayBuffer.isView(element)) {
// Convert view to Uint8Array.
const uint8 = new Uint8Array(element.buffer);
ret.push(uint8);
} else if (element instanceof ArrayBuffer) {
// Create a new Uint8Array view for the given ArrayBuffer.
const uint8 = new Uint8Array(element);
ret.push(uint8);
} else {
ret.push(enc.encode(String(element)));
}
}
return ret;
}

function convertLineEndingsToNative(s: string): string {
// TODO(qti3e) Implement convertLineEndingsToNative.
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native
return s;
}
4 changes: 2 additions & 2 deletions js/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export class Buffer implements Reader, Writer {
}

/** empty() returns whether the unread portion of the buffer is empty. */
empty() {
empty(): boolean {
return this.buf.byteLength <= this.off;
}

/** length is a getter that returns the number of bytes of the unread
* portion of the buffer
*/
get length() {
get length(): number {
return this.buf.byteLength - this.off;
}

Expand Down
22 changes: 11 additions & 11 deletions js/buffer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const N = 100;
let testBytes: Uint8Array | null;
let testString: string | null;

function init() {
function init(): void {
if (testBytes == null) {
testBytes = new Uint8Array(N);
for (let i = 0; i < N; i++) {
Expand All @@ -24,7 +24,7 @@ function init() {
}
}

function check(buf: Deno.Buffer, s: string) {
function check(buf: Deno.Buffer, s: string): void {
const bytes = buf.bytes();
assertEquals(buf.length, bytes.byteLength);
const decoder = new TextDecoder();
Expand Down Expand Up @@ -69,6 +69,13 @@ async function empty(buf: Buffer, s: string, fub: Uint8Array): Promise<void> {
check(buf, "");
}

function repeat(c: string, bytes: number): Uint8Array {
assertEquals(c.length, 1);
const ui8 = new Uint8Array(bytes);
ui8.fill(c.charCodeAt(0));
return ui8;
}

test(function bufferNewBuffer() {
init();
const buf = new Buffer(testBytes.buffer as ArrayBuffer);
Expand Down Expand Up @@ -140,7 +147,7 @@ test(async function bufferTooLargeByteWrites() {
const growLen = Number.MAX_VALUE;
const xBytes = repeat("x", 0);
const buf = new Buffer(xBytes.buffer as ArrayBuffer);
const { nread, eof } = await buf.read(tmp);
await buf.read(tmp);

let err;
try {
Expand Down Expand Up @@ -186,21 +193,14 @@ test(async function bufferReadFrom() {
}
});

function repeat(c: string, bytes: number): Uint8Array {
assertEquals(c.length, 1);
const ui8 = new Uint8Array(bytes);
ui8.fill(c.charCodeAt(0));
return ui8;
}

test(async function bufferTestGrow() {
const tmp = new Uint8Array(72);
for (let startLen of [0, 100, 1000, 10000, 100000]) {
const xBytes = repeat("x", startLen);
for (let growLen of [0, 100, 1000, 10000, 100000]) {
const buf = new Buffer(xBytes.buffer as ArrayBuffer);
// If we read, this affects buf.off, which is good to test.
const { nread, eof } = await buf.read(tmp);
const { nread } = await buf.read(tmp);
buf.grow(growLen);
const yBytes = repeat("y", growLen);
await buf.write(yBytes);
Expand Down
4 changes: 2 additions & 2 deletions js/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export interface BuildInfo {

// 'build' is injected by rollup.config.js at compile time.
export const build: BuildInfo = {
// tslint:disable:no-any
/* eslint-disable @typescript-eslint/no-explicit-any */
// These string will be replaced by rollup
arch: `ROLLUP_REPLACE_ARCH` as any,
os: `ROLLUP_REPLACE_OS` as any,
gnArgs: `ROLLUP_REPLACE_GN_ARGS`
// tslint:disable:any
/* eslint-enable @typescript-eslint/no-explicit-any */
};

// TODO(kevinkassimo): deprecate Deno.platform
Expand Down
26 changes: 13 additions & 13 deletions js/chmod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
import * as dispatch from "./dispatch";

function req(
path: string,
mode: number
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.Chmod.startChmod(builder);
msg.Chmod.addPath(builder, path_);
msg.Chmod.addMode(builder, mode);
const inner = msg.Chmod.endChmod(builder);
return [builder, msg.Any.Chmod, inner];
}

/** Changes the permission of a specific file/directory of specified path
* synchronously.
*
Expand All @@ -19,16 +32,3 @@ export function chmodSync(path: string, mode: number): void {
export async function chmod(path: string, mode: number): Promise<void> {
await dispatch.sendAsync(...req(path, mode));
}

function req(
path: string,
mode: number
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.Chmod.startChmod(builder);
msg.Chmod.addPath(builder, path_);
msg.Chmod.addMode(builder, mode);
const inner = msg.Chmod.endChmod(builder);
return [builder, msg.Any.Chmod, inner];
}
Loading

0 comments on commit 034e2cc

Please sign in to comment.