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
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing toml
  • Loading branch information
zekth committed May 25, 2019
commit 589cfb439d506141742de346cadc42a9ff031854
86 changes: 52 additions & 34 deletions encoding/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { deepAssign } from "../util/deep_assign.ts";
import { pad } from "../strings/pad.ts";

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

class ParserGroup {
arrValues: unknown[] = [];
objValues: object = {};
objValues: Record<string, unknown> = {};

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

class ParserContext {
currentGroup?: ParserGroup;
output: object = {};
output: Record<string, unknown> = {};
}

class Parser {
Expand Down Expand Up @@ -123,28 +123,30 @@ class Parser {
this.tomlLines = merged;
}
_unflat(keys: string[], values: object = {}, cObj: object = {}): object {
let out = {};
let out: Record<string, unknown> = {};
if (keys.length === 0) {
return cObj;
} else {
if (Object.keys(cObj).length === 0) {
cObj = values;
}
let key = keys.pop();
out[key] = cObj;
let key: string | undefined = keys.pop();
if (key) {
out[key] = cObj;
}
return this._unflat(keys, values, out);
}
}
_groupToOutput(): void {
const arrProperty = this.context.currentGroup.name
.replace(/"/g, "")
const arrProperty = this.context
.currentGroup!.name.replace(/"/g, "")
.replace(/'/g, "")
.split(".");
let u = {};
if (this.context.currentGroup.type === "array") {
u = this._unflat(arrProperty, this.context.currentGroup.arrValues);
if (this.context.currentGroup!.type === "array") {
u = this._unflat(arrProperty, this.context.currentGroup!.arrValues);
} else {
u = this._unflat(arrProperty, this.context.currentGroup.objValues);
u = this._unflat(arrProperty, this.context.currentGroup!.objValues);
}
deepAssign(this.context.output, u);
delete this.context.currentGroup;
Expand Down Expand Up @@ -352,23 +354,27 @@ class Parser {
_cleanOutput(): void {
this._propertyClean(this.context.output);
}
_propertyClean(obj: object): void {
_propertyClean(obj: Record<string, unknown>): void {
const keys = Object.keys(obj);
for (let i = 0; i < keys.length; i++) {
let k = keys[i];
let v = obj[k];
let pathDeclaration = this._parseDeclarationName(k);
delete obj[k];
if (pathDeclaration.length > 1) {
k = pathDeclaration.shift();
k = k.replace(/"/g, "");
v = this._unflat(pathDeclaration, v as object);
} else {
k = k.replace(/"/g, "");
}
obj[k] = v;
if (v instanceof Object) {
this._propertyClean(v);
if (k) {
let v = obj[k];
let pathDeclaration = this._parseDeclarationName(k);
delete obj[k];
if (pathDeclaration.length > 1) {
const shift = pathDeclaration.shift();
if (shift) {
k = shift.replace(/"/g, "");
v = this._unflat(pathDeclaration, v as object);
}
} else {
k = k.replace(/"/g, "");
}
obj[k] = v;
if (v instanceof Object) {
this._propertyClean(v);
}
}
}
}
Expand All @@ -392,18 +398,26 @@ class Dumper {
this.output = this._format();
return this.output;
}
_parse(obj: object, path: string = ""): string[] {
_parse(obj: Record<string, unknown>, path: string = ""): string[] {
const out = [];
const props = Object.keys(obj);
const propObj = props.filter(
(e): boolean =>
(obj[e] instanceof Array && !this._isSimplySerializable(obj[e][0])) ||
!this._isSimplySerializable(obj[e])
(e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return !this._isSimplySerializable(d[0]);
}
return !this._isSimplySerializable(obj[e]);
}
);
const propPrim = props.filter(
(e): boolean =>
!(obj[e] instanceof Array && !this._isSimplySerializable(obj[e][0])) &&
this._isSimplySerializable(obj[e])
(e: string): boolean => {
if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[];
return this._isSimplySerializable(d[0]);
}
return this._isSimplySerializable(obj[e]);
}
);
const k = propPrim.concat(propObj);
for (let i = 0; i < k.length; i++) {
Expand Down Expand Up @@ -434,7 +448,11 @@ class Dumper {
} else if (typeof value === "object") {
out.push("");
out.push(this._header(path + prop));
out.push(...this._parse(value, `${path}${prop}.`));
if (value) {
const toParse: Record<string, unknown> = value;
out.push(...this._parse(toParse, `${path}${prop}.`));
}
// out.push(...this._parse(value, `${path}${prop}.`));
}
}
out.push("");
Expand Down