Skip to content

Commit

Permalink
Update linter and code style
Browse files Browse the repository at this point in the history
PR-URL: #411
  • Loading branch information
tshemsedinov committed Jun 22, 2022
1 parent 6c0b3be commit dc9b69c
Showing 9 changed files with 30 additions and 34 deletions.
6 changes: 1 addition & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -9,10 +9,6 @@
"ecmaVersion": "latest"
},
"rules": {
"arrow-parens": ["error", "always"],
"comma-dangle": "off",
"handle-callback-err": "off",
"consistent-return": "off",
"new-cap": "off"
"consistent-return": "off"
}
}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"singleQuote": true,
"trailingComma": "es5",
"trailingComma": "all",
"overrides": [
{
"files": ".prettierrc",
4 changes: 2 additions & 2 deletions lib/types.js
Original file line number Diff line number Diff line change
@@ -55,13 +55,13 @@ const updateTypeMetadata = (Type, metadata = {}) => {
const checkCustomType = (proto) => {
if (!proto) {
throw new Error(
'Custom type must be an object with methods "construct" and "checkType"'
'Custom type must be an object with methods "construct" and "checkType"',
);
}
const { checkType, construct } = proto;
if (!checkType || !construct) {
throw new Error(
'Custom type must contain "construct" and "checkType" methods'
'Custom type must contain "construct" and "checkType" methods',
);
}
if (typeof checkType !== 'function' || typeof construct !== 'function') {
2 changes: 1 addition & 1 deletion metaschema.d.ts
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ export function loadSchema(fileName: string): Promise<Schema>;
export function readDirectory(dirPath: string): Promise<Map<string, object>>;
export function loadModel(
modelPath: string,
systemTypes: object
systemTypes: object,
): Promise<Model>;
export function saveTypes(outputFile: string, model: Model): Promise<void>;

4 changes: 2 additions & 2 deletions test/collections.js
Original file line number Diff line number Diff line change
@@ -343,11 +343,11 @@ metatests.test('Collections: nested object', (test) => {
test.strictSame(sch2.check({}).valid, false);
test.strictSame(
sch3.check({ key: [{ key: { key: { name: 'Georg' } } }] }).valid,
true
true,
);
test.strictSame(
sch3.check({ key: [{ key: { name: 'Georg' } }] }).valid,
false
false,
);
test.strictSame(sch4.check({}).valid, true);
test.strictSame(sch4.fields.required, false);
10 changes: 5 additions & 5 deletions test/model.js
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ metatests.test('Model: from struct', (test) => {
const warn = model.warnings[0];
test.strictEqual(
warn,
'Warning: "Address" referenced by "Company" is not found'
'Warning: "Address" referenced by "Company" is not found',
);

test.end();
@@ -118,7 +118,7 @@ metatests.test(
const identifier = model.entities.get('Identifier');
test.strictEqual(
identifier.check({ creation: Date.now().toLocaleString() }).valid,
true
true,
);
const tester = model.entities.get('Tester');
test.strictEqual(
@@ -132,7 +132,7 @@ metatests.test(
],
},
}).valid,
true
true,
);
test.strictEqual(
tester.check({
@@ -141,8 +141,8 @@ metatests.test(
count: 2,
},
}).valid,
false
false,
);
test.end();
}
},
);
24 changes: 12 additions & 12 deletions test/schema.js
Original file line number Diff line number Diff line change
@@ -127,21 +127,21 @@ metatests.test('Schema: validation function', (test) => {
schema.check({
field: 'abc',
}).valid,
true
true,
);

test.strictSame(
schema.check({
field2: 'abc',
}).errors,
['Field "" .field is required', 'Field "field2" is not expected']
['Field "" .field is required', 'Field "field2" is not expected'],
);

test.strictSame(
schema.check({
throw: '42',
}).errors,
['Field "" validation failed Error: 42', 'Field "throw" is not expected']
['Field "" validation failed Error: 42', 'Field "throw" is not expected'],
);

test.end();
@@ -183,14 +183,14 @@ metatests.test('Schema: nested validation function', (test) => {
schema.check({
field: 'abc',
}).valid,
true
true,
);

test.strictSame(
schema.check({
field2: 'abc',
}).errors,
['Field "field" is required', 'Field "field2" is not expected']
['Field "field" is required', 'Field "field2" is not expected'],
);

test.strictSame(
@@ -200,7 +200,7 @@ metatests.test('Schema: nested validation function', (test) => {
field: 'abc',
},
}).valid,
true
true,
);

test.strictSame(
@@ -213,7 +213,7 @@ metatests.test('Schema: nested validation function', (test) => {
[
'Field "field2" is not expected',
'Field "nested" nested.field is required',
]
],
);

test.strictSame(
@@ -226,7 +226,7 @@ metatests.test('Schema: nested validation function', (test) => {
[
'Field "throw" is not expected',
'Field "nested" validation failed Error: 42',
]
],
);
test.end();
});
@@ -278,16 +278,16 @@ metatests.test(
type: 'myType',
note: 'this is not vorbidden anymore',
}).valid,
true
true,
);
test.strictSame(
schema.check({
note: 'this is not vorbidden anymore',
}).valid,
false
false,
);
test.end();
}
},
);

metatests.test('Schema: custom validate on field', (test) => {
@@ -317,7 +317,7 @@ metatests.test('Schema: custom validate on field', (test) => {
test.strictEqual(schema1.check({ email: 'asd@asd.com' }).valid, true);
test.strictEqual(
schema1.check({ email: 'asdasdasdasdasdasd@asd.com' }).errors,
['Field "email" exceeds the maximum length']
['Field "email" exceeds the maximum length'],
);
const defs2 = {
type: 'number',
8 changes: 4 additions & 4 deletions test/structs.js
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ metatests.test('Structs: multiple optional nested struct', (test) => {
nfield1: { text: 'abc' },
},
}).valid,
true
true,
);

test.strictSame(
@@ -156,7 +156,7 @@ metatests.test('Structs: multiple optional nested struct', (test) => {
nfield2: { text: 'aaa' },
},
}).valid,
true
true,
);

test.strictSame(
@@ -167,7 +167,7 @@ metatests.test('Structs: multiple optional nested struct', (test) => {
nfield2: { text: 'aaa', caption: 'caption' },
},
}).valid,
true
true,
);

test.strictSame(
@@ -181,7 +181,7 @@ metatests.test('Structs: multiple optional nested struct', (test) => {
[
`Field "data.nfield1.text" is required`,
`Field "data.nfield2.caption" not of expected type: string`,
]
],
);
test.end();
});
4 changes: 2 additions & 2 deletions test/tuple.js
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ metatests.test('Tuple: basic implementation', (test) => {
]);
test.strictEqual(
schema2.check([BigInt(9007199254740991), false, 123]).errors,
['Field "" value length is more then expected in tuple']
['Field "" value length is more then expected in tuple'],
);

const long = { type: 'tuple', value: ['string'] };
@@ -75,7 +75,7 @@ metatests.test('Tuple: usage with schema', (test) => {
test.strictEqual(schema.check({ field: [true, 123] }).valid, true);
test.strictEqual(
schema.check({ field: [false, { some: 'wrong data' }] }).errors,
['Field "field(count1)" not of expected type: number']
['Field "field(count1)" not of expected type: number'],
);
test.end();
});

0 comments on commit dc9b69c

Please sign in to comment.