Skip to content

Commit

Permalink
Make the lint output less verbose by adding ora (#2528)
Browse files Browse the repository at this point in the history
* lint: make output less verbose

* Uses ora to display a spinner with succeed/fail feedback.
* Removes `console.log` calls for succeeding checks.

* lint: make ora use stdout + stderr

* lint: use console.warn for error summary
  • Loading branch information
caugner authored and Elchi3 committed Oct 29, 2018
1 parent 83746d7 commit c5ac9eb
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 12 deletions.
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

0 comments on commit c5ac9eb

Please sign in to comment.