@@ -78,10 +78,12 @@ function format(ast, path) {
78
78
} ;
79
79
}
80
80
81
+ let changedIdx = - 1 ;
81
82
for ( let i = 0 ; i < content . length ; i ++ ) {
82
83
// checks on all ## headings
83
84
const item = content [ i ] ;
84
85
if ( item . type === "heading" && item . depth === 2 ) {
86
+ changedIdx = - 1 ;
85
87
// check correct amount of text is at heading 2
86
88
if (
87
89
item . children . length === 2 &&
@@ -201,10 +203,58 @@ function format(ast, path) {
201
203
changed = true ;
202
204
}
203
205
}
204
- if (
205
- item . children . length !== 1 ||
206
- item . children [ 0 ] . type !== "text" ||
207
- ! [
206
+
207
+ if ( item . children . length !== 1 || item . children [ 0 ] . type !== "text" ) {
208
+ console . log (
209
+ `${ path } :${ item . children [ 0 ] . position . start . line } :${ item . children [ 0 ] . position . start . column } `
210
+ ) ;
211
+ return {
212
+ correct : false ,
213
+ reason : `Level 3 headings should only be text` ,
214
+ } ;
215
+ }
216
+
217
+ if ( item . children [ 0 ] . value === 'Performance Improvements' ) {
218
+ if ( i + 1 < content . length && ( content [ i + 1 ] . type !== 'list' || content [ i + 2 ] . type !== 'heading' ) ) {
219
+ console . log (
220
+ `${ path } :${ item . children [ 0 ] . position . start . line } :${ item . children [ 0 ] . position . start . column } `
221
+ ) ;
222
+ return {
223
+ correct : false ,
224
+ reason : `Performance improvements section must be a single list to fix it` ,
225
+ } ;
226
+ }
227
+
228
+ if ( changedIdx === - 1 ) {
229
+ for ( let j = i + 1 ; j < content . length ; j ++ ) {
230
+ const curItem = content [ j ] ;
231
+ if ( curItem . type === 'heading' ) {
232
+ if ( curItem . depth < 3 )
233
+ break ;
234
+ if ( curItem . depth === 3 && curItem . children . length === 1 &&
235
+ curItem . children [ 0 ] . type === 'text' && curItem . children [ 0 ] . value === 'Changed' ) {
236
+ changedIdx = j ;
237
+ break ;
238
+ }
239
+ }
240
+ }
241
+ }
242
+
243
+ if ( changedIdx !== - 1 ) {
244
+ // Merge it into any already-seen changed section
245
+ const toMerge = content [ i + 1 ] ;
246
+ content . splice ( i , 2 ) ;
247
+ content . splice ( changedIdx + 1 , 0 , toMerge ) ;
248
+ changed = true ;
249
+ } else {
250
+ // Otherwise rename to Changed
251
+ item . children [ 0 ] . value = 'Changed' ;
252
+ changed = true ;
253
+ }
254
+ continue ;
255
+ }
256
+
257
+ if ( ! [
208
258
"Added" ,
209
259
"Changed" ,
210
260
"Deprecated" ,
@@ -222,6 +272,9 @@ function format(ast, path) {
222
272
} ;
223
273
}
224
274
275
+ if ( item . children [ 0 ] . value === 'Changed' )
276
+ changedIdx = i ;
277
+
225
278
// check that there is something other than a heading following it, which we have to presume describes the change
226
279
if ( ! content [ i + 1 ] || content [ i + 1 ] . type === "heading" ) {
227
280
console . log (
@@ -230,7 +283,7 @@ function format(ast, path) {
230
283
return {
231
284
correct : false ,
232
285
reason :
233
- "Level 3 headings must be followed by something other than the next heading - you should use text to describe the change" ,
286
+ "Level 3 headings must be followed by something other than a heading to describe the change" ,
234
287
} ;
235
288
}
236
289
}
0 commit comments