Skip to content

Commit

Permalink
Use yargs to parse the arguments passed to the linter
Browse files Browse the repository at this point in the history
  This makes it possible to manually lint multiple files at once
without needing to run the linter multiple times.

  Also probably fixes the issue where an error in a single file would
cause all subsequent files to be printed at the end¹.

# References:
¹ https://travis-ci.org/mdn/browser-compat-data/builds/383532922#L7191
  • Loading branch information
ExE-Boss committed Jun 19, 2018
1 parent 0f0067b commit 968f561
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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",
"yargs": "^11.1.0"
},
"scripts": {
"confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js",
Expand Down
18 changes: 16 additions & 2 deletions test/lint.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
'use strict';
const fs = require('fs');
const path = require('path');
const yargs = require('yargs');
const {testStyle} = require('./test-style');
const {testSchema} = require('./test-schema');
const {testVersions} = require('./test-versions');
/** @type {Map<string,string>} */
const filesWithErrors = new Map();

const argv = yargs.alias('version','v')
.usage('$0 [[--] files...]', false, (yargs) => {
yargs.positional('files...', {
description: 'The files to lint',
type: 'string'
})
})
.help().alias('help','h').alias('help','?')
.parse(process.argv.slice(2));

let hasErrors = false;

/**
* @param {string[]} files
*/
function load(...files) {
if (files.length === 1 && files[0] instanceof Array) {
files = files[0];
}
for (let file of files) {
if (file.indexOf(__dirname) !== 0) {
file = path.resolve(__dirname, '..', file);
Expand Down Expand Up @@ -51,8 +65,8 @@ function load(...files) {
}
}

if (process.argv[2]) {
load(process.argv[2]);
if (argv.files) {
load(argv.files);
} else {
load(
'api',
Expand Down

0 comments on commit 968f561

Please sign in to comment.