Skip to content

Commit

Permalink
Merge pull request #9 from Bandwidth/task/line-numbers
Browse files Browse the repository at this point in the history
task/update linter to show correct line numbers
  • Loading branch information
ajrice6713 authored Oct 21, 2022
2 parents 45ef305 + 049e728 commit ea51dc2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -27,6 +28,18 @@ type Options = {
save: boolean;
};

interface Result {
code: string,
message: string,
path: Array<string>,
severity: number,
source: string,
range: {
start: { line: number, character: number },
end: { line: number, character: number }
}
}

async function downloadRuleset(
fileUrl: string,
outputLocationPath: string
Expand Down Expand Up @@ -107,7 +120,11 @@ export const handler = async (argv: Arguments<Options>): Promise<void> => {
);

// Run the linter
await spectral.run(spec).then((result: Array<Object>) => {
await spectral.run(new Document(specFile, Parsers.Yaml, specPath)).then((result: Array<Result>) => {
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));
Expand Down

0 comments on commit ea51dc2

Please sign in to comment.