Skip to content

Commit 6326bec

Browse files
authored
Merge branch 'master' into fix-override-with-disabled-rule
2 parents ab3272c + c6621f8 commit 6326bec

File tree

7 files changed

+1468
-2027
lines changed

7 files changed

+1468
-2027
lines changed

lib/loader.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const path = require('path');
66
const rules = require('./rules.js');
77
const resolver = require('oas-resolver');
88
const yaml = require('js-yaml');
9+
const readline = require('readline');
910

1011
class ExtendableError extends Error {
1112
constructor(message) {
@@ -27,6 +28,21 @@ function readFileAsync(filename, encoding) {
2728
});
2829
}
2930

31+
function readFileStdinAsync() {
32+
return new Promise((resolve, reject) => {
33+
const rl = readline.createInterface({
34+
input: process.stdin
35+
});
36+
let lines = [];
37+
rl.on('line', (line) => {
38+
lines.push(line);
39+
});
40+
rl.on('close', () => {
41+
resolve(lines.join('\n'));
42+
});
43+
});
44+
}
45+
3046
const fetchUrl = async (url) => {
3147
let response;
3248
try {
@@ -45,18 +61,24 @@ const fetchUrl = async (url) => {
4561
};
4662

4763

64+
// file can be null, meaning stdin
4865
function readSpecFile(file, options) {
4966
if (options.verbose > 1) {
50-
console.log('GET ' + file);
67+
file ? console.error('GET ' + file) : console.error('GET <stdin>');
5168
}
52-
if (file && file.startsWith('http')) {
69+
if (!file) {
70+
// standard input
71+
return readFileStdinAsync();
72+
} else if (file && file.startsWith('http')) {
73+
// remote file
5374
return fetch(file).then(res => {
5475
if (res.status !== 200) {
5576
throw new Error(`Received status code ${res.status}`);
5677
}
5778
return res.text();
5879
})
5980
} else {
81+
// local file
6082
// TODO error handlers?
6183
return readFileAsync(file, 'utf8');
6284
}
@@ -83,16 +105,16 @@ const recursivelyLoadRulesets = async (ruleset, loadedRulesets, options) => {
83105
let text;
84106
// If the ruleset looks like a HTTP URL
85107
if (ruleset && ruleset.startsWith('http')) {
86-
if (verbose > 1) console.log('GET ' + ruleset);
108+
if (verbose > 1) console.error('GET ' + ruleset);
87109
text = await fetchUrl(ruleset);
88110
}
89111
else if (fs.existsSync(ruleset)) {
90-
if (verbose > 1) console.log('READ ' + ruleset);
112+
if (verbose > 1) console.error('READ ' + ruleset);
91113
text = fs.readFileSync(ruleset, 'utf8');
92114
}
93115
else {
94116
const rulesetFile = path.join(__dirname, '../rules/' + ruleset + '.yaml');
95-
if (verbose > 1) console.log('READ ' + rulesetFile);
117+
if (verbose > 1) console.error('READ ' + rulesetFile);
96118
text = fs.readFileSync(rulesetFile, 'utf8');
97119
}
98120

lint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ More information: https://speccy.io/rules/1-rulesets#${rule.name}
6868
const command = async (specFile, cmd) => {
6969
config.init(cmd);
7070
const jsonSchema = config.get('jsonSchema');
71-
const verbose = config.get('quiet') ? 0 : (config.get('verbose') ? 2 : 1);
71+
const verbose = config.get('quiet') ? 0 : config.get('verbose', 1);
7272
const rulesets = config.get('lint:rules');
7373
const skip = config.get('lint:skip');
7474

@@ -84,7 +84,7 @@ const command = async (specFile, cmd) => {
8484
);
8585

8686
return new Promise((resolve, reject) => {
87-
validator.validate(spec, buildValidatorOptions(skip, verbose), (err, _options) => {
87+
validator.validate(spec, buildValidatorOptions(skip, verbose), (err, _options) => {
8888
const { context, warnings, valid } = _options || err.options;
8989

9090
if (err && valid === false) {

0 commit comments

Comments
 (0)