Skip to content

Commit a905091

Browse files
committed
fix lints & remove old tests
1 parent ba23707 commit a905091

File tree

4 files changed

+24
-90
lines changed

4 files changed

+24
-90
lines changed

lib/validator.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,24 @@ Validator.prototype.compile = function(schema) {
6666
throw new Error("If the schema is an Array, must contain at least one element!");
6767
}
6868

69-
var rules = this.compileSchemaType(schema);
69+
const rules = this.compileSchemaType(schema);
7070
return function(value) {
7171
return self.checkSchemaType(value, rules, undefined, null);
72-
}
72+
};
7373
}
7474

75-
var rule = this.compileSchemaObject(schema);
75+
const rule = this.compileSchemaObject(schema);
7676
return function(value) {
7777
return self.checkSchemaObject(value, rule, undefined, null);
78-
}
78+
};
7979
};
8080

8181
Validator.prototype.compileSchemaObject = function(schemaObject) {
8282
if (schemaObject === null || typeof schemaObject !== "object" || Array.isArray(schemaObject)) {
8383
throw new Error("Invalid schema!");
8484
}
8585

86-
var compiledObject = Object.keys(schemaObject).map(name => {
86+
const compiledObject = Object.keys(schemaObject).map(name => {
8787
const compiledType = this.compileSchemaType(schemaObject[name]);
8888
return {name: name, compiledType: compiledType};
8989
});
@@ -92,9 +92,9 @@ Validator.prototype.compileSchemaObject = function(schemaObject) {
9292
// return compiledObject;
9393

9494
const sourceCode = [];
95-
sourceCode.push(`let res;`);
96-
sourceCode.push(`let propertyPath;`);
97-
sourceCode.push(`const errors = [];`);
95+
sourceCode.push("let res;");
96+
sourceCode.push("let propertyPath;");
97+
sourceCode.push("const errors = [];");
9898
for (let i = 0; i < compiledObject.length; i++) {
9999
const property = compiledObject[i];
100100
const name = property.name;
@@ -104,16 +104,16 @@ Validator.prototype.compileSchemaObject = function(schemaObject) {
104104
} else {
105105
sourceCode.push(`res = this.checkSchemaRule(value.${name}, compiledObject[${i}].compiledType, propertyPath, value);`);
106106
}
107-
sourceCode.push(`if (res !== true) {`);
108-
sourceCode.push(`\tthis.handleResult(errors, propertyPath, res);`);
109-
sourceCode.push(`}`);
107+
sourceCode.push("if (res !== true) {");
108+
sourceCode.push("\tthis.handleResult(errors, propertyPath, res);");
109+
sourceCode.push("}");
110110
}
111111

112-
sourceCode.push(`return errors.length === 0 ? true : errors;`);
112+
sourceCode.push("return errors.length === 0 ? true : errors;");
113113

114-
var compiledObjectFunction = new Function("value", "compiledObject", "path", "parent", sourceCode.join("\n"));
114+
const compiledObjectFunction = new Function("value", "compiledObject", "path", "parent", sourceCode.join("\n"));
115115

116-
var self = this;
116+
const self = this;
117117
return function(value, _unused, path, parent) {
118118
return compiledObjectFunction.call(self, value, compiledObject, path, parent);
119119
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"rollup-plugin-uglify-es": "0.0.1"
5252
},
5353
"jest": {
54+
"coverageDirectory": "../coverage",
5455
"testEnvironment": "node",
5556
"rootDir": "./lib",
5657
"roots": [

test/helpers/deep-extend.spec.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ describe("deepExtend", () => {
88
b: 5,
99
c: 6
1010
},
11-
d: true
11+
d: true,
12+
j: [],
13+
k: [1,2]
1214
}, {
1315
a: {
1416
b: 10,
@@ -17,7 +19,9 @@ describe("deepExtend", () => {
1719
f: "F",
1820
g: {
1921
h: "H"
20-
}
22+
},
23+
j: "some",
24+
k: [5,6]
2125
});
2226
expect(result).toEqual({
2327
a: {
@@ -29,7 +33,9 @@ describe("deepExtend", () => {
2933
f: "F",
3034
g: {
3135
h: "H"
32-
}
36+
},
37+
j: "some",
38+
k: [5,6]
3339
});
3440
});
3541
});

test/validator.spec.js

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -196,79 +196,6 @@ describe("Test compile (unit test)", () => {
196196
});
197197
});
198198

199-
// Skip tests for earlier compiler internals
200-
describe.skip("Test _processRule", () => {
201-
202-
const v = new Validator();
203-
v.compile = jest.fn();
204-
v._checkWrapper = jest.fn();
205-
206-
it("should return array of rules", () => {
207-
let res = v._processRule({ type: "number", positive: true }, "id", false);
208-
209-
expect(res).toBeInstanceOf(Array);
210-
expect(res.length).toBe(1);
211-
expect(res[0].fn).toBeInstanceOf(Function);
212-
expect(res[0].type).toBe("number");
213-
expect(res[0].name).toBe("id");
214-
expect(res[0].schema).toEqual({ type: "number", positive: true });
215-
expect(res[0].iterate).toBe(false);
216-
});
217-
218-
it("should convert shorthand definition", () => {
219-
let res = v._processRule("string", "name", false);
220-
221-
expect(res).toBeInstanceOf(Array);
222-
expect(res.length).toBe(1);
223-
expect(res[0].fn).toBeInstanceOf(Function);
224-
expect(res[0].type).toBe("string");
225-
expect(res[0].name).toBe("name");
226-
expect(res[0].schema).toEqual({ type: "string" });
227-
expect(res[0].iterate).toBe(false);
228-
});
229-
230-
it("should call compile if type is object", () => {
231-
let res = v._processRule({ type: "object", props: {
232-
id: "number"
233-
} }, "item", false);
234-
235-
expect(res).toBeInstanceOf(Array);
236-
expect(res.length).toBe(2);
237-
expect(res[0].fn).toBeInstanceOf(Function);
238-
expect(res[0].type).toBe("object");
239-
expect(res[0].name).toBe("item");
240-
expect(res[0].iterate).toBe(false);
241-
242-
//expect(res[1].fn).toBeInstanceOf(Function);
243-
expect(res[1].type).toBe("object");
244-
expect(res[1].name).toBe("item");
245-
expect(res[1].iterate).toBe(false);
246-
247-
expect(v.compile).toHaveBeenCalledTimes(1);
248-
expect(v.compile).toHaveBeenCalledWith({id: "number"});
249-
});
250-
251-
it("should call checkWrapper & processRule if type is Array", () => {
252-
let res = v._processRule({ type: "array", items: "number" }, "list", false);
253-
254-
expect(res).toBeInstanceOf(Array);
255-
expect(res.length).toBe(2);
256-
257-
expect(res[0].fn).toBeInstanceOf(Function);
258-
expect(res[0].type).toBe("array");
259-
expect(res[0].name).toBe("list");
260-
expect(res[0].iterate).toBe(false);
261-
262-
//expect(res[1].fn).toBeInstanceOf(Function);
263-
expect(res[1].type).toBe("array");
264-
expect(res[1].name).toBe("list");
265-
expect(res[1].iterate).toBe(true);
266-
267-
expect(v._checkWrapper).toHaveBeenCalledTimes(1);
268-
expect(v._checkWrapper).toHaveBeenCalledWith([{"fn": expect.any(Function), "iterate": false, "name": null, "schema": {"type": "number"}, "type": "number"}]);
269-
});
270-
});
271-
272199
describe("Test compile (integration test)", () => {
273200

274201
describe("Test check generator with good obj", () => {

0 commit comments

Comments
 (0)