File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,12 @@ interface HintIssueType extends HintIssueBase {
14
14
code : 'invalid_type' ;
15
15
}
16
16
17
- export type HintIssue = HintIssueRootType | HintIssueType ;
17
+ interface HintJSONIssue {
18
+ code : 'invalid_json' ;
19
+ line : number ;
20
+ }
21
+
22
+ export type HintIssue = HintIssueRootType | HintIssueType | HintJSONIssue ;
18
23
19
24
export class HintError extends Error {
20
25
issues : HintIssue [ ] = [ ] ;
Original file line number Diff line number Diff line change @@ -168,19 +168,8 @@ export const check = (jsonStr: string): GeoJSON => {
168
168
} ) ;
169
169
} catch ( e ) {
170
170
issues . push ( {
171
- code : 'invalid_type' ,
172
- loc : {
173
- start : {
174
- line : e . line ,
175
- column : e . column ,
176
- offset : 0 ,
177
- } ,
178
- end : {
179
- line : e . line ,
180
- column : e . column ,
181
- offset : 0 ,
182
- } ,
183
- } ,
171
+ code : 'invalid_json' ,
172
+ line : e . line ,
184
173
} ) ;
185
174
}
186
175
if ( ast ) checkObject ( issues , ast . body ) ;
Original file line number Diff line number Diff line change @@ -40,6 +40,22 @@ describe('check', () => {
40
40
) . toThrow ( HintError ) ;
41
41
} ) ;
42
42
43
+ it ( 'bad json' , ( ) => {
44
+ try {
45
+ check (
46
+ `{
47
+ "type": "MultiPoint"
48
+ "coordinates": [["foo", "bar"]]
49
+ }`
50
+ ) ;
51
+ } catch ( e ) {
52
+ expect ( e . issues [ 0 ] ) . toEqual ( {
53
+ code : 'invalid_json' ,
54
+ line : 3 ,
55
+ } ) ;
56
+ }
57
+ } ) ;
58
+
43
59
describe ( 'works with fixtures' , ( ) => {
44
60
const fixtureNames = readdirSync ( Path . join ( __dirname , './fixture/bad/' ) ) ;
45
61
for ( let name of fixtureNames ) {
You can’t perform that action at this time.
0 commit comments