@@ -152,30 +152,22 @@ export abstract class Plugins {
152
152
return [ ! offence , message + Helpers . errMessageSuffix ] ;
153
153
}
154
154
155
- public static footerNotesMisplacement ( rawStr : string ) {
155
+ public static footerNotesMisplacement ( bodyStr : string ) {
156
156
let offence = false ;
157
157
158
- let lineBreakIndex = rawStr . indexOf ( "\n" ) ;
159
-
160
- if ( lineBreakIndex >= 0 ) {
161
- // Extracting bodyStr from rawStr rather than using body directly is a
162
- // workaround for https://github.com/conventional-changelog/commitlint/issues/3428
163
- let bodyStr = rawStr . substring ( lineBreakIndex ) . trim ( ) ;
164
-
165
- if ( bodyStr !== "" ) {
166
- let seenBody = false ;
167
- let seenFooter = false ;
168
- let lines = bodyStr . split ( / \r ? \n / ) ;
169
- for ( let line of lines ) {
170
- if ( line . length === 0 ) {
171
- continue ;
172
- }
173
- seenBody = seenBody || ! Helpers . isFooterNote ( line ) ;
174
- seenFooter = seenFooter || Helpers . isFooterNote ( line ) ;
175
- if ( seenFooter && ! Helpers . isFooterNote ( line ) ) {
176
- offence = true ;
177
- break ;
178
- }
158
+ if ( bodyStr !== "" ) {
159
+ let seenBody = false ;
160
+ let seenFooter = false ;
161
+ let lines = bodyStr . split ( / \r ? \n / ) ;
162
+ for ( let line of lines ) {
163
+ if ( line . length === 0 ) {
164
+ continue ;
165
+ }
166
+ seenBody = seenBody || ! Helpers . isFooterNote ( line ) ;
167
+ seenFooter = seenFooter || Helpers . isFooterNote ( line ) ;
168
+ if ( seenFooter && ! Helpers . isFooterNote ( line ) ) {
169
+ offence = true ;
170
+ break ;
179
171
}
180
172
}
181
173
}
@@ -186,44 +178,36 @@ export abstract class Plugins {
186
178
] ;
187
179
}
188
180
189
- public static footerReferencesExistence ( rawStr : string ) {
181
+ public static footerReferencesExistence ( bodyStr : string ) {
190
182
let offence = false ;
191
183
192
- let lineBreakIndex = rawStr . indexOf ( "\n" ) ;
193
-
194
- if ( lineBreakIndex >= 0 ) {
195
- // Extracting bodyStr from rawStr rather than using body directly is a
196
- // workaround for https://github.com/conventional-changelog/commitlint/issues/3428
197
- let bodyStr = rawStr . substring ( lineBreakIndex ) . trim ( ) ;
198
-
199
- if ( bodyStr !== "" ) {
200
- let lines = bodyStr . split ( / \r ? \n / ) ;
201
- let bodyReferences = new Set ( ) ;
202
- let references = new Set ( ) ;
203
- for ( let line of lines ) {
204
- let matches = line . match ( / (?< = \[ ) ( [ 0 - 9 ] + ) (? = \] ) / g) ;
205
- if ( matches === null ) {
206
- continue ;
207
- }
208
- for ( let match of matches ) {
209
- if ( Helpers . isFooterReference ( line ) ) {
210
- references . add ( match ) ;
211
- } else {
212
- bodyReferences . add ( match ) ;
213
- }
214
- }
184
+ if ( bodyStr !== "" ) {
185
+ let lines = bodyStr . split ( / \r ? \n / ) ;
186
+ let bodyReferences = new Set ( ) ;
187
+ let references = new Set ( ) ;
188
+ for ( let line of lines ) {
189
+ let matches = line . match ( / (?< = \[ ) ( [ 0 - 9 ] + ) (? = \] ) / g) ;
190
+ if ( matches === null ) {
191
+ continue ;
215
192
}
216
- for ( let ref of bodyReferences ) {
217
- if ( ! references . has ( ref ) ) {
218
- offence = true ;
219
- break ;
193
+ for ( let match of matches ) {
194
+ if ( Helpers . isFooterReference ( line ) ) {
195
+ references . add ( match ) ;
196
+ } else {
197
+ bodyReferences . add ( match ) ;
220
198
}
221
199
}
222
- for ( let ref of references ) {
223
- if ( ! bodyReferences . has ( ref ) ) {
224
- offence = true ;
225
- break ;
226
- }
200
+ }
201
+ for ( let ref of bodyReferences ) {
202
+ if ( ! references . has ( ref ) ) {
203
+ offence = true ;
204
+ break ;
205
+ }
206
+ }
207
+ for ( let ref of references ) {
208
+ if ( ! bodyReferences . has ( ref ) ) {
209
+ offence = true ;
210
+ break ;
227
211
}
228
212
}
229
213
}
@@ -368,18 +352,12 @@ export abstract class Plugins {
368
352
}
369
353
370
354
public static bodySoftMaxLineLength (
371
- rawStr : string ,
355
+ bodyStr : string ,
372
356
bodyMaxLineLength : number
373
357
) {
374
358
let offence = false ;
375
359
376
- let lineBreakIndex = rawStr . indexOf ( "\n" ) ;
377
-
378
- if ( lineBreakIndex >= 0 ) {
379
- // Extracting bodyStr from rawStr rather than using body directly is a
380
- // workaround for https://github.com/conventional-changelog/commitlint/issues/3428
381
- let bodyStr = rawStr . substring ( lineBreakIndex ) ;
382
-
360
+ if ( bodyStr !== "" ) {
383
361
bodyStr = Helpers . removeAllCodeBlocks ( bodyStr ) . trim ( ) ;
384
362
385
363
if ( bodyStr !== "" ) {
0 commit comments