Skip to content

Commit 41b5efd

Browse files
committed
Fix lint issues
1 parent 102d99d commit 41b5efd

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

lib/validator.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ function escapeEvalString(str) {
3333
// Based on https://github.com/joliss/js-string-escape
3434
return str.replace(escapeEvalRegex, function (character) {
3535
switch (character) {
36-
case '"':
37-
case "'":
38-
case '\\':
39-
return '\\' + character
40-
// Four possible LineTerminator characters need to be escaped:
41-
case '\n':
42-
return '\\n'
43-
case '\r':
44-
return '\\r'
45-
case '\u2028':
46-
return '\\u2028'
47-
case '\u2029':
48-
return '\\u2029'
36+
case "\"":
37+
case "'":
38+
case "\\":
39+
return "\\" + character;
40+
// Four possible LineTerminator characters need to be escaped:
41+
case "\n":
42+
return "\\n";
43+
case "\r":
44+
return "\\r";
45+
case "\u2028":
46+
return "\\u2028";
47+
case "\u2029":
48+
return "\\u2029";
4949
}
5050
});
5151
}
@@ -135,7 +135,7 @@ Validator.prototype.compileSchemaObject = function(schemaObject) {
135135
for (let i = 0; i < compiledObject.properties.length; i++) {
136136
const property = compiledObject.properties[i];
137137
const name = escapeEvalString(property.name);
138-
const propertyValueExpr = identifierRegex.test(name) ? `value.${name}` : `value[\"${name}\"]`;
138+
const propertyValueExpr = identifierRegex.test(name) ? `value.${name}` : `value["${name}"]`;
139139

140140
sourceCode.push(`propertyPath = (path !== undefined ? path + ".${name}" : "${name}");`);
141141
if (Array.isArray(property.compiledType)) {

test/validator.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,11 @@ describe("Test irregular object property names", () => {
11141114

11151115
it("should compile schema with reserved keyword", () => {
11161116
// Reserved keywords are permitted as unquoted property names in ES5+. There is no special support for these
1117-
const o = {};
11181117
const schema = {
1119-
'for': { type: "string" },
1120-
'goto': { type: "string" },
1121-
'var': { type: "string" },
1122-
'try': { type: "string" },
1118+
for: { type: "string" },
1119+
goto: { type: "string" },
1120+
var: { type: "string" },
1121+
try: { type: "string" },
11231122
};
11241123

11251124
const res = v.validate({

0 commit comments

Comments
 (0)