Add eslint checks for rustdoc-js tester
This commit is contained in:
parent
67e1681c1d
commit
856c9bb481
96
src/tools/rustdoc-js/.eslintrc.js
Normal file
96
src/tools/rustdoc-js/.eslintrc.js
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
module.exports = {
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"node": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2015,
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"semi": [
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
],
|
||||||
|
"quotes": [
|
||||||
|
"error",
|
||||||
|
"double"
|
||||||
|
],
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"no-trailing-spaces": "error",
|
||||||
|
"no-var": ["error"],
|
||||||
|
"prefer-const": ["error"],
|
||||||
|
"prefer-arrow-callback": ["error"],
|
||||||
|
"brace-style": [
|
||||||
|
"error",
|
||||||
|
"1tbs",
|
||||||
|
{ "allowSingleLine": false }
|
||||||
|
],
|
||||||
|
"keyword-spacing": [
|
||||||
|
"error",
|
||||||
|
{ "before": true, "after": true }
|
||||||
|
],
|
||||||
|
"arrow-spacing": [
|
||||||
|
"error",
|
||||||
|
{ "before": true, "after": true }
|
||||||
|
],
|
||||||
|
"key-spacing": [
|
||||||
|
"error",
|
||||||
|
{ "beforeColon": false, "afterColon": true, "mode": "strict" }
|
||||||
|
],
|
||||||
|
"func-call-spacing": ["error", "never"],
|
||||||
|
"space-infix-ops": "error",
|
||||||
|
"space-before-function-paren": ["error", "never"],
|
||||||
|
"space-before-blocks": "error",
|
||||||
|
"comma-dangle": ["error", "always-multiline"],
|
||||||
|
"comma-style": ["error", "last"],
|
||||||
|
"max-len": ["error", { "code": 100, "tabWidth": 4 }],
|
||||||
|
"eol-last": ["error", "always"],
|
||||||
|
"arrow-parens": ["error", "as-needed"],
|
||||||
|
"no-unused-vars": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"argsIgnorePattern": "^_",
|
||||||
|
"varsIgnorePattern": "^_"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"eqeqeq": "error",
|
||||||
|
"no-const-assign": "error",
|
||||||
|
"no-debugger": "error",
|
||||||
|
"no-dupe-args": "error",
|
||||||
|
"no-dupe-else-if": "error",
|
||||||
|
"no-dupe-keys": "error",
|
||||||
|
"no-duplicate-case": "error",
|
||||||
|
"no-ex-assign": "error",
|
||||||
|
"no-fallthrough": "error",
|
||||||
|
"no-invalid-regexp": "error",
|
||||||
|
"no-import-assign": "error",
|
||||||
|
"no-self-compare": "error",
|
||||||
|
"no-template-curly-in-string": "error",
|
||||||
|
"block-scoped-var": "error",
|
||||||
|
"guard-for-in": "error",
|
||||||
|
"no-alert": "error",
|
||||||
|
"no-confusing-arrow": "error",
|
||||||
|
"no-div-regex": "error",
|
||||||
|
"no-floating-decimal": "error",
|
||||||
|
"no-implicit-globals": "error",
|
||||||
|
"no-implied-eval": "error",
|
||||||
|
"no-label-var": "error",
|
||||||
|
"no-lonely-if": "error",
|
||||||
|
"no-mixed-operators": "error",
|
||||||
|
"no-multi-assign": "error",
|
||||||
|
"no-return-assign": "error",
|
||||||
|
"no-script-url": "error",
|
||||||
|
"no-sequences": "error",
|
||||||
|
"no-div-regex": "error",
|
||||||
|
}
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
const path = require('path');
|
const path = require("path");
|
||||||
|
|
||||||
function loadContent(content) {
|
function loadContent(content) {
|
||||||
const Module = module.constructor;
|
const Module = module.constructor;
|
||||||
@ -15,7 +15,7 @@ function loadContent(content) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function readFile(filePath) {
|
function readFile(filePath) {
|
||||||
return fs.readFileSync(filePath, 'utf8');
|
return fs.readFileSync(filePath, "utf8");
|
||||||
}
|
}
|
||||||
|
|
||||||
function contentToDiffLine(key, value) {
|
function contentToDiffLine(key, value) {
|
||||||
@ -25,41 +25,41 @@ function contentToDiffLine(key, value) {
|
|||||||
// This function is only called when no matching result was found and therefore will only display
|
// This function is only called when no matching result was found and therefore will only display
|
||||||
// the diff between the two items.
|
// the diff between the two items.
|
||||||
function betterLookingDiff(entry, data) {
|
function betterLookingDiff(entry, data) {
|
||||||
let output = ' {\n';
|
let output = " {\n";
|
||||||
const spaces = ' ';
|
const spaces = " ";
|
||||||
for (const key in entry) {
|
for (const key in entry) {
|
||||||
if (!entry.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(entry, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!data || !data.hasOwnProperty(key)) {
|
if (!data || !Object.prototype.hasOwnProperty.call(data, key)) {
|
||||||
output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n';
|
output += "-" + spaces + contentToDiffLine(key, entry[key]) + "\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const value = data[key];
|
const value = data[key];
|
||||||
if (value !== entry[key]) {
|
if (value !== entry[key]) {
|
||||||
output += '-' + spaces + contentToDiffLine(key, entry[key]) + '\n';
|
output += "-" + spaces + contentToDiffLine(key, entry[key]) + "\n";
|
||||||
output += '+' + spaces + contentToDiffLine(key, value) + '\n';
|
output += "+" + spaces + contentToDiffLine(key, value) + "\n";
|
||||||
} else {
|
} else {
|
||||||
output += spaces + contentToDiffLine(key, value) + '\n';
|
output += spaces + contentToDiffLine(key, value) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output + ' }';
|
return output + " }";
|
||||||
}
|
}
|
||||||
|
|
||||||
function lookForEntry(entry, data) {
|
function lookForEntry(entry, data) {
|
||||||
return data.findIndex(data_entry => {
|
return data.findIndex(data_entry => {
|
||||||
let allGood = true;
|
let allGood = true;
|
||||||
for (const key in entry) {
|
for (const key in entry) {
|
||||||
if (!entry.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(entry, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let value = data_entry[key];
|
let value = data_entry[key];
|
||||||
// To make our life easier, if there is a "parent" type, we add it to the path.
|
// To make our life easier, if there is a "parent" type, we add it to the path.
|
||||||
if (key === 'path' && data_entry['parent'] !== undefined) {
|
if (key === "path" && data_entry["parent"] !== undefined) {
|
||||||
if (value.length > 0) {
|
if (value.length > 0) {
|
||||||
value += '::' + data_entry['parent']['name'];
|
value += "::" + data_entry["parent"]["name"];
|
||||||
} else {
|
} else {
|
||||||
value = data_entry['parent']['name'];
|
value = data_entry["parent"]["name"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (value !== entry[key]) {
|
if (value !== entry[key]) {
|
||||||
@ -95,7 +95,7 @@ function checkNeededFields(fullPath, expected, error_text, queryName, position)
|
|||||||
fieldsToCheck = [];
|
fieldsToCheck = [];
|
||||||
}
|
}
|
||||||
for (const field of fieldsToCheck) {
|
for (const field of fieldsToCheck) {
|
||||||
if (!expected.hasOwnProperty(field)) {
|
if (!Object.prototype.hasOwnProperty.call(expected, field)) {
|
||||||
let text = `${queryName}==> Mandatory key \`${field}\` is not present`;
|
let text = `${queryName}==> Mandatory key \`${field}\` is not present`;
|
||||||
if (fullPath.length > 0) {
|
if (fullPath.length > 0) {
|
||||||
text += ` in field \`${fullPath}\``;
|
text += ` in field \`${fullPath}\``;
|
||||||
@ -117,22 +117,22 @@ function valueCheck(fullPath, expected, result, error_text, queryName) {
|
|||||||
error_text.push(`${queryName}==> EXPECTED has extra value in array from field ` +
|
error_text.push(`${queryName}==> EXPECTED has extra value in array from field ` +
|
||||||
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(expected[i])}\``);
|
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(expected[i])}\``);
|
||||||
} else {
|
} else {
|
||||||
valueCheck(fullPath + '[' + i + ']', expected[i], result[i], error_text, queryName);
|
valueCheck(fullPath + "[" + i + "]", expected[i], result[i], error_text, queryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; i < result.length; ++i) {
|
for (; i < result.length; ++i) {
|
||||||
error_text.push(`${queryName}==> RESULT has extra value in array from field ` +
|
error_text.push(`${queryName}==> RESULT has extra value in array from field ` +
|
||||||
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(result[i])}\` ` +
|
`\`${fullPath}\` (position ${i}): \`${JSON.stringify(result[i])}\` ` +
|
||||||
'compared to EXPECTED');
|
"compared to EXPECTED");
|
||||||
}
|
}
|
||||||
} else if (expected !== null && typeof expected !== "undefined" &&
|
} else if (expected !== null && typeof expected !== "undefined" &&
|
||||||
expected.constructor == Object) {
|
expected.constructor == Object) { // eslint-disable-line eqeqeq
|
||||||
for (const key in expected) {
|
for (const key in expected) {
|
||||||
if (!expected.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(expected, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!result.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(result, key)) {
|
||||||
error_text.push('==> Unknown key "' + key + '"');
|
error_text.push("==> Unknown key \"" + key + "\"");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let result_v = result[key];
|
let result_v = result[key];
|
||||||
@ -147,13 +147,13 @@ function valueCheck(fullPath, expected, result, error_text, queryName) {
|
|||||||
});
|
});
|
||||||
result_v = result_v.join("");
|
result_v = result_v.join("");
|
||||||
}
|
}
|
||||||
const obj_path = fullPath + (fullPath.length > 0 ? '.' : '') + key;
|
const obj_path = fullPath + (fullPath.length > 0 ? "." : "") + key;
|
||||||
valueCheck(obj_path, expected[key], result_v, error_text, queryName);
|
valueCheck(obj_path, expected[key], result_v, error_text, queryName);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const expectedValue = JSON.stringify(expected);
|
const expectedValue = JSON.stringify(expected);
|
||||||
const resultValue = JSON.stringify(result);
|
const resultValue = JSON.stringify(result);
|
||||||
if (expectedValue != resultValue) {
|
if (expectedValue !== resultValue) {
|
||||||
error_text.push(`${queryName}==> Different values for field \`${fullPath}\`:\n` +
|
error_text.push(`${queryName}==> Different values for field \`${fullPath}\`:\n` +
|
||||||
`EXPECTED: \`${expectedValue}\`\nRESULT: \`${resultValue}\``);
|
`EXPECTED: \`${expectedValue}\`\nRESULT: \`${resultValue}\``);
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ function runParser(query, expected, parseQuery, queryName) {
|
|||||||
const error_text = [];
|
const error_text = [];
|
||||||
checkNeededFields("", expected, error_text, queryName, null);
|
checkNeededFields("", expected, error_text, queryName, null);
|
||||||
if (error_text.length === 0) {
|
if (error_text.length === 0) {
|
||||||
valueCheck('', expected, parseQuery(query), error_text, queryName);
|
valueCheck("", expected, parseQuery(query), error_text, queryName);
|
||||||
}
|
}
|
||||||
return error_text;
|
return error_text;
|
||||||
}
|
}
|
||||||
@ -177,16 +177,16 @@ function runSearch(query, expected, doSearch, loadedFile, queryName) {
|
|||||||
const error_text = [];
|
const error_text = [];
|
||||||
|
|
||||||
for (const key in expected) {
|
for (const key in expected) {
|
||||||
if (!expected.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(expected, key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!results.hasOwnProperty(key)) {
|
if (!Object.prototype.hasOwnProperty.call(results, key)) {
|
||||||
error_text.push('==> Unknown key "' + key + '"');
|
error_text.push("==> Unknown key \"" + key + "\"");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const entry = expected[key];
|
const entry = expected[key];
|
||||||
|
|
||||||
if (exact_check == true && entry.length !== results[key].length) {
|
if (exact_check && entry.length !== results[key].length) {
|
||||||
error_text.push(queryName + "==> Expected exactly " + entry.length +
|
error_text.push(queryName + "==> Expected exactly " + entry.length +
|
||||||
" results but found " + results[key].length + " in '" + key + "'");
|
" results but found " + results[key].length + " in '" + key + "'");
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ function runCheck(loadedFile, key, callback) {
|
|||||||
function runChecks(testFile, doSearch, parseQuery) {
|
function runChecks(testFile, doSearch, parseQuery) {
|
||||||
let checkExpected = false;
|
let checkExpected = false;
|
||||||
let checkParsed = false;
|
let checkParsed = false;
|
||||||
let testFileContent = readFile(testFile) + 'exports.QUERY = QUERY;';
|
let testFileContent = readFile(testFile) + "exports.QUERY = QUERY;";
|
||||||
|
|
||||||
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
|
if (testFileContent.indexOf("FILTER_CRATE") !== -1) {
|
||||||
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
|
testFileContent += "exports.FILTER_CRATE = FILTER_CRATE;";
|
||||||
@ -277,11 +277,11 @@ function runChecks(testFile, doSearch, parseQuery) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (testFileContent.indexOf("\nconst EXPECTED") !== -1) {
|
if (testFileContent.indexOf("\nconst EXPECTED") !== -1) {
|
||||||
testFileContent += 'exports.EXPECTED = EXPECTED;';
|
testFileContent += "exports.EXPECTED = EXPECTED;";
|
||||||
checkExpected = true;
|
checkExpected = true;
|
||||||
}
|
}
|
||||||
if (testFileContent.indexOf("\nconst PARSED") !== -1) {
|
if (testFileContent.indexOf("\nconst PARSED") !== -1) {
|
||||||
testFileContent += 'exports.PARSED = PARSED;';
|
testFileContent += "exports.PARSED = PARSED;";
|
||||||
checkParsed = true;
|
checkParsed = true;
|
||||||
}
|
}
|
||||||
if (!checkParsed && !checkExpected) {
|
if (!checkParsed && !checkExpected) {
|
||||||
@ -361,7 +361,7 @@ function parseOptions(args) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < args.length; ++i) {
|
for (let i = 0; i < args.length; ++i) {
|
||||||
if (correspondences.hasOwnProperty(args[i])) {
|
if (Object.prototype.hasOwnProperty.call(correspondences, args[i])) {
|
||||||
i += 1;
|
i += 1;
|
||||||
if (i >= args.length) {
|
if (i >= args.length) {
|
||||||
console.log("Missing argument after `" + args[i - 1] + "` option.");
|
console.log("Missing argument after `" + args[i - 1] + "` option.");
|
||||||
@ -410,12 +410,12 @@ function main(argv) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (opts["test_file"].length !== 0) {
|
if (opts["test_file"].length !== 0) {
|
||||||
opts["test_file"].forEach(function (file) {
|
opts["test_file"].forEach(file => {
|
||||||
process.stdout.write(`Testing ${file} ... `);
|
process.stdout.write(`Testing ${file} ... `);
|
||||||
errors += runChecks(file, doSearch, parseAndSearch.parseQuery);
|
errors += runChecks(file, doSearch, parseAndSearch.parseQuery);
|
||||||
});
|
});
|
||||||
} else if (opts["test_folder"].length !== 0) {
|
} else if (opts["test_folder"].length !== 0) {
|
||||||
fs.readdirSync(opts["test_folder"]).forEach(function (file) {
|
fs.readdirSync(opts["test_folder"]).forEach(file => {
|
||||||
if (!file.endsWith(".js")) {
|
if (!file.endsWith(".js")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user