@@ -8,8 +8,9 @@ const path = require("path");
8
8
const util = require ( "util" ) ;
9
9
const chalk = require ( 'chalk' ) ;
10
10
const YAML = require ( "yaml" ) ;
11
+ const Parsers = require ( '@stoplight/spectral-parsers' ) ;
11
12
const { fetch } = require ( "@stoplight/spectral-runtime" ) ;
12
- const { Spectral } = require ( "@stoplight/spectral-core" ) ;
13
+ const { Spectral, Document } = require ( "@stoplight/spectral-core" ) ;
13
14
const {
14
15
bundleAndLoadRuleset,
15
16
} = require ( "@stoplight/spectral-ruleset-bundler/with-loader" ) ;
@@ -27,6 +28,18 @@ type Options = {
27
28
save: boolean ;
28
29
} ;
29
30
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
+
30
43
async function downloadRuleset (
31
44
fileUrl : string ,
32
45
outputLocationPath : string
@@ -107,7 +120,11 @@ export const handler = async (argv: Arguments<Options>): Promise<void> => {
107
120
) ;
108
121
109
122
// 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
+ } ) ;
111
128
if ( json ) {
112
129
// Print result in JSON format so that it can be parsed programmatically
113
130
console . log ( JSON . stringify ( result , null , 2 ) ) ;
0 commit comments