Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes the lint output less verbose #2528

Merged
merged 3 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 140 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"homepage": "https://github.com/mdn/browser-compat-data#readme",
"devDependencies": {
"ajv": "^5.0.1",
"mdn-confluence": "0.0.7"
"mdn-confluence": "0.0.7",
"ora": "^3.0.0"
},
"scripts": {
"confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js",
Expand Down
24 changes: 21 additions & 3 deletions test/lint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const fs = require('fs');
const path = require('path');
const ora = require('ora');
const {testStyle} = require('./test-style');
const {testSchema} = require('./test-schema');
const {testVersions} = require('./test-versions');
Expand All @@ -26,7 +27,20 @@ function load(...files) {
if (path.extname(file) === '.json') {
let hasStyleErrors, hasSchemaErrors, hasVersionErrors = false;
const relativeFilePath = path.relative(process.cwd(), file);
console.log(relativeFilePath);

const spinner = ora({
stream: process.stdout,
text: relativeFilePath
});

const console_error = console.error;
console.error = (...args) => {
spinner.stream = process.stderr;
spinner.fail(relativeFilePath);
console.error = console_error;
console.error(...args);
}

if (file.indexOf('browsers' + path.sep) !== -1) {
hasSchemaErrors = testSchema(file, './../schemas/browsers.schema.json');
} else {
Expand All @@ -37,7 +51,11 @@ function load(...files) {
if (hasStyleErrors || hasSchemaErrors || hasVersionErrors) {
hasErrors = true;
filesWithErrors.set(relativeFilePath, file);
} else {
console.error = console_error;
spinner.succeed();
}

}

continue;
Expand Down Expand Up @@ -72,10 +90,10 @@ if (process.argv[2]) {
}

if (hasErrors) {
console.log("");
console.warn("");
console.warn(`Problems in ${filesWithErrors.size} file${filesWithErrors.size > 1 ? 's' : ''}:`);
for (const [fileName, file] of filesWithErrors) {
console.log(fileName);
console.warn(fileName);
testSchema(file);
testStyle(file);
testVersions(file);
Expand Down
1 change: 0 additions & 1 deletion test/test-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function testSchema(dataFilename, schemaFilename = './../schemas/compat-data.sch
);

if (valid) {
console.log('\x1b[32m JSON schema – OK \x1b[0m');
return false;
} else {
console.error('\x1b[31m File : ' + path.relative(process.cwd(), dataFilename));
Expand Down
4 changes: 1 addition & 3 deletions test/test-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ function testStyle(filename) {
expected = expected.replace(/\r/g, "");
}

if (actual === expected) {
console.log('\x1b[32m Style – OK \x1b[0m');
} else {
if (actual !== expected) {
hasErrors = true;
console.error('\x1b[31m File : ' + path.relative(process.cwd(), filename));
console.error('\x1b[31m Style – Error on line ' + jsonDiff(actual, expected));
Expand Down
1 change: 0 additions & 1 deletion test/test-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function testVersions(dataFilename) {
console.error('\x1b[31m Browser version error(s)\x1b[0m');
return true;
} else {
console.log('\x1b[32m Browser versions – OK \x1b[0m');
return false;
}
}
Expand Down