diff --git a/src/commands/lint.ts b/src/commands/lint.ts index 05e5be2..c226cd9 100644 --- a/src/commands/lint.ts +++ b/src/commands/lint.ts @@ -8,8 +8,9 @@ const path = require("path"); const util = require("util"); const chalk = require('chalk'); const YAML = require("yaml"); +const Parsers = require('@stoplight/spectral-parsers'); const { fetch } = require("@stoplight/spectral-runtime"); -const { Spectral } = require("@stoplight/spectral-core"); +const { Spectral, Document } = require("@stoplight/spectral-core"); const { bundleAndLoadRuleset, } = require("@stoplight/spectral-ruleset-bundler/with-loader"); @@ -27,6 +28,18 @@ type Options = { save: boolean; }; +interface Result { + code: string, + message: string, + path: Array, + severity: number, + source: string, + range: { + start: { line: number, character: number }, + end: { line: number, character: number } + } +} + async function downloadRuleset( fileUrl: string, outputLocationPath: string @@ -107,7 +120,11 @@ export const handler = async (argv: Arguments): Promise => { ); // Run the linter - await spectral.run(spec).then((result: Array) => { + await spectral.run(new Document(specFile, Parsers.Yaml, specPath)).then((result: Array) => { + result.forEach(res => { + res.range.start.line += 1; + res.range.end.line += 1; + }); if (json) { // Print result in JSON format so that it can be parsed programmatically console.log(JSON.stringify(result, null, 2));