Skip to content

Commit ff9ff14

Browse files
committed
adds ESLint
1 parent 0a42f5c commit ff9ff14

11 files changed

+7400
-4971
lines changed

.eslintrc.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"mocha": true
5+
},
6+
"extends": ["airbnb-base", "prettier"],
7+
"globals": {
8+
"Atomics": "readonly",
9+
"SharedArrayBuffer": "readonly",
10+
"emit": "readonly"
11+
},
12+
"parserOptions": {
13+
"ecmaVersion": 2018,
14+
"sourceType": "module"
15+
},
16+
"rules": {
17+
"no-bitwise": "off",
18+
"curly": "error",
19+
"no-unused-vars": ["error", { "varsIgnorePattern": "consume" }],
20+
"no-underscore-dangle": ["error", { "allow": ["__get__", "__set__"] }]
21+
}
22+
}

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": false,
3+
"trailingComma": "all",
4+
"tabWidth": 2
5+
}

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
}
6+
}

lib/validate-schemas.spec.js

+49-31
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,79 @@
1-
var glob = require("glob");
1+
const glob = require("glob");
22
const fs = require("fs");
33
const Ajv = require("ajv");
44
const chai = require("chai");
55
const axios = require("axios");
6-
const assert = chai.assert;
6+
7+
const { assert } = chai;
78

89
function loadRemoteSchema(uri) {
9-
return axios.get(uri).then(function (res) {
10-
if (res.status >= 400) {
11-
throw new Error("Schema loading error: " + res.statusCode);
12-
}
13-
return res.data;
10+
const client = axios.create({
11+
timeout: 1500,
1412
});
13+
14+
return client
15+
.get(uri)
16+
.catch((e) => {
17+
console.log(`error while loading schema from ${uri} with error ${e}`);
18+
})
19+
.then((res) => {
20+
if (res.status >= 400) {
21+
throw new Error(`Schema loading error: ${res.statusCode}`);
22+
}
23+
return res.data;
24+
});
1525
}
1626

17-
const validateSchema = (filepath) => {
18-
return new Promise((resolve, reject) => {
19-
fs.readFile(filepath, "utf8", function (err, fileContents) {
27+
const validateSchema = (filepath) =>
28+
new Promise((resolve, reject) => {
29+
fs.readFile(filepath, "utf8", (err, fileContents) => {
2030
if (err) {
2131
reject(err);
2232
} else {
23-
var schema = JSON.parse(fileContents);
33+
const schema = JSON.parse(fileContents);
34+
2435
const ajv = new Ajv({
2536
allErrors: true,
2637
loadSchema: loadRemoteSchema,
2738
});
28-
ajv.compileAsync(schema, (err, validate) => {
29-
if (err) {
30-
resolve({ isValid: false, filepath: filepath, errors: ajv.errors });
39+
40+
ajv.compileAsync(schema, (compileErr) => {
41+
if (compileErr) {
42+
resolve({ isValid: false, filepath, errors: ajv.errors });
3143
} else {
32-
resolve({ isValid: true, filepath: filepath });
44+
resolve({ isValid: true, filepath });
3345
}
3446
});
3547
}
3648
});
3749
});
38-
};
3950

40-
describe("validate schemas", function () {
41-
it("should validate all schemas", function (done) {
42-
const options = { absolute: true };
43-
glob("**/*schema.json", options, function (err, files) {
44-
var promises = [];
51+
describe("validate schemas", () => {
52+
it("should validate all schemas", (done) => {
53+
const options = { absolute: true, ignore: "node_modules/**" };
54+
glob("**/*schema.json", options, (err, files) => {
55+
if (err) {
56+
console.log(err);
57+
}
58+
const promises = [];
4559
files.forEach((file) => {
4660
promises.push(validateSchema(file));
4761
});
48-
Promise.all(promises).then((values) => {
49-
values.forEach((result) => {
50-
if (!result.isValid) {
51-
console.log(result.errors);
52-
}
62+
Promise.all(promises)
63+
.catch((promiseErr) => {
64+
console.log(promiseErr);
65+
})
66+
.then((values) => {
67+
values.forEach((result) => {
68+
if (!result.isValid) {
69+
console.log(result.errors);
70+
}
5371

54-
assert.isTrue(result.isValid, `${result.filepath} is invalid`);
55-
});
72+
assert.isTrue(result.isValid, `${result.filepath} is invalid`);
73+
});
5674

57-
done();
58-
});
75+
done();
76+
});
5977
});
60-
});
78+
}).timeout(20000);
6179
});

0 commit comments

Comments
 (0)