From 4fa2e4e81e293342f247225a63e7ab9ca4d62629 Mon Sep 17 00:00:00 2001 From: Filipe Freire Date: Tue, 15 Nov 2022 16:49:31 +0000 Subject: [PATCH] [INS-2119] Inso CLI logging parity (#5408) * [INS-2119] Inso CLI logging parity * fix bootstrap --- packages/insomnia-inso/package-lock.json | 43 ++++++++++--------- packages/insomnia-inso/package.json | 1 + .../src/commands/lint-specification.ts | 27 ++++++++---- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/packages/insomnia-inso/package-lock.json b/packages/insomnia-inso/package-lock.json index 36b34ad37e..bfcb53ca4e 100644 --- a/packages/insomnia-inso/package-lock.json +++ b/packages/insomnia-inso/package-lock.json @@ -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", diff --git a/packages/insomnia-inso/package.json b/packages/insomnia-inso/package.json index a816612ef8..d5289253de 100644 --- a/packages/insomnia-inso/package.json +++ b/packages/insomnia-inso/package.json @@ -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", diff --git a/packages/insomnia-inso/src/commands/lint-specification.ts b/packages/insomnia-inso/src/commands/lint-specification.ts index 23a1fee46f..e96952a6a3 100644 --- a/packages/insomnia-inso/src/commands/lint-specification.ts +++ b/packages/insomnia-inso/src/commands/lint-specification.ts @@ -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; }