Skip to content

Commit ea51dc2

Browse files
authored
Merge pull request #9 from Bandwidth/task/line-numbers
task/update linter to show correct line numbers
2 parents 45ef305 + 049e728 commit ea51dc2

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/commands/lint.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const path = require("path");
88
const util = require("util");
99
const chalk = require('chalk');
1010
const YAML = require("yaml");
11+
const Parsers = require('@stoplight/spectral-parsers');
1112
const { fetch } = require("@stoplight/spectral-runtime");
12-
const { Spectral } = require("@stoplight/spectral-core");
13+
const { Spectral, Document } = require("@stoplight/spectral-core");
1314
const {
1415
bundleAndLoadRuleset,
1516
} = require("@stoplight/spectral-ruleset-bundler/with-loader");
@@ -27,6 +28,18 @@ type Options = {
2728
save: boolean;
2829
};
2930

31+
interface Result {
32+
code: string,
33+
message: string,
34+
path: Array<string>,
35+
severity: number,
36+
source: string,
37+
range: {
38+
start: { line: number, character: number },
39+
end: { line: number, character: number }
40+
}
41+
}
42+
3043
async function downloadRuleset(
3144
fileUrl: string,
3245
outputLocationPath: string
@@ -107,7 +120,11 @@ export const handler = async (argv: Arguments<Options>): Promise<void> => {
107120
);
108121

109122
// Run the linter
110-
await spectral.run(spec).then((result: Array<Object>) => {
123+
await spectral.run(new Document(specFile, Parsers.Yaml, specPath)).then((result: Array<Result>) => {
124+
result.forEach(res => {
125+
res.range.start.line += 1;
126+
res.range.end.line += 1;
127+
});
111128
if (json) {
112129
// Print result in JSON format so that it can be parsed programmatically
113130
console.log(JSON.stringify(result, null, 2));

0 commit comments

Comments
 (0)