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
strict - clean ws/, io/, fs/
  • Loading branch information
bartlomieju committed May 25, 2019
commit 2b2ec3a6ad4ec8693e0c95e54b6d9ce7d374b117
29 changes: 14 additions & 15 deletions encoding/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { deepAssign } from "../util/deep_assign.ts";
import { pad } from "../strings/pad.ts";

class KeyValuePair {
key: string;
value: unknown;
constructor (public key: string, public value: unknown) {}
}

class ParserGroup {
type: string;
name: string;
arrValues: unknown[] = [];
objValues: object = {};

constructor (public type: string, public name: string) {}
}

class ParserContext {
Expand Down Expand Up @@ -167,22 +166,22 @@ class Parser {
if (this.context.currentGroup) {
this._groupToOutput();
}
let g = new ParserGroup();
g.name = line.match(captureReg)[1];
if (g.name.match(/\[.*\]/)) {
g.type = "array";
g.name = g.name.match(captureReg)[1];

let type;
let name = line.match(captureReg)![1];
if (name.match(/\[.*\]/)) {
type = "array";
name = name.match(captureReg)![1];
} else {
g.type = "object";
type = "object";
}
this.context.currentGroup = g;
this.context.currentGroup = new ParserGroup(type, name);
}
_processDeclaration(line: string): KeyValuePair {
let kv = new KeyValuePair();
const idx = line.indexOf("=");
kv.key = line.substring(0, idx).trim();
kv.value = this._parseData(line.slice(idx + 1));
return kv;
const key = line.substring(0, idx).trim();
const value = this._parseData(line.slice(idx + 1));
return new KeyValuePair(key, value);
}
// TODO (zekth) Need refactor using ACC
_parseData(dataString: string): unknown {
Expand Down
5 changes: 3 additions & 2 deletions fs/path/win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function normalize(path: string): string {
const len = path.length;
if (len === 0) return ".";
let rootEnd = 0;
let device: string;
let device: string | undefined;
let isAbsolute = false;
const code = path.charCodeAt(0);

Expand Down Expand Up @@ -301,7 +301,7 @@ export function join(...paths: string[]): string {
const pathsCount = paths.length;
if (pathsCount === 0) return ".";

let joined: string;
let joined: string | undefined;
let firstPart: string;
for (let i = 0; i < pathsCount; ++i) {
let path = paths[i];
Expand Down Expand Up @@ -329,6 +329,7 @@ export function join(...paths: string[]): string {
// path.join('//server', 'share') -> '\\\\server\\share\\')
let needsReplace = true;
let slashCount = 0;
firstPart = firstPart!;
if (isPathSeparator(firstPart.charCodeAt(0))) {
++slashCount;
const firstLen = firstPart.length;
Expand Down
18 changes: 9 additions & 9 deletions io/bufio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ export type BufState =

/** BufReader implements buffering for a Reader object. */
export class BufReader implements Reader {
private buf: Uint8Array;
private rd: Reader; // Reader provided by caller.
private buf!: Uint8Array;
private rd!: Reader; // Reader provided by caller.
private r = 0; // buf read position.
private w = 0; // buf write position.
private lastByte: number;
private lastCharSize: number;
private err: BufState;
private lastByte!: number;
private err: BufState = null;

/** return new BufReader unless r is BufReader */
static create(r: Reader, size = DEFAULT_BUF_SIZE): BufReader {
Expand Down Expand Up @@ -282,7 +281,7 @@ export class BufReader implements Reader {
async readSlice(delim: number): Promise<[Uint8Array, BufState]> {
let s = 0; // search start index
let line: Uint8Array;
let err: BufState;
let err: BufState = null;
while (true) {
// Search buffer.
let i = this.buf.subarray(this.r + s, this.w).indexOf(delim);
Expand Down Expand Up @@ -347,7 +346,7 @@ export class BufReader implements Reader {
}

// 0 <= n <= len(this.buf)
let err: BufState;
let err: BufState = null;
let avail = this.w - this.r;
if (avail < n) {
// not enough data in buffer
Expand Down Expand Up @@ -408,7 +407,7 @@ export class BufWriter implements Writer {
return null;
}

let n: number;
let n: number = 0;
let err: BufState = null;
try {
n = await this.wr.write(this.buf.subarray(0, this.n));
Expand All @@ -429,6 +428,7 @@ export class BufWriter implements Writer {
return err;
}
this.n = 0;
return err;
}

/** Returns how many bytes are unused in the buffer. */
Expand All @@ -448,7 +448,7 @@ export class BufWriter implements Writer {
*/
async write(p: Uint8Array): Promise<number> {
let nn = 0;
let n: number;
let n: number = 0;
while (p.byteLength > this.available() && !this.err) {
if (this.buffered() == 0) {
// Large write, empty buffer.
Expand Down
12 changes: 7 additions & 5 deletions ws/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ export interface WebSocketCloseEvent {
reason?: string;
}

export function isWebSocketCloseEvent(a): a is WebSocketCloseEvent {
return a && typeof a["code"] === "number";
export function isWebSocketCloseEvent(a: WebSocketEvent): a is WebSocketCloseEvent {
return typeof a === "object" && a.hasOwnProperty("code");
}

export type WebSocketPingEvent = ["ping", Uint8Array];

export function isWebSocketPingEvent(a): a is WebSocketPingEvent {
export function isWebSocketPingEvent(a: WebSocketEvent): a is WebSocketPingEvent {
return Array.isArray(a) && a[0] === "ping" && a[1] instanceof Uint8Array;
}

export type WebSocketPongEvent = ["pong", Uint8Array];

export function isWebSocketPongEvent(a): a is WebSocketPongEvent {
export function isWebSocketPongEvent(a: WebSocketEvent): a is WebSocketPongEvent {
return Array.isArray(a) && a[0] === "pong" && a[1] instanceof Uint8Array;
}

Expand Down Expand Up @@ -455,7 +455,9 @@ export async function connectWebSocket(
if (!m) {
abortHandshake(new Error("ws: invalid status line: " + statusLine));
}
const [_, version, statusCode] = m;
const version: string = m![1];
const statusCode: string = m![2];

if (version !== "HTTP/1.1" || statusCode !== "101") {
abortHandshake(
new Error(
Expand Down