[INS-2119] Inso CLI logging parity (#5408)

* [INS-2119] Inso CLI logging parity

* fix bootstrap
This commit is contained in:
Filipe Freire authored and GitHub committed 2022-11-15 16:49:31 +00:00
1 parent 473624a45e
commit 4fa2e4e81e
3 files changed
+42 -29

No files matched your search

+22 -21
View File
@@ -12,6 +12,7 @@
"@stoplight/spectral-core": "^1.12.2",
"@stoplight/spectral-formats": "^1.2.0",
"@stoplight/spectral-rulesets": "^1.9.0",
"@stoplight/types": "^13.8.0",
"axios": "^0.21.2",
"commander": "^5.1.0",
"consola": "^2.15.0",
@@ -1193,18 +1194,6 @@
"node": ">=8.3.0"
}
},
"node_modules/@stoplight/spectral-formats/node_modules/@stoplight/types": {
"version": "13.2.0",
"resolved": "https://registry.npmjs.org/@stoplight/types/-/types-13.2.0.tgz",
"integrity": "sha512-V3BRfzWEAcCpICGQh/WW2LX4rcB2KagQ7/msf0BDTCF5qpFMSwOxcjv25k1NUMVQSh3qwGfGoka/gYGA5m+NQA==",
"dependencies": {
"@types/json-schema": "^7.0.4",
"utility-types": "^3.10.0"
},
"engines": {
"node": "^12.20 || >=14.13"
}
},
"node_modules/@stoplight/spectral-formats/node_modules/tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
@@ -1660,6 +1649,18 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
"integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ=="
},
"node_modules/@stoplight/types": {
"version": "13.8.0",
"resolved": "https://registry.npmjs.org/@stoplight/types/-/types-13.8.0.tgz",
"integrity": "sha512-5glKswz7y9aACh+a+JegID+4xX//4TsIdv7iPl29hWnOoWrnlPbg3Gjc4nYUXXgMSaSlSsA15JU/0+rE89fR4A==",
"dependencies": {
"@types/json-schema": "^7.0.4",
"utility-types": "^3.10.0"
},
"engines": {
"node": "^12.20 || >=14.13"
}
},
"node_modules/@stoplight/yaml-ast-parser": {
"version": "0.0.48",
"resolved": "https://registry.npmjs.org/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.48.tgz",
@@ -7741,15 +7742,6 @@
"safe-stable-stringify": "^1.1"
}
},
"@stoplight/types": {
"version": "13.2.0",
"resolved": "https://registry.npmjs.org/@stoplight/types/-/types-13.2.0.tgz",
"integrity": "sha512-V3BRfzWEAcCpICGQh/WW2LX4rcB2KagQ7/msf0BDTCF5qpFMSwOxcjv25k1NUMVQSh3qwGfGoka/gYGA5m+NQA==",
"requires": {
"@types/json-schema": "^7.0.4",
"utility-types": "^3.10.0"
}
},
"tslib": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz",
@@ -8116,6 +8108,15 @@
}
}
},
"@stoplight/types": {
"version": "13.8.0",
"resolved": "https://registry.npmjs.org/@stoplight/types/-/types-13.8.0.tgz",
"integrity": "sha512-5glKswz7y9aACh+a+JegID+4xX//4TsIdv7iPl29hWnOoWrnlPbg3Gjc4nYUXXgMSaSlSsA15JU/0+rE89fR4A==",
"requires": {
"@types/json-schema": "^7.0.4",
"utility-types": "^3.10.0"
}
},
"@stoplight/yaml-ast-parser": {
"version": "0.0.48",
"resolved": "https://registry.npmjs.org/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.48.tgz",
+1
View File
@@ -64,6 +64,7 @@
"@stoplight/spectral-core": "^1.12.2",
"@stoplight/spectral-formats": "^1.2.0",
"@stoplight/spectral-rulesets": "^1.9.0",
"@stoplight/types": "^13.8.0",
"axios": "^0.21.2",
"commander": "^5.1.0",
"consola": "^2.15.0",
@@ -1,5 +1,6 @@
import { RulesetDefinition, Spectral } from '@stoplight/spectral-core';
import { oas } from '@stoplight/spectral-rulesets';
import { DiagnosticSeverity } from '@stoplight/types';
import fs from 'fs';
import path from 'path';
@@ -52,19 +53,29 @@ export async function lintSpecification(
const spectral = new Spectral();
await spectral.setRuleset(oas as RulesetDefinition);
logger.info(`Using ruleset: oas, see ${oas.documentationUrl}`);
const results = (await spectral.run(specContent)).filter(result => (
result.severity === 0 // filter for errors only
));
const results = (await spectral.run(specContent));
if (results.length) {
logger.log(`${results.length} lint errors found. \n`);
// Print Summary
if (results.some(r => r.severity === DiagnosticSeverity.Error)) {
logger.fatal(`${results.filter(r => r.severity === DiagnosticSeverity.Error).length} lint errors found. \n`);
}
if (results.some(r => r.severity === DiagnosticSeverity.Warning)) {
logger.warn(`${results.filter(r => r.severity === DiagnosticSeverity.Warning).length} lint warnings found. \n`);
}
results.forEach(r =>
logger.log(`${r.range.start.line}:${r.range.start.character} - ${r.message}`),
logger.log(`${r.range.start.line + 1}:${r.range.start.character + 1} - ${DiagnosticSeverity[r.severity]} - ${r.code} - ${r.message} - ${r.path.join('.')}`),
);
return false;
}
logger.log('No linting errors. Yay!');
// Fail if errors present
if (results.some(r => r.severity === DiagnosticSeverity.Error)) {
logger.log('Errors found, failing lint.');
return false;
}
} else {
logger.log('No linting errors or warnings.');
}
return true;
}