@@ -29,6 +29,8 @@ const doubleCheck = (data, verbose = false) => {
29
29
}
30
30
31
31
const removeLinebreak = l => l . replace ( / [ \n \r ] / g, '' )
32
+ const replaceChar = ( str , idx , chr ) =>
33
+ str . substring ( 0 , idx ) + chr + str . substring ( idx + 1 )
32
34
33
35
const extraChar = err =>
34
36
err . expected [ 0 ] . type === 'other' && [ '}' , ']' ] . includes ( err . found )
@@ -129,14 +131,29 @@ const fixJson = (err, data, verbose) => {
129
131
const brokenLine = removeLinebreak ( lines [ targetLine ] )
130
132
const fixedLine = brokenLine . replace ( / ( " : \s * ) ' ( .* ?) ' / g, '$1"$2"' )
131
133
fixedData [ targetLine ] = fixedLine
132
- } else if ( missingQuotes ( err ) ) {
133
- psw ( 'pre' )
134
- console . log ( fixedData )
134
+ } else if ( missingQuotes ( err ) )
135
135
fixedData = fixMissingQuotes ( { start, fixedData, verbose} )
136
- psw ( 'post' )
137
- console . log ( fixedData )
138
- } else if ( notSquare ( err ) ) {
139
- console . log ( 'WIP' )
136
+ else if ( notSquare ( err ) ) {
137
+ let targetLine = start . line - 2
138
+ const brokenLine = removeLinebreak (
139
+ lines [ targetLine ] . includes ( '[' ) ? lines [ targetLine ] : lines [ ++ targetLine ] ,
140
+ )
141
+ const fixedLine = replaceChar ( brokenLine , start . column - 1 , '{' )
142
+ fixedData [ targetLine ] = fixedLine
143
+
144
+ try {
145
+ parse ( fixedData . join ( '\n' ) )
146
+ } catch ( e ) {
147
+ const newStart = e . location . start
148
+ const newTargetLine = newStart . line - 1
149
+ const newLine = removeLinebreak ( fixedData [ newTargetLine ] ) . replace (
150
+ ']' ,
151
+ '}' ,
152
+ )
153
+ fixedData [ newTargetLine ] = newLine
154
+ }
155
+
156
+ fixedData [ targetLine ] = fixedLine
140
157
} else
141
158
throw new Error (
142
159
`Unsupported issue: ${ err . message } (please open an issue at the repo)` ,
0 commit comments