Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Implement strict mode #453

Merged
merged 29 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6e30522
add TS strict mode to CI
bartlomieju May 25, 2019
9b96923
strict - clean log/
bartlomieju May 25, 2019
742c19e
strict - clean ws/ and testing/
bartlomieju May 25, 2019
d40b031
strict - clean archive/
bartlomieju May 25, 2019
68452b1
strict - clean fs/
bartlomieju May 25, 2019
c4948a5
strict - clean http/
bartlomieju May 25, 2019
1c2c688
strict - clean log/, mime/, prettier/, textproto/
bartlomieju May 25, 2019
2b2ec3a
strict - clean ws/, io/, fs/
bartlomieju May 25, 2019
fa00df0
fix CSV
zekth May 25, 2019
589cfb4
fixing toml
zekth May 25, 2019
681a87c
Merge pull request #1 from zekth/fix_toml_strict
bartlomieju May 25, 2019
ce6b612
more strict fixes
bartlomieju May 26, 2019
c072d6f
rewrite flags module in strict mode
bartlomieju May 26, 2019
3284359
Merge branch 'chore-refactor_flags_strict_mode' into chore-strict_tsc…
bartlomieju May 26, 2019
a8c8aa8
fs module strict
zekth May 26, 2019
d294937
Merge pull request #2 from zekth/strict_contrib
bartlomieju May 26, 2019
6f733a1
strict fix
zekth May 26, 2019
295e6bd
Merge pull request #3 from zekth/strict_another
bartlomieju May 26, 2019
898718f
last part of cleanup
bartlomieju May 26, 2019
e9364c2
fmt
bartlomieju May 26, 2019
eb7a354
Merge branch 'master' into chore-strict_tsconfig
bartlomieju May 26, 2019
2644bf1
lint
bartlomieju May 26, 2019
0429cb1
more fixes for strict mode
bartlomieju May 26, 2019
79cd16a
fix testing/format.ts
bartlomieju May 26, 2019
eef15e6
fix textproto
bartlomieju May 26, 2019
158ae3b
rename deno.tsconfig.json to tsconfig.test.json
bartlomieju May 26, 2019
77a7a90
Merge branch 'master' into chore-strict_tsconfig
bartlomieju May 30, 2019
f8ebcd6
fmt
bartlomieju May 30, 2019
1e36fdb
strict fixes after master merge
bartlomieju May 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
last part of cleanup
  • Loading branch information
bartlomieju committed May 26, 2019
commit 898718f3fde31f4783729376306963ea1b90a591
8 changes: 4 additions & 4 deletions http/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ function toString(cookie: Cookie): string {
if (cookie.httpOnly) {
out.push("HttpOnly");
}
if (Number.isInteger(cookie.maxAge)) {
assert(cookie.maxAge > 0, "Max-Age must be an integer superior to 0");
if (Number.isInteger(cookie.maxAge!)) {
assert(cookie.maxAge! > 0, "Max-Age must be an integer superior to 0");
out.push(`Max-Age=${cookie.maxAge}`);
}
if (cookie.domain) {
Expand Down Expand Up @@ -75,10 +75,10 @@ function toString(cookie: Cookie): string {
export function getCookies(req: ServerRequest): Cookies {
if (req.headers.has("Cookie")) {
const out: Cookies = {};
const c = req.headers.get("Cookie").split(";");
const c = req.headers.get("Cookie")!.split(";");
for (const kv of c) {
const cookieVal = kv.split("=");
const key = cookieVal.shift().trim();
const key = cookieVal.shift()!.trim();
out[key] = cookieVal.join("=");
}
return out;
Expand Down
39 changes: 19 additions & 20 deletions http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ export async function writeResponse(w: Writer, r: Response): Promise<void> {
let out = `HTTP/${protoMajor}.${protoMinor} ${statusCode} ${statusText}\r\n`;

setContentLength(r);
const headers = r.headers!;

if (r.headers) {
for (const [key, value] of r.headers) {
out += `${key}: ${value}\r\n`;
}
for (const [key, value] of headers!) {
out += `${key}: ${value}\r\n`;
}
out += "\r\n";

Expand All @@ -88,8 +87,8 @@ export async function writeResponse(w: Writer, r: Response): Promise<void> {
if (r.body instanceof Uint8Array) {
const n = await writer.write(r.body);
assert(n === r.body.byteLength);
} else if (r.headers.has("content-length")) {
const bodyLength = parseInt(r.headers.get("content-length"));
} else if (headers.has("content-length")) {
const bodyLength = parseInt(headers.get("content-length")!);
const n = await copy(writer, r.body);
assert(n === bodyLength);
} else {
Expand All @@ -99,17 +98,17 @@ export async function writeResponse(w: Writer, r: Response): Promise<void> {
}

export class ServerRequest {
url: string;
method: string;
proto: string;
headers: Headers;
r: BufReader;
w: BufWriter;
url!: string;
method!: string;
proto!: string;
headers!: Headers;
r!: BufReader;
w!: BufWriter;
done: Deferred<void> = deferred();

public async *bodyStream(): AsyncIterableIterator<Uint8Array> {
if (this.headers.has("content-length")) {
const len = +this.headers.get("content-length");
const len = +this.headers.get("content-length")!;
if (Number.isNaN(len)) {
return new Uint8Array(0);
}
Expand All @@ -126,7 +125,7 @@ export class ServerRequest {
} else {
if (this.headers.has("transfer-encoding")) {
const transferEncodings = this.headers
.get("transfer-encoding")
.get("transfer-encoding")!
.split(",")
.map((e): string => e.trim().toLowerCase());
if (transferEncodings.includes("chunked")) {
Expand Down Expand Up @@ -226,7 +225,7 @@ export async function readRequest(
let firstLine: string;
[firstLine, err] = await tp.readLine();
if (err) {
return [null, err];
return [req, err];
}
[req.method, req.url, req.proto] = firstLine.split(" ", 3);
[req.headers, err] = await tp.readMIMEHeader();
Expand Down Expand Up @@ -254,7 +253,7 @@ export class Server implements AsyncIterable<ServerRequest> {
): AsyncIterableIterator<ServerRequest> {
const bufr = new BufReader(conn);
const w = new BufWriter(conn);
let bufStateErr: BufState;
let bufStateErr: BufState = null;
let req: ServerRequest;

while (!this.closing) {
Expand All @@ -264,18 +263,18 @@ export class Server implements AsyncIterable<ServerRequest> {
bufStateErr = err;
}
if (bufStateErr) break;
req.w = w;
yield req;
req!.w = w;
yield req!;
// Wait for the request to be processed before we accept a new request on
// this connection.
await req.done;
await req!.done;
}

if (bufStateErr === "EOF") {
// The connection was gracefully closed.
} else if (bufStateErr instanceof Error) {
// An error was thrown while parsing request headers.
await writeResponse(req.w, {
await writeResponse(req!.w, {
status: 400,
body: new TextEncoder().encode(`${bufStateErr.message}\r\n\r\n`)
});
Expand Down
7 changes: 3 additions & 4 deletions io/writers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { decode, encode } from "../strings/strings.ts";
export class StringWriter implements Writer {
private chunks: Uint8Array[] = [];
private byteLength: number = 0;
private cache: string | undefined;

constructor(private base: string = "") {
const c = encode(base);
Expand All @@ -16,12 +17,10 @@ export class StringWriter implements Writer {
async write(p: Uint8Array): Promise<number> {
this.chunks.push(p);
this.byteLength += p.byteLength;
this.cache = null;
this.cache = undefined;
return p.byteLength;
}

private cache: string;

toString(): string {
if (this.cache) {
return this.cache;
Expand All @@ -33,6 +32,6 @@ export class StringWriter implements Writer {
offs += chunk.byteLength;
}
this.cache = decode(buf);
return this.cache;
return this.cache!;
}
}
8 changes: 4 additions & 4 deletions log/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export class BaseHandler {
return this.formatter.replace(
/{(\S+)}/g,
(match, p1): string => {
const value = logRecord[p1];
const value = logRecord[p1 as keyof LogRecord];

// do not interpolate missing values
if (!value) {
return match;
}

return value;
return String(value);
}
);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export class ConsoleHandler extends BaseHandler {
}

export abstract class WriterHandler extends BaseHandler {
protected _writer: Writer;
protected _writer!: Writer;
private _encoder = new TextEncoder();

log(msg: string): void {
Expand All @@ -100,7 +100,7 @@ interface FileHandlerOptions extends HandlerOptions {
}

export class FileHandler extends WriterHandler {
private _file: File;
private _file!: File;
private _filename: string;

constructor(levelName: string, options: FileHandlerOptions) {
Expand Down
26 changes: 13 additions & 13 deletions mime/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,20 @@ class PartReader implements Reader, Closer {

close(): void {}

private contentDisposition: string;
private contentDispositionParams: { [key: string]: string };
private contentDisposition!: string;
private contentDispositionParams!: { [key: string]: string };

private getContentDispositionParams(): { [key: string]: string } {
if (this.contentDispositionParams) return this.contentDispositionParams;
const cd = this.headers.get("content-disposition");
const params = {};
const comps = cd.split(";");
const params: {[key: string]: string} = {};
const comps = cd!.split(";");
this.contentDisposition = comps[0];
comps
.slice(1)
.map((v): string => v.trim())
.map((v: string): string => v.trim())
.map(
(kv): void => {
(kv: string): void => {
const [k, v] = kv.split("=");
if (v) {
const s = v.charAt(0);
Expand Down Expand Up @@ -265,7 +265,7 @@ export class MultipartReader {
file.close();
formFile = {
filename: p.fileName,
type: p.headers.get("content-type"),
type: p.headers.get("content-type")!,
tempfile: filepath,
size
};
Expand All @@ -275,22 +275,22 @@ export class MultipartReader {
} else {
formFile = {
filename: p.fileName,
type: p.headers.get("content-type"),
type: p.headers.get("content-type")!,
content: buf.bytes(),
size: buf.bytes().byteLength
};
maxMemory -= n;
maxValueBytes -= n;
}
result[p.formName] = formFile;
result[p.formName] = formFile!;
}
return result;
}

private currentPart: PartReader;
private partsRead: number;
private currentPart: PartReader | undefined;
private partsRead: number = 0;

private async nextPart(): Promise<PartReader> {
private async nextPart(): Promise<PartReader | undefined> {
if (this.currentPart) {
this.currentPart.close();
}
Expand Down Expand Up @@ -413,7 +413,7 @@ export class MultipartWriter {
return this._boundary;
}

private lastPart: PartWriter;
private lastPart: PartWriter | undefined;
private bufWriter: BufWriter;
private isClosed: boolean = false;

Expand Down
2 changes: 1 addition & 1 deletion prettier/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const { build, run } = Deno;

// Runs a command in cross-platform way
export function xrun(opts): Deno.Process {
export function xrun(opts: Deno.RunOptions): Deno.Process {
return run({
...opts,
args: build.os === "win" ? ["cmd.exe", "/c", ...opts.args] : opts.args
Expand Down
6 changes: 3 additions & 3 deletions ws/sha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ export class Sha1 {

if (notString) {
for (i = start; index < length && i < 64; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
blocks[i >> 2] |= message[index] as number << SHIFT[i++ & 3];
}
} else {
for (i = start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
code = (message as string).charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
} else if (code < 0x800) {
Expand All @@ -94,7 +94,7 @@ export class Sha1 {
} else {
code =
0x10000 +
(((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
(((code & 0x3ff) << 10) | ((message as string).charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
Expand Down